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-protocol",
"nu-table", "nu-table",
"nu-utils", "nu-utils",
"ratatui",
"strip-ansi-escapes", "strip-ansi-escapes",
"terminal_size 0.2.6", "terminal_size 0.2.6",
"tui",
] ]
[[package]] [[package]]
@ -4269,6 +4269,19 @@ dependencies = [
"rand_core 0.5.1", "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]] [[package]]
name = "rayon" name = "rayon"
version = "1.7.0" version = "1.7.0"
@ -5463,19 +5476,6 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" 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]] [[package]]
name = "typed-arena" name = "typed-arena"
version = "1.7.0" version = "1.7.0"

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,7 @@ use nu_protocol::{
Value, Value,
}; };
use nu_table::TextStyle; use nu_table::TextStyle;
use tui::{ use ratatui::{
layout::Rect, layout::Rect,
style::Style, style::Style,
widgets::{BorderType, Borders, Paragraph}, 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 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) .borders(Borders::ALL)
.border_type(BorderType::Plain) .border_type(BorderType::Plain)
.border_style(border_color); .border_style(border_color);
let option_area = Rect::new(option_b_x1, area.y, OPTION_BLOCK_WIDTH, area.height); 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) .borders(Borders::ALL)
.border_type(BorderType::Plain) .border_type(BorderType::Plain)
.border_style(border_color); .border_style(border_color);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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