From 4679ddc885a9b35c901f3600b63fd9e86118264c Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sat, 3 Jun 2023 20:30:00 +0000 Subject: [PATCH] chore: `Spans` -> `Line`, ratatui 0.21 update --- src/ui/color_match.rs | 12 +++++------ src/ui/draw_blocks.rs | 46 +++++++++++++++++++++---------------------- src/ui/mod.rs | 4 +--- 3 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/ui/color_match.rs b/src/ui/color_match.rs index 2e349f6..104a2ae 100644 --- a/src/ui/color_match.rs +++ b/src/ui/color_match.rs @@ -3,12 +3,12 @@ pub mod log_sanitizer { use cansi::{v3::categorise_text, Color as CansiColor, Intensity}; use ratatui::{ style::{Color, Modifier, Style}, - text::{Span, Spans}, + text::{Span, Line}, }; /// Attempt to colorize the given string to tui-rs standards - pub fn colorize_logs<'a>(input: &str) -> Vec> { - vec![Spans::from( + pub fn colorize_logs<'a>(input: &str) -> Vec> { + vec![Line::from( categorise_text(input) .iter() .map(|i| { @@ -40,7 +40,7 @@ pub mod log_sanitizer { } /// Remove all ansi formatting from a given string and create tui-rs spans - pub fn remove_ansi<'a>(input: &str) -> Vec> { + pub fn remove_ansi<'a>(input: &str) -> Vec> { raw(&categorise_text(input) .into_iter() .map(|i| i.text) @@ -48,8 +48,8 @@ pub mod log_sanitizer { } /// create tui-rs spans that exactly match the given strings - pub fn raw<'a>(input: &str) -> Vec> { - vec![Spans::from(Span::raw(input.to_owned()))] + pub fn raw<'a>(input: &str) -> Vec> { + vec![Line::from(Span::raw(input.to_owned()))] } /// Change from ansi to tui colors diff --git a/src/ui/draw_blocks.rs b/src/ui/draw_blocks.rs index 29e5589..4bbe359 100644 --- a/src/ui/draw_blocks.rs +++ b/src/ui/draw_blocks.rs @@ -4,7 +4,7 @@ use ratatui::{ layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, symbols, - text::{Span, Spans}, + text::{Span, Line}, widgets::{ Axis, Block, BorderType, Borders, Chart, Clear, Dataset, GraphType, List, ListItem, Paragraph, @@ -96,7 +96,7 @@ pub fn commands( let items = app_data.lock().get_control_items().map_or(vec![], |i| { i.iter() .map(|c| { - let lines = Spans::from(vec![Span::styled( + let lines = Line::from(vec![Span::styled( c.to_string(), Style::default().fg(c.get_color()), )]); @@ -138,7 +138,7 @@ pub fn containers( let state_style = Style::default().fg(i.state.get_color()); let blue = Style::default().fg(Color::Blue); - let lines = Spans::from(vec![ + let lines = Line::from(vec![ Span::styled( format!( "{:( /// Help popup box needs these three pieces of information struct HelpInfo { - spans: Vec>, + spans: Vec>, width: usize, height: usize, } impl HelpInfo { - /// Find the max width of a Span in &[Spans], although it isn't calculating it correctly - fn calc_width(spans: &[Spans]) -> usize { - spans + /// Find the max width of a Span in &[Line], although it isn't calculating it correctly + fn calc_width(lines: &[Line]) -> usize { + lines .iter() - .flat_map(|x| x.0.iter()) + .flat_map(|x| x.spans.iter()) .map(ratatui::text::Span::width) .max() .unwrap_or(1) } /// Just an empty span, i.e. a new line - fn empty_span<'a>() -> Spans<'a> { - Spans::from(String::new()) + fn empty_span<'a>() -> Line<'a> { + Line::from(String::new()) } /// generate a span, of given &str and given color @@ -529,7 +529,7 @@ impl HelpInfo { fn gen_name() -> Self { let mut spans = NAME_TEXT .lines() - .map(|i| Spans::from(Self::white_span(i))) + .map(|i| Line::from(Self::white_span(i))) .collect::>(); spans.insert(0, Self::empty_span()); let width = Self::calc_width(&spans); @@ -545,7 +545,7 @@ impl HelpInfo { fn gen_description() -> Self { let spans = [ Self::empty_span(), - Spans::from(Self::white_span(DESCRIPTION)), + Line::from(Self::white_span(DESCRIPTION)), Self::empty_span(), ]; let width = Self::calc_width(&spans); @@ -565,14 +565,14 @@ impl HelpInfo { let space = || button_desc(" "); let spans = [ - Spans::from(vec![ + Line::from(vec![ space(), button_item("tab"), or(), button_item("shift+tab"), button_desc("to change panels"), ]), - Spans::from(vec![ + Line::from(vec![ space(), button_item("↑ ↓"), or(), @@ -583,30 +583,30 @@ impl HelpInfo { button_item("Home End"), button_desc("to change selected line"), ]), - Spans::from(vec![ + Line::from(vec![ space(), button_item("enter"), button_desc("to send docker container command"), ]), - Spans::from(vec![ + Line::from(vec![ space(), button_item("h"), button_desc("to toggle this help information"), ]), - Spans::from(vec![space(), button_item("0"), button_desc("to stop sort")]), - Spans::from(vec![ + Line::from(vec![space(), button_item("0"), button_desc("to stop sort")]), + Line::from(vec![ space(), button_item("1 - 9"), button_desc("sort by header - or click header"), ]), - Spans::from(vec![ + Line::from(vec![ space(), button_item("m"), button_desc( "to toggle mouse capture - if disabled, text on screen can be selected & copied", ), ]), - Spans::from(vec![ + Line::from(vec![ space(), button_item("q"), button_desc("to quit at any time"), @@ -626,10 +626,10 @@ impl HelpInfo { fn gen_final() -> Self { let spans = [ Self::empty_span(), - Spans::from(vec![Self::black_span( + Line::from(vec![Self::black_span( "currently an early work in progress, all and any input appreciated", )]), - Spans::from(vec![Span::styled( + Line::from(vec![Span::styled( REPO.to_owned(), Style::default() .fg(Color::White) @@ -738,7 +738,7 @@ pub fn delete_confirm( .title_alignment(Alignment::Center) .borders(Borders::ALL); - let confirm = Spans::from(vec![ + let confirm = Line::from(vec![ Span::from("Are you sure you want to delete container: "), Span::styled( name, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 53ec6a1..e70dec4 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -278,9 +278,7 @@ fn draw_frame( ); if let Some(id) = delete_confirm { - let name = app_data.lock().get_container_name_by_id(&id); - name.map_or_else( - || { + app_data.lock().get_container_name_by_id(&id).map_or_else(|| { // If a container is deleted outside of oxker but whilst the Delete Confirm dialog is open, it can get caught in kind of a dead lock situation // so if in that unique situation, just clear the delete_container id gui_state.lock().set_delete_container(None);