using ratatui instead of tui (#8952)

# Description

Refer to https://github.com/fdehau/tui-rs/issues/654, I found that tui
maybe un-maintained, instead, I'd suggest to use an actively fork
https://github.com/tui-rs-revival/ratatui

cc: @zhiburt 

# User-Facing Changes
NaN
This commit is contained in:
WindSoilder 2023-04-26 07:07:23 +08:00 committed by GitHub
parent 7d6a32c5f8
commit 503052b669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 48 additions and 48 deletions

28
Cargo.lock generated
View file

@ -2957,9 +2957,9 @@ dependencies = [
"nu-protocol",
"nu-table",
"nu-utils",
"ratatui",
"strip-ansi-escapes",
"terminal_size 0.2.6",
"tui",
]
[[package]]
@ -4269,6 +4269,19 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "ratatui"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829"
dependencies = [
"bitflags",
"cassowary",
"crossterm 0.26.1",
"unicode-segmentation",
"unicode-width",
]
[[package]]
name = "rayon"
version = "1.7.0"
@ -5463,19 +5476,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
[[package]]
name = "tui"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1"
dependencies = [
"bitflags",
"cassowary",
"crossterm 0.25.0",
"unicode-segmentation",
"unicode-width",
]
[[package]]
name = "typed-arena"
version = "1.7.0"

View file

@ -23,6 +23,6 @@ nu-utils = { path = "../nu-utils", version = "0.79.1" }
terminal_size = "0.2.1"
strip-ansi-escapes = "0.1.1"
crossterm = "0.26"
tui = "0.19.0"
ratatui = "0.20.1"
ansi-str = "0.7.2"
lscolors = { version = "0.14", default-features = false, features = ["nu-ansi-term"] }

View file

@ -4,7 +4,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::layout::Rect;
use ratatui::layout::Rect;
use crate::{
nu_common::{try_build_table, NuSpan},

View file

@ -8,7 +8,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::layout::Rect;
use ratatui::layout::Rect;
use crate::{
nu_common::{collect_input, NuSpan},

View file

@ -4,7 +4,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
PipelineData, Value,
};
use tui::layout::Rect;
use ratatui::layout::Rect;
use crate::{
nu_common::{collect_pipeline, has_simple_value, run_command_with_value},

View file

@ -1,4 +1,4 @@
use tui::{
use ratatui::{
buffer::Buffer,
layout::Rect,
style::{Modifier, Style},

View file

@ -24,7 +24,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::{backend::CrosstermBackend, layout::Rect, widgets::Block};
use ratatui::{backend::CrosstermBackend, layout::Rect, widgets::Block};
use crate::{
nu_common::{CtrlC, NuColor, NuConfig, NuSpan, NuStyle},
@ -43,8 +43,8 @@ use super::views::{Layout, View};
use events::UIEvents;
pub type Frame<'a> = tui::Frame<'a, CrosstermBackend<Stdout>>;
pub type Terminal = tui::Terminal<CrosstermBackend<Stdout>>;
pub type Frame<'a> = ratatui::Frame<'a, CrosstermBackend<Stdout>>;
pub type Terminal = ratatui::Terminal<CrosstermBackend<Stdout>>;
pub type ConfigMap = HashMap<String, Value>;
#[derive(Debug, Clone)]

View file

@ -1,4 +1,4 @@
use tui::{
use ratatui::{
buffer::Buffer,
layout::Rect,
style::{Modifier, Style},

View file

@ -1,7 +1,7 @@
use std::borrow::Cow;
use ansi_str::{get_blocks, AnsiStr};
use tui::{
use ratatui::{
layout::Rect,
style::{Color, Modifier, Style},
widgets::Widget,
@ -24,7 +24,7 @@ impl<'a> ColoredTextW<'a> {
}
impl Widget for ColoredTextW<'_> {
fn render(self, area: Rect, buf: &mut tui::buffer::Buffer) {
fn render(self, area: Rect, buf: &mut ratatui::buffer::Buffer) {
let text = cut_string(self.text, area, self.col);
let mut offset = 0;

View file

@ -7,7 +7,7 @@ use nu_protocol::{
Value,
};
use nu_table::TextStyle;
use tui::{
use ratatui::{
layout::Rect,
style::Style,
widgets::{BorderType, Borders, Paragraph},
@ -197,13 +197,13 @@ impl View for ConfigurationView {
let view_content_area = Rect::new(view_content_x1, 1, view_content_w, view_content_h);
let option_block = tui::widgets::Block::default()
let option_block = ratatui::widgets::Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(border_color);
let option_area = Rect::new(option_b_x1, area.y, OPTION_BLOCK_WIDTH, area.height);
let view_block = tui::widgets::Block::default()
let view_block = ratatui::widgets::Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(border_color);

View file

@ -1,7 +1,7 @@
use crossterm::event::KeyEvent;
use nu_color_config::TextStyle;
use nu_protocol::engine::{EngineState, Stack};
use tui::{layout::Rect, widgets::Paragraph};
use ratatui::{layout::Rect, widgets::Paragraph};
use crate::{
nu_common::NuText,

View file

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
PipelineData, Value,
};
use tui::{
use ratatui::{
layout::Rect,
style::{Modifier, Style},
widgets::{BorderType, Borders, Paragraph},
@ -67,7 +67,7 @@ impl View for InteractiveView<'_> {
let border_color = self.border_color;
let highlighted_color = self.highlighted_color;
let cmd_block = tui::widgets::Block::default()
let cmd_block = ratatui::widgets::Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(border_color);
@ -119,7 +119,7 @@ impl View for InteractiveView<'_> {
}
}
let table_block = tui::widgets::Block::default()
let table_block = ratatui::widgets::Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(border_color);

View file

@ -13,7 +13,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::layout::Rect;
use ratatui::layout::Rect;
use crate::{nu_common::NuConfig, pager::ConfigMap};

View file

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::layout::Rect;
use ratatui::layout::Rect;
use crate::{
nu_common::{NuSpan, NuText},

View file

@ -8,7 +8,7 @@ use nu_protocol::{
engine::{EngineState, Stack},
Value,
};
use tui::{layout::Rect, widgets::Block};
use ratatui::{layout::Rect, widgets::Block};
use crate::{
nu_common::{collect_input, lscolorize, NuConfig, NuSpan, NuStyle, NuText},

View file

@ -6,7 +6,7 @@ use std::{
use nu_color_config::{Alignment, StyleComputer, TextStyle};
use nu_protocol::Value;
use nu_table::string_width;
use tui::{
use ratatui::{
buffer::Buffer,
layout::Rect,
text::Span,
@ -91,8 +91,8 @@ impl StatefulWidget for TableW<'_> {
fn render(
self,
area: tui::layout::Rect,
buf: &mut tui::buffer::Buffer,
area: ratatui::layout::Rect,
buf: &mut ratatui::buffer::Buffer,
state: &mut Self::State,
) {
if area.width < 5 {
@ -572,7 +572,7 @@ impl Widget for IndexColumn<'_> {
let p = Paragraph::new(text)
.style(style)
.alignment(tui::layout::Alignment::Right);
.alignment(ratatui::layout::Alignment::Right);
let area = Rect::new(area.x, area.y + row, area.width, 1);
p.render(area, buf);
@ -690,7 +690,7 @@ fn create_column(data: &[Vec<NuText>], col: usize) -> Vec<NuText> {
}
fn repeat_vertical(
buf: &mut tui::buffer::Buffer,
buf: &mut ratatui::buffer::Buffer,
x_offset: u16,
y_offset: u16,
width: u16,
@ -755,7 +755,7 @@ fn calculate_column_width(column: &[NuText]) -> usize {
}
fn render_column(
buf: &mut tui::buffer::Buffer,
buf: &mut ratatui::buffer::Buffer,
x: u16,
y: u16,
available_width: u16,

View file

@ -3,7 +3,7 @@ use std::borrow::Cow;
use nu_color_config::{Alignment, StyleComputer};
use nu_protocol::{ShellError, Value};
use nu_table::{string_width, TextStyle};
use tui::{
use ratatui::{
buffer::Buffer,
style::{Color, Modifier, Style},
text::Span,
@ -33,8 +33,8 @@ pub fn set_span(
text_width as u16
}
pub fn nu_style_to_tui(style: NuStyle) -> tui::style::Style {
let mut out = tui::style::Style::default();
pub fn nu_style_to_tui(style: NuStyle) -> ratatui::style::Style {
let mut out = ratatui::style::Style::default();
if let Some(clr) = style.background {
out.bg = nu_ansi_color_to_tui_color(clr);
}
@ -74,7 +74,7 @@ pub fn nu_style_to_tui(style: NuStyle) -> tui::style::Style {
out
}
pub fn nu_ansi_color_to_tui_color(clr: NuColor) -> Option<tui::style::Color> {
pub fn nu_ansi_color_to_tui_color(clr: NuColor) -> Option<ratatui::style::Color> {
use NuColor::*;
let clr = match clr {
@ -94,7 +94,7 @@ pub fn nu_ansi_color_to_tui_color(clr: NuColor) -> Option<tui::style::Color> {
LightCyan => Color::LightCyan,
White => Color::White,
Fixed(i) => Color::Indexed(i),
Rgb(r, g, b) => tui::style::Color::Rgb(r, g, b),
Rgb(r, g, b) => ratatui::style::Color::Rgb(r, g, b),
LightGray => Color::Gray,
LightPurple => Color::LightMagenta,
Purple => Color::Magenta,
@ -104,8 +104,8 @@ pub fn nu_ansi_color_to_tui_color(clr: NuColor) -> Option<tui::style::Color> {
Some(clr)
}
pub fn text_style_to_tui_style(style: TextStyle) -> tui::style::Style {
let mut out = tui::style::Style::default();
pub fn text_style_to_tui_style(style: TextStyle) -> ratatui::style::Style {
let mut out = ratatui::style::Style::default();
if let Some(style) = style.color_style {
out = nu_style_to_tui(style);
}