feat: migrate to ratatui (#26)
Co-authored-by: Ben PHL <benphawke@gmail.com>
This commit is contained in:
+2
-2
@@ -12,9 +12,9 @@ include = ["src/**/*", "README.md"]
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tui = { version = "0.19", default-features = false }
|
ratatui = { version = "0.23", default-features = false }
|
||||||
unicode-width = "0.1"
|
unicode-width = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
crossterm = "0.27"
|
crossterm = "0.27"
|
||||||
tui = "0.19"
|
ratatui = "0.23"
|
||||||
|
|||||||
+2
-2
@@ -6,13 +6,13 @@ use crossterm::{
|
|||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
};
|
};
|
||||||
use std::{error::Error, io};
|
use ratatui::{
|
||||||
use tui::{
|
|
||||||
backend::{Backend, CrosstermBackend},
|
backend::{Backend, CrosstermBackend},
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
widgets::{Block, Borders},
|
widgets::{Block, Borders},
|
||||||
Terminal,
|
Terminal,
|
||||||
};
|
};
|
||||||
|
use std::{error::Error, io};
|
||||||
|
|
||||||
use tui_tree_widget::{Tree, TreeItem};
|
use tui_tree_widget::{Tree, TreeItem};
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -46,11 +46,11 @@ fn internal<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn get_naive_string_from_text(text: &tui::text::Text<'_>) -> String {
|
fn get_naive_string_from_text(text: &ratatui::text::Text<'_>) -> String {
|
||||||
text.lines
|
text.lines
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.spans
|
||||||
.first()
|
.first()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.content
|
.content
|
||||||
|
|||||||
+9
-9
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use tui::buffer::Buffer;
|
use ratatui::buffer::Buffer;
|
||||||
use tui::layout::{Corner, Rect};
|
use ratatui::layout::{Corner, Rect};
|
||||||
use tui::style::Style;
|
use ratatui::style::Style;
|
||||||
use tui::text::Text;
|
use ratatui::text::Text;
|
||||||
use tui::widgets::{Block, StatefulWidget, Widget};
|
use ratatui::widgets::{Block, StatefulWidget, Widget};
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
mod flatten;
|
mod flatten;
|
||||||
@@ -247,9 +247,9 @@ impl<'a> TreeItem<'a> {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use tui_tree_widget::{Tree, TreeItem, TreeState};
|
/// # use tui_tree_widget::{Tree, TreeItem, TreeState};
|
||||||
/// # use tui::backend::TestBackend;
|
/// # use ratatui::backend::TestBackend;
|
||||||
/// # use tui::Terminal;
|
/// # use ratatui::Terminal;
|
||||||
/// # use tui::widgets::{Block, Borders};
|
/// # use ratatui::widgets::{Block, Borders};
|
||||||
/// # fn main() -> std::io::Result<()> {
|
/// # fn main() -> std::io::Result<()> {
|
||||||
/// # let mut terminal = Terminal::new(TestBackend::new(32, 32)).unwrap();
|
/// # let mut terminal = Terminal::new(TestBackend::new(32, 32)).unwrap();
|
||||||
/// let mut state = TreeState::default();
|
/// let mut state = TreeState::default();
|
||||||
@@ -480,7 +480,7 @@ impl<'a> StatefulWidget for Tree<'a> {
|
|||||||
|
|
||||||
let max_element_width = area.width.saturating_sub(after_depth_x - x);
|
let max_element_width = area.width.saturating_sub(after_depth_x - x);
|
||||||
for (j, line) in item.item.text.lines.iter().enumerate() {
|
for (j, line) in item.item.text.lines.iter().enumerate() {
|
||||||
buf.set_spans(after_depth_x, y + j as u16, line, max_element_width);
|
buf.set_line(after_depth_x, y + j as u16, line, max_element_width);
|
||||||
}
|
}
|
||||||
if is_selected {
|
if is_selected {
|
||||||
buf.set_style(area, self.highlight_style);
|
buf.set_style(area, self.highlight_style);
|
||||||
|
|||||||
Reference in New Issue
Block a user