deps: bump ratatui to 0.21.0 (#1178)

This commit is contained in:
Clement Tsang 2023-05-31 00:21:55 -04:00 committed by GitHub
parent 74953455dc
commit 4e99f31ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 85 additions and 84 deletions

4
Cargo.lock generated
View File

@ -906,9 +906,9 @@ dependencies = [
[[package]] [[package]]
name = "ratatui" name = "ratatui"
version = "0.20.1" version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829" checksum = "ce841e0486e7c2412c3740168ede33adeba8e154a15107b879d8162d77c7174e"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cassowary", "cassowary",

View File

@ -101,7 +101,7 @@ sysinfo = "=0.29.0"
thiserror = "1.0.40" thiserror = "1.0.40"
time = { version = "0.3.21", features = ["formatting", "macros"] } time = { version = "0.3.21", features = ["formatting", "macros"] }
toml_edit = { version = "0.19.10", features = ["serde"] } toml_edit = { version = "0.19.10", features = ["serde"] }
tui = { version = "0.20.1", package = "ratatui" } tui = { version = "0.21.0", package = "ratatui" }
typed-builder = "0.14.0" typed-builder = "0.14.0"
unicode-segmentation = "1.10.1" unicode-segmentation = "1.10.1"
unicode-width = "0.1.10" unicode-width = "0.1.10"

View File

@ -5,7 +5,7 @@ use itertools::izip;
use tui::{ use tui::{
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
text::{Span, Spans}, text::{Line, Span},
widgets::Paragraph, widgets::Paragraph,
Frame, Terminal, Frame, Terminal,
}; };
@ -62,7 +62,7 @@ pub struct Painter {
pub colours: CanvasStyling, pub colours: CanvasStyling,
height: u16, height: u16,
width: u16, width: u16,
styled_help_text: Vec<Spans<'static>>, styled_help_text: Vec<Line<'static>>,
is_mac_os: bool, // TODO: This feels out of place... is_mac_os: bool, // TODO: This feels out of place...
// TODO: Redo this entire thing. // TODO: Redo this entire thing.
@ -212,7 +212,7 @@ impl Painter {
} }
}); });
self.styled_help_text = styled_help_spans.into_iter().map(Spans::from).collect(); self.styled_help_text = styled_help_spans.into_iter().map(Line::from).collect();
} }
fn draw_frozen_indicator<B: Backend>(&self, f: &mut Frame<'_, B>, draw_loc: Rect) { fn draw_frozen_indicator<B: Backend>(&self, f: &mut Frame<'_, B>, draw_loc: Rect) {

View File

@ -5,7 +5,7 @@ use tui::{
backend::Backend, backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame, terminal::Frame,
text::{Span, Spans, Text}, text::{Line, Span, Text},
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph, Wrap},
}; };
@ -22,15 +22,15 @@ impl Painter {
pub fn get_dd_spans(&self, app_state: &App) -> Option<Text<'_>> { pub fn get_dd_spans(&self, app_state: &App) -> Option<Text<'_>> {
if let Some(dd_err) = &app_state.dd_err { if let Some(dd_err) = &app_state.dd_err {
return Some(Text::from(vec![ return Some(Text::from(vec![
Spans::default(), Line::default(),
Spans::from("Failed to kill process."), Line::from("Failed to kill process."),
Spans::from(dd_err.clone()), Line::from(dd_err.clone()),
Spans::from("Please press ENTER or ESC to close this dialog."), Line::from("Please press ENTER or ESC to close this dialog."),
])); ]));
} else if let Some(to_kill_processes) = app_state.get_to_delete_processes() { } else if let Some(to_kill_processes) = app_state.get_to_delete_processes() {
if let Some(first_pid) = to_kill_processes.1.first() { if let Some(first_pid) = to_kill_processes.1.first() {
return Some(Text::from(vec![ return Some(Text::from(vec![
Spans::from(""), Line::from(""),
if app_state if app_state
.states .states
.proc_state .proc_state
@ -40,19 +40,19 @@ impl Painter {
.unwrap_or(false) .unwrap_or(false)
{ {
if to_kill_processes.1.len() != 1 { if to_kill_processes.1.len() != 1 {
Spans::from(format!( Line::from(format!(
"Kill {} processes with the name \"{}\"? Press ENTER to confirm.", "Kill {} processes with the name \"{}\"? Press ENTER to confirm.",
to_kill_processes.1.len(), to_kill_processes.1.len(),
to_kill_processes.0 to_kill_processes.0
)) ))
} else { } else {
Spans::from(format!( Line::from(format!(
"Kill 1 process with the name \"{}\"? Press ENTER to confirm.", "Kill 1 process with the name \"{}\"? Press ENTER to confirm.",
to_kill_processes.0 to_kill_processes.0
)) ))
} }
} else { } else {
Spans::from(format!( Line::from(format!(
"Kill process \"{}\" with PID {}? Press ENTER to confirm.", "Kill process \"{}\" with PID {}? Press ENTER to confirm.",
to_kill_processes.0, first_pid to_kill_processes.0, first_pid
)) ))
@ -358,7 +358,7 @@ impl Painter {
) -> bool { ) -> bool {
if let Some(dd_text) = dd_text { if let Some(dd_text) = dd_text {
let dd_title = if app_state.dd_err.is_some() { let dd_title = if app_state.dd_err.is_some() {
Spans::from(vec![ Line::from(vec![
Span::styled(" Error ", self.colours.widget_title_style), Span::styled(" Error ", self.colours.widget_title_style),
Span::styled( Span::styled(
format!( format!(
@ -372,7 +372,7 @@ impl Painter {
), ),
]) ])
} else { } else {
Spans::from(vec![ Line::from(vec![
Span::styled(" Confirm Kill Process ", self.colours.widget_title_style), Span::styled(" Confirm Kill Process ", self.colours.widget_title_style),
Span::styled( Span::styled(
format!( format!(

View File

@ -4,8 +4,8 @@ use tui::{
backend::Backend, backend::Backend,
layout::{Alignment, Rect}, layout::{Alignment, Rect},
terminal::Frame, terminal::Frame,
text::Line,
text::Span, text::Span,
text::Spans,
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph, Wrap},
}; };
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -19,7 +19,7 @@ impl Painter {
pub fn draw_help_dialog<B: Backend>( pub fn draw_help_dialog<B: Backend>(
&self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect,
) { ) {
let help_title = Spans::from(vec![ let help_title = Line::from(vec![
Span::styled(" Help ", self.colours.widget_title_style), Span::styled(" Help ", self.colours.widget_title_style),
Span::styled( Span::styled(
format!( format!(

View File

@ -2,8 +2,8 @@ use tui::{
backend::Backend, backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
terminal::Frame, terminal::Frame,
text::Line,
text::Span, text::Span,
text::Spans,
widgets::{Block, Paragraph}, widgets::{Block, Paragraph},
}; };
@ -93,16 +93,16 @@ impl Painter {
usize::from(draw_loc.width).saturating_sub(6 + left_name.len() + right_name.len()); usize::from(draw_loc.width).saturating_sub(6 + left_name.len() + right_name.len());
let left_arrow_text = vec![ let left_arrow_text = vec![
Spans::default(), Line::default(),
Spans::from(Span::styled( Line::from(Span::styled(
format!("{}", left_name), format!("{}", left_name),
self.colours.text_style, self.colours.text_style,
)), )),
]; ];
let right_arrow_text = vec![ let right_arrow_text = vec![
Spans::default(), Line::default(),
Spans::from(Span::styled( Line::from(Span::styled(
format!("{}", right_name), format!("{}", right_name),
self.colours.text_style, self.colours.text_style,
)), )),

View File

@ -2,7 +2,7 @@ use tui::{
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
terminal::Frame, terminal::Frame,
text::{Span, Spans}, text::{Line, Span},
widgets::{Block, Borders, Cell, Paragraph, Row, Table, Tabs}, widgets::{Block, Borders, Cell, Paragraph, Row, Table, Tabs},
}; };
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
@ -40,7 +40,7 @@ impl Painter {
let title = if app_state.is_expanded { let title = if app_state.is_expanded {
const TITLE_BASE: &str = " Battery ── Esc to go back "; const TITLE_BASE: &str = " Battery ── Esc to go back ";
Spans::from(vec![ Line::from(vec![
Span::styled(" Battery ", self.colours.widget_title_style), Span::styled(" Battery ", self.colours.widget_title_style),
Span::styled( Span::styled(
format!( format!(
@ -53,7 +53,7 @@ impl Painter {
), ),
]) ])
} else { } else {
Spans::from(Span::styled(" Battery ", self.colours.widget_title_style)) Line::from(Span::styled(" Battery ", self.colours.widget_title_style))
}; };
let battery_block = if draw_border { let battery_block = if draw_border {
@ -89,7 +89,7 @@ impl Painter {
Tabs::new( Tabs::new(
battery_names battery_names
.iter() .iter()
.map(|name| Spans::from((*name).clone())) .map(|name| Line::from((*name).clone()))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
) )
.block(Block::default()) .block(Block::default())
@ -227,9 +227,9 @@ impl Painter {
margined_draw_loc, margined_draw_loc,
); );
} else { } else {
let mut contents = vec![Spans::default(); table_gap.into()]; let mut contents = vec![Line::default(); table_gap.into()];
contents.push(Spans::from(Span::styled( contents.push(Line::from(Span::styled(
"No data found for this battery", "No data found for this battery",
self.colours.text_style, self.colours.text_style,
))); )));

View File

@ -2,7 +2,7 @@ use tui::{
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
terminal::Frame, terminal::Frame,
text::{Span, Spans}, text::{Line, Span},
widgets::{Block, Paragraph}, widgets::{Block, Paragraph},
}; };
@ -44,13 +44,13 @@ impl Painter {
let total_tx_label = format!("Total TX: {}", &app_state.converted_data.total_tx_display); let total_tx_label = format!("Total TX: {}", &app_state.converted_data.total_tx_display);
let net_text = vec![ let net_text = vec![
Spans::from(Span::styled(rx_label, self.colours.rx_style)), Line::from(Span::styled(rx_label, self.colours.rx_style)),
Spans::from(Span::styled(tx_label, self.colours.tx_style)), Line::from(Span::styled(tx_label, self.colours.tx_style)),
]; ];
let total_net_text = vec![ let total_net_text = vec![
Spans::from(Span::styled(total_rx_label, self.colours.total_rx_style)), Line::from(Span::styled(total_rx_label, self.colours.total_rx_style)),
Spans::from(Span::styled(total_tx_label, self.colours.total_tx_style)), Line::from(Span::styled(total_tx_label, self.colours.total_tx_style)),
]; ];
f.render_widget(Paragraph::new(net_text).block(Block::default()), net_loc[0]); f.render_widget(Paragraph::new(net_text).block(Block::default()), net_loc[0]);

View File

@ -3,7 +3,7 @@ use tui::{
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
style::Style, style::Style,
terminal::Frame, terminal::Frame,
text::{Span, Spans}, text::{Line, Span},
widgets::{Block, Borders, Paragraph}, widgets::{Block, Borders, Paragraph},
}; };
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
@ -185,7 +185,7 @@ impl Painter {
self.colours.text_style, self.colours.text_style,
); );
let mut search_text = vec![Spans::from({ let mut search_text = vec![Line::from({
let mut search_vec = vec![Span::styled( let mut search_vec = vec![Span::styled(
SEARCH_TITLE, SEARCH_TITLE,
if is_on_widget { if is_on_widget {
@ -225,7 +225,7 @@ impl Painter {
} else { } else {
("Case(Alt+C)", "Whole(Alt+W)", "Regex(Alt+R)") ("Case(Alt+C)", "Whole(Alt+W)", "Regex(Alt+R)")
}; };
let option_text = Spans::from(vec![ let option_text = Line::from(vec![
Span::styled(case, case_style), Span::styled(case, case_style),
Span::raw(" "), Span::raw(" "),
Span::styled(whole, whole_word_style), Span::styled(whole, whole_word_style),
@ -233,7 +233,7 @@ impl Painter {
Span::styled(regex, regex_style), Span::styled(regex, regex_style),
]); ]);
search_text.push(Spans::from(Span::styled( search_text.push(Line::from(Span::styled(
if let Some(err) = &proc_widget_state.proc_search.search_state.error_message { if let Some(err) = &proc_widget_state.proc_search.search_state.error_message {
err.as_str() err.as_str()
} else { } else {

View File

@ -7,7 +7,7 @@ use concat_string::concat_string;
use tui::{ use tui::{
backend::Backend, backend::Backend,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
text::{Span, Spans, Text}, text::{Line, Span, Text},
widgets::{Block, Borders, Row, Table}, widgets::{Block, Borders, Row, Table},
Frame, Frame,
}; };
@ -98,7 +98,7 @@ where
/// Generates a title, given the available space. /// Generates a title, given the available space.
pub fn generate_title<'a>( pub fn generate_title<'a>(
&self, draw_info: &'a DrawInfo, total_items: usize, &self, draw_info: &'a DrawInfo, total_items: usize,
) -> Option<Spans<'a>> { ) -> Option<Line<'a>> {
self.props.title.as_ref().map(|title| { self.props.title.as_ref().map(|title| {
let current_index = self.state.current_index.saturating_add(1); let current_index = self.state.current_index.saturating_add(1);
let draw_loc = draw_info.loc; let draw_loc = draw_info.loc;
@ -129,12 +129,12 @@ where
UnicodeSegmentation::graphemes(title_base.as_str(), true).count() + 2, UnicodeSegmentation::graphemes(title_base.as_str(), true).count() + 2,
)); ));
let esc = concat_string!("", lines, "─ Esc to go back "); let esc = concat_string!("", lines, "─ Esc to go back ");
Spans::from(vec![ Line::from(vec![
Span::styled(title, title_style), Span::styled(title, title_style),
Span::styled(esc, border_style), Span::styled(esc, border_style),
]) ])
} else { } else {
Spans::from(Span::styled(title, title_style)) Line::from(Span::styled(title, title_style))
} }
}) })
} }

View File

@ -6,7 +6,7 @@ use tui::{
layout::{Constraint, Rect}, layout::{Constraint, Rect},
style::Style, style::Style,
symbols::Marker, symbols::Marker,
text::{Span, Spans}, text::{Line, Span},
widgets::{Block, Borders, GraphType}, widgets::{Block, Borders, GraphType},
Frame, Frame,
}; };
@ -96,10 +96,10 @@ impl<'a> TimeGraph<'a> {
} }
/// Generates a title for the [`TimeGraph`] widget, given the available space. /// Generates a title for the [`TimeGraph`] widget, given the available space.
fn generate_title(&self, draw_loc: Rect) -> Spans<'_> { fn generate_title(&self, draw_loc: Rect) -> Line<'_> {
if self.is_expanded { if self.is_expanded {
let title_base = concat_string!(self.title, "── Esc to go back "); let title_base = concat_string!(self.title, "── Esc to go back ");
Spans::from(vec![ Line::from(vec![
Span::styled(self.title.as_ref(), self.title_style), Span::styled(self.title.as_ref(), self.title_style),
Span::styled( Span::styled(
concat_string!( concat_string!(
@ -113,7 +113,7 @@ impl<'a> TimeGraph<'a> {
), ),
]) ])
} else { } else {
Spans::from(Span::styled(self.title.as_ref(), self.title_style)) Line::from(Span::styled(self.title.as_ref(), self.title_style))
} }
} }
@ -182,7 +182,7 @@ mod test {
layout::Rect, layout::Rect,
style::{Color, Style}, style::{Color, Style},
symbols::Marker, symbols::Marker,
text::{Span, Spans}, text::{Line, Span},
}; };
use super::TimeGraph; use super::TimeGraph;
@ -253,14 +253,14 @@ mod test {
let title = time_graph.generate_title(draw_loc); let title = time_graph.generate_title(draw_loc);
assert_eq!( assert_eq!(
title, title,
Spans::from(Span::styled(" Network ", Style::default().fg(Color::Cyan))) Line::from(Span::styled(" Network ", Style::default().fg(Color::Cyan)))
); );
time_graph.is_expanded = true; time_graph.is_expanded = true;
let title = time_graph.generate_title(draw_loc); let title = time_graph.generate_title(draw_loc);
assert_eq!( assert_eq!(
title, title,
Spans::from(vec![ Line::from(vec![
Span::styled(" Network ", Style::default().fg(Color::Cyan)), Span::styled(" Network ", Style::default().fg(Color::Cyan)),
Span::styled("───── Esc to go back ", Style::default().fg(Color::Blue)) Span::styled("───── Esc to go back ", Style::default().fg(Color::Blue))
]) ])

View File

@ -2,7 +2,7 @@ use tui::{
buffer::Buffer, buffer::Buffer,
layout::Rect, layout::Rect,
style::Style, style::Style,
text::Spans, text::Line,
widgets::{Block, Widget}, widgets::{Block, Widget},
}; };
@ -25,8 +25,8 @@ impl Default for LabelLimit {
pub struct PipeGauge<'a> { pub struct PipeGauge<'a> {
block: Option<Block<'a>>, block: Option<Block<'a>>,
ratio: f64, ratio: f64,
start_label: Option<Spans<'a>>, start_label: Option<Line<'a>>,
inner_label: Option<Spans<'a>>, inner_label: Option<Line<'a>>,
label_style: Style, label_style: Style,
gauge_style: Style, gauge_style: Style,
hide_parts: LabelLimit, hide_parts: LabelLimit,
@ -60,7 +60,7 @@ impl<'a> PipeGauge<'a> {
/// The label displayed before the bar. /// The label displayed before the bar.
pub fn start_label<T>(mut self, start_label: T) -> Self pub fn start_label<T>(mut self, start_label: T) -> Self
where where
T: Into<Spans<'a>>, T: Into<Line<'a>>,
{ {
self.start_label = Some(start_label.into()); self.start_label = Some(start_label.into());
self self
@ -69,7 +69,7 @@ impl<'a> PipeGauge<'a> {
/// The label displayed inside the bar. /// The label displayed inside the bar.
pub fn inner_label<T>(mut self, inner_label: T) -> Self pub fn inner_label<T>(mut self, inner_label: T) -> Self
where where
T: Into<Spans<'a>>, T: Into<Line<'a>>,
{ {
self.inner_label = Some(inner_label.into()); self.inner_label = Some(inner_label.into());
self self
@ -125,8 +125,8 @@ impl<'a> Widget for PipeGauge<'a> {
match self.hide_parts { match self.hide_parts {
LabelLimit::StartLabel => { LabelLimit::StartLabel => {
let inner_label = self.inner_label.unwrap_or_else(|| Spans::from("")); let inner_label = self.inner_label.unwrap_or_else(|| Line::from(""));
let _ = buf.set_spans( let _ = buf.set_line(
gauge_area.left(), gauge_area.left(),
gauge_area.top(), gauge_area.top(),
&inner_label, &inner_label,
@ -139,8 +139,8 @@ impl<'a> Widget for PipeGauge<'a> {
LabelLimit::Auto(_) LabelLimit::Auto(_)
if gauge_area.width < (inner_label_width + start_label_width + 1) as u16 => if gauge_area.width < (inner_label_width + start_label_width + 1) as u16 =>
{ {
let inner_label = self.inner_label.unwrap_or_else(|| Spans::from("")); let inner_label = self.inner_label.unwrap_or_else(|| Line::from(""));
let _ = buf.set_spans( let _ = buf.set_line(
gauge_area.left(), gauge_area.left(),
gauge_area.top(), gauge_area.top(),
&inner_label, &inner_label,
@ -151,8 +151,8 @@ impl<'a> Widget for PipeGauge<'a> {
return; return;
} }
_ => { _ => {
let start_label = self.start_label.unwrap_or_else(|| Spans::from("")); let start_label = self.start_label.unwrap_or_else(|| Line::from(""));
buf.set_spans( buf.set_line(
gauge_area.left(), gauge_area.left(),
gauge_area.top(), gauge_area.top(),
&start_label, &start_label,
@ -162,10 +162,10 @@ impl<'a> Widget for PipeGauge<'a> {
} }
}; };
let end_label = self.inner_label.unwrap_or_else(|| Spans::from("")); let end_label = self.inner_label.unwrap_or_else(|| Line::from(""));
match self.hide_parts { match self.hide_parts {
LabelLimit::Bars => { LabelLimit::Bars => {
let _ = buf.set_spans( let _ = buf.set_line(
gauge_area gauge_area
.right() .right()
.saturating_sub(end_label.width() as u16 + 1), .saturating_sub(end_label.width() as u16 + 1),
@ -177,7 +177,7 @@ impl<'a> Widget for PipeGauge<'a> {
LabelLimit::Auto(width_limit) LabelLimit::Auto(width_limit)
if gauge_area.right().saturating_sub(col) < width_limit => if gauge_area.right().saturating_sub(col) < width_limit =>
{ {
let _ = buf.set_spans( let _ = buf.set_line(
gauge_area gauge_area
.right() .right()
.saturating_sub(end_label.width() as u16 + 1), .saturating_sub(end_label.width() as u16 + 1),
@ -187,15 +187,15 @@ impl<'a> Widget for PipeGauge<'a> {
); );
} }
LabelLimit::Auto(_) | LabelLimit::None => { LabelLimit::Auto(_) | LabelLimit::None => {
let (start, _) = buf.set_spans(col, row, &Spans::from("["), gauge_area.width); let (start, _) = buf.set_line(col, row, &Line::from("["), gauge_area.width);
if start >= gauge_area.right() { if start >= gauge_area.right() {
return; return;
} }
let (end, _) = buf.set_spans( let (end, _) = buf.set_line(
(gauge_area.x + gauge_area.width).saturating_sub(1), (gauge_area.x + gauge_area.width).saturating_sub(1),
row, row,
&Spans::from("]"), &Line::from("]"),
gauge_area.width, gauge_area.width,
); );
@ -214,7 +214,7 @@ impl<'a> Widget for PipeGauge<'a> {
let gauge_end = gauge_area let gauge_end = gauge_area
.right() .right()
.saturating_sub(end_label.width() as u16 + 1); .saturating_sub(end_label.width() as u16 + 1);
buf.set_spans(gauge_end, row, &end_label, end_label.width() as u16); buf.set_line(gauge_end, row, &end_label, end_label.width() as u16);
} }
} }
LabelLimit::StartLabel => unreachable!(), LabelLimit::StartLabel => unreachable!(),

View File

@ -8,9 +8,9 @@ use tui::{
layout::{Constraint, Rect}, layout::{Constraint, Rect},
style::{Color, Style}, style::{Color, Style},
symbols::{self, Marker}, symbols::{self, Marker},
text::{Span, Spans}, text::{Line, Span},
widgets::{ widgets::{
canvas::{Line, Points}, canvas::{Line as CanvasLine, Points},
Block, Borders, GraphType, Widget, Block, Borders, GraphType, Widget,
}, },
}; };
@ -25,7 +25,7 @@ pub type Point = (f64, f64);
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Axis<'a> { pub struct Axis<'a> {
/// Title displayed next to axis end /// Title displayed next to axis end
pub title: Option<Spans<'a>>, pub title: Option<Line<'a>>,
/// Bounds for the axis (all data points outside these limits will not be represented) /// Bounds for the axis (all data points outside these limits will not be represented)
pub bounds: [f64; 2], pub bounds: [f64; 2],
/// A list of labels to put to the left or below the axis /// A list of labels to put to the left or below the axis
@ -49,7 +49,7 @@ impl<'a> Default for Axis<'a> {
impl<'a> Axis<'a> { impl<'a> Axis<'a> {
pub fn title<T>(mut self, title: T) -> Axis<'a> pub fn title<T>(mut self, title: T) -> Axis<'a>
where where
T: Into<Spans<'a>>, T: Into<Line<'a>>,
{ {
self.title = Some(title.into()); self.title = Some(title.into());
self self
@ -460,7 +460,7 @@ impl<'a> Widget for TimeChart<'a> {
); );
if let GraphType::Line = dataset.graph_type { if let GraphType::Line = dataset.graph_type {
ctx.draw(&Line { ctx.draw(&CanvasLine {
x1: interpolated_point.0, x1: interpolated_point.0,
y1: interpolated_point.1, y1: interpolated_point.1,
x2: newer_point.0, x2: newer_point.0,
@ -478,7 +478,7 @@ impl<'a> Widget for TimeChart<'a> {
if let GraphType::Line = dataset.graph_type { if let GraphType::Line = dataset.graph_type {
for data in data_slice.windows(2) { for data in data_slice.windows(2) {
ctx.draw(&Line { ctx.draw(&CanvasLine {
x1: data[0].0, x1: data[0].0,
y1: data[0].1, y1: data[0].1,
x2: data[1].0, x2: data[1].0,
@ -504,7 +504,7 @@ impl<'a> Widget for TimeChart<'a> {
); );
if let GraphType::Line = dataset.graph_type { if let GraphType::Line = dataset.graph_type {
ctx.draw(&Line { ctx.draw(&CanvasLine {
x1: older_point.0, x1: older_point.0,
y1: older_point.1, y1: older_point.1,
x2: interpolated_point.0, x2: interpolated_point.0,
@ -551,7 +551,7 @@ impl<'a> Widget for TimeChart<'a> {
}, },
original_style, original_style,
); );
buf.set_spans(x, y, &title, width); buf.set_line(x, y, &title, width);
} }
if let Some((x, y)) = layout.title_y { if let Some((x, y)) = layout.title_y {
@ -566,7 +566,7 @@ impl<'a> Widget for TimeChart<'a> {
}, },
original_style, original_style,
); );
buf.set_spans(x, y, &title, width); buf.set_line(x, y, &title, width);
} }
} }
} }

View File

@ -10,9 +10,9 @@ use tui::{
layout::Rect, layout::Rect,
style::{Color, Style}, style::{Color, Style},
symbols, symbols,
text::Spans, text::Line,
widgets::{ widgets::{
canvas::{Line, Points}, canvas::{Line as CanvasLine, Points},
Block, Widget, Block, Widget,
}, },
}; };
@ -22,7 +22,7 @@ pub trait Shape {
fn draw(&self, painter: &mut Painter<'_, '_>); fn draw(&self, painter: &mut Painter<'_, '_>);
} }
impl Shape for Line { impl Shape for CanvasLine {
fn draw(&self, painter: &mut Painter<'_, '_>) { fn draw(&self, painter: &mut Painter<'_, '_>) {
let (x1, y1) = match painter.get_point(self.x1, self.y1) { let (x1, y1) = match painter.get_point(self.x1, self.y1) {
Some(c) => c, Some(c) => c,
@ -122,7 +122,7 @@ impl Shape for Points<'_> {
pub struct Label<'a> { pub struct Label<'a> {
x: f64, x: f64,
y: f64, y: f64,
spans: Spans<'a>, spans: Line<'a>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -365,6 +365,7 @@ impl<'a> Context<'a> {
symbols::Marker::Dot => Box::new(CharGrid::new(width, height, '•')), symbols::Marker::Dot => Box::new(CharGrid::new(width, height, '•')),
symbols::Marker::Block => Box::new(CharGrid::new(width, height, '▄')), symbols::Marker::Block => Box::new(CharGrid::new(width, height, '▄')),
symbols::Marker::Braille => Box::new(BrailleGrid::new(width, height)), symbols::Marker::Braille => Box::new(BrailleGrid::new(width, height)),
symbols::Marker::Bar => Box::new(CharGrid::new(width, height, '▄')),
}; };
Context { Context {
x_bounds, x_bounds,
@ -542,7 +543,7 @@ where
{ {
let x = ((label.x - left) * resolution.0 / width) as u16 + canvas_area.left(); let x = ((label.x - left) * resolution.0 / width) as u16 + canvas_area.left();
let y = ((top - label.y) * resolution.1 / height) as u16 + canvas_area.top(); let y = ((top - label.y) * resolution.1 / height) as u16 + canvas_area.top();
buf.set_spans(x, y, &label.spans, canvas_area.right() - x); buf.set_line(x, y, &label.spans, canvas_area.right() - x);
} }
} }
} }

View File

@ -1,6 +1,6 @@
use std::cmp::Ordering; use std::cmp::Ordering;
use tui::text::{Span, Spans, Text}; use tui::text::{Line, Span, Text};
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use unicode_width::UnicodeWidthStr; use unicode_width::UnicodeWidthStr;
@ -99,7 +99,7 @@ pub fn get_decimal_prefix(quantity: u64, unit: &str) -> (f64, String) {
/// Truncates text if it is too long, and adds an ellipsis at the end if needed. /// Truncates text if it is too long, and adds an ellipsis at the end if needed.
pub fn truncate_to_text<'a, U: Into<usize>>(content: &str, width: U) -> Text<'a> { pub fn truncate_to_text<'a, U: Into<usize>>(content: &str, width: U) -> Text<'a> {
Text { Text {
lines: vec![Spans(vec![Span::raw(truncate_str(content, width))])], lines: vec![Line::from(vec![Span::raw(truncate_str(content, width))])],
} }
} }