diff --git a/Cargo.lock b/Cargo.lock index 025d4d75..076e1e6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1445,9 +1445,9 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829" +checksum = "ce841e0486e7c2412c3740168ede33adeba8e154a15107b879d8162d77c7174e" dependencies = [ "bitflags", "cassowary", diff --git a/Cargo.toml b/Cargo.toml index ce69c1f1..8b2287f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ log = "0.4" notify = "5.1" notify-debouncer-mini = "0.2" once_cell = "1" -ratatui = { version = "0.20", default-features = false, features = ['crossterm', 'serde'] } +ratatui = { version = "0.21", default-features = false, features = ['crossterm', 'serde'] } rayon-core = "1.11" ron = "0.8" scopeguard = "1.1" diff --git a/src/app.rs b/src/app.rs index 26ce4647..a30b4775 100644 --- a/src/app.rs +++ b/src/app.rs @@ -39,7 +39,7 @@ use ratatui::{ layout::{ Alignment, Constraint, Direction, Layout, Margin, Rect, }, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Paragraph, Tabs}, Frame, }; @@ -1189,7 +1189,7 @@ impl App { let table_area = r; // use entire area to allow drawing the horizontal separator line let text_area = left_right[1]; - let tabs = tab_labels.into_iter().map(Spans::from).collect(); + let tabs = tab_labels.into_iter().map(Line::from).collect(); f.render_widget( Tabs::new(tabs) @@ -1206,7 +1206,7 @@ impl App { ); f.render_widget( - Paragraph::new(Spans::from(vec![Span::styled( + Paragraph::new(Line::from(vec![Span::styled( ellipsis_trim_start( &self.repo_path_text, text_area.width as usize, diff --git a/src/cmdbar.rs b/src/cmdbar.rs index f3888a05..2479cc31 100644 --- a/src/cmdbar.rs +++ b/src/cmdbar.rs @@ -5,7 +5,7 @@ use crate::{ use ratatui::{ backend::Backend, layout::{Alignment, Rect}, - text::{Span, Spans}, + text::{Line, Span}, widgets::Paragraph, Frame, }; @@ -151,7 +151,7 @@ impl CommandBar { .draw_list .split(|c| matches!(c, DrawListEntry::LineBreak)) .map(|c_arr| { - Spans::from( + Line::from( c_arr .iter() .map(|c| match c { @@ -174,7 +174,7 @@ impl CommandBar { .collect::>(), ) }) - .collect::>(); + .collect::>(); f.render_widget( Paragraph::new(texts).alignment(Alignment::Left), @@ -190,7 +190,7 @@ impl CommandBar { ); f.render_widget( - Paragraph::new(Spans::from(vec![Span::raw( + Paragraph::new(Line::from(vec![Span::raw( Cow::from(if self.expanded { "less [.]" } else { diff --git a/src/components/branch_find_popup.rs b/src/components/branch_find_popup.rs index 71dd0a01..2dafdecd 100644 --- a/src/components/branch_find_popup.rs +++ b/src/components/branch_find_popup.rs @@ -15,7 +15,7 @@ use fuzzy_matcher::FuzzyMatcher; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Margin, Rect}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Clear}, Frame, }; @@ -233,7 +233,7 @@ impl DrawableComponent for BranchFindPopup { &self.branches[*idx], width, ); - Spans::from( + Line::from( full_text .char_indices() .map(|(c_idx, c)| { diff --git a/src/components/branchlist.rs b/src/components/branchlist.rs index 611abf13..027dc303 100644 --- a/src/components/branchlist.rs +++ b/src/components/branchlist.rs @@ -31,7 +31,7 @@ use ratatui::{ layout::{ Alignment, Constraint, Direction, Layout, Margin, Rect, }, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{Block, BorderType, Borders, Clear, Paragraph, Tabs}, Frame, }; @@ -661,7 +661,7 @@ impl BranchListComponent { theme.branch(selected, is_head), ); - txt.push(Spans::from(vec![ + txt.push(Line::from(vec![ span_prefix, span_name, span_hash, @@ -702,7 +702,7 @@ impl BranchListComponent { let tabs = [Span::raw("Local"), Span::raw("Remote")] .iter() .cloned() - .map(Spans::from) + .map(Line::from) .collect(); f.render_widget( diff --git a/src/components/commit_details/compare_details.rs b/src/components/commit_details/compare_details.rs index 6a3911ea..015e3ff3 100644 --- a/src/components/commit_details/compare_details.rs +++ b/src/components/commit_details/compare_details.rs @@ -17,7 +17,7 @@ use crossterm::event::Event; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, Frame, }; @@ -65,9 +65,9 @@ impl CompareDetailsComponent { } #[allow(unstable_name_collisions)] - fn get_commit_text(&self, data: &CommitDetails) -> Vec { + fn get_commit_text(&self, data: &CommitDetails) -> Vec { let mut res = vec![ - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Author), Span::styled( Cow::from(format!( @@ -77,7 +77,7 @@ impl CompareDetailsComponent { self.theme.text(true, false), ), ]), - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( @@ -89,7 +89,7 @@ impl CompareDetailsComponent { ]), ]; - res.push(Spans::from(vec![ + res.push(Line::from(vec![ style_detail(&self.theme, &Detail::Message), Span::styled( Cow::from( diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index 254f6e78..8ff2775e 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -19,7 +19,7 @@ use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, style::{Modifier, Style}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, Frame, }; use std::clone::Clone; @@ -133,7 +133,7 @@ impl DetailsComponent { &self, width: usize, height: usize, - ) -> Vec { + ) -> Vec { let (wrapped_title, wrapped_message) = Self::get_wrapped_lines(&self.data, width); @@ -144,7 +144,7 @@ impl DetailsComponent { .skip(self.scroll.get_top()) .take(height) .map(|(i, line)| { - Spans::from(vec![Span::styled( + Line::from(vec![Span::styled( line.clone(), self.get_theme_for_line(i < wrapped_title.len()), )]) @@ -153,10 +153,10 @@ impl DetailsComponent { } #[allow(unstable_name_collisions, clippy::too_many_lines)] - fn get_text_info(&self) -> Vec { + fn get_text_info(&self) -> Vec { self.data.as_ref().map_or_else(Vec::new, |data| { let mut res = vec![ - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Author), Span::styled( Cow::from(format!( @@ -166,7 +166,7 @@ impl DetailsComponent { self.theme.text(true, false), ), ]), - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( @@ -180,7 +180,7 @@ impl DetailsComponent { if let Some(ref committer) = data.committer { res.extend(vec![ - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Commiter), Span::styled( Cow::from(format!( @@ -190,7 +190,7 @@ impl DetailsComponent { self.theme.text(true, false), ), ]), - Spans::from(vec![ + Line::from(vec![ style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( @@ -203,7 +203,7 @@ impl DetailsComponent { ]); } - res.push(Spans::from(vec![ + res.push(Line::from(vec![ Span::styled( Cow::from(strings::commit::details_sha()), self.theme.text(false, false), @@ -215,12 +215,12 @@ impl DetailsComponent { ])); if !self.tags.is_empty() { - res.push(Spans::from(style_detail( + res.push(Line::from(style_detail( &self.theme, &Detail::Sha, ))); - res.push(Spans::from( + res.push(Line::from( itertools::Itertools::intersperse( self.tags.iter().map(|tag| { Span::styled( diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index f340b9bd..ba799eaf 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -22,7 +22,7 @@ use itertools::Itertools; use ratatui::{ backend::Backend, layout::{Alignment, Rect}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Paragraph}, Frame, }; @@ -306,7 +306,7 @@ impl CommitList { width: usize, now: DateTime, marked: Option, - ) -> Spans<'a> { + ) -> Line<'a> { let mut txt: Vec = Vec::with_capacity( ELEMENTS_PER_LINE + if marked.is_some() { 2 } else { 0 }, ); @@ -390,13 +390,13 @@ impl CommitList { theme.text(true, selected), )); - Spans::from(txt) + Line::from(txt) } - fn get_text(&self, height: usize, width: usize) -> Vec { + fn get_text(&self, height: usize, width: usize) -> Vec { let selection = self.relative_selection(); - let mut txt: Vec = Vec::with_capacity(height); + let mut txt: Vec = Vec::with_capacity(height); let now = Local::now(); diff --git a/src/components/diff.rs b/src/components/diff.rs index 76b174f3..c36b8d05 100644 --- a/src/components/diff.rs +++ b/src/components/diff.rs @@ -24,7 +24,7 @@ use ratatui::{ backend::Backend, layout::Rect, symbols, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Paragraph}, Frame, }; @@ -330,15 +330,15 @@ impl DiffComponent { None } - fn get_text(&self, width: u16, height: u16) -> Vec { - let mut res: Vec = Vec::new(); + fn get_text(&self, width: u16, height: u16) -> Vec { + let mut res: Vec = Vec::new(); if let Some(diff) = &self.diff { if diff.hunks.is_empty() { let is_positive = diff.size_delta >= 0; let delta_byte_size = ByteSize::b(diff.size_delta.unsigned_abs()); let sign = if is_positive { "+" } else { "-" }; - res.extend(vec![Spans::from(vec![ + res.extend(vec![Line::from(vec![ Span::raw(Cow::from("size: ")), Span::styled( Cow::from(format!( @@ -435,7 +435,7 @@ impl DiffComponent { end_of_hunk: bool, theme: &SharedTheme, scrolled_right: usize, - ) -> Spans<'a> { + ) -> Line<'a> { let style = theme.diff_hunk_marker(selected_hunk); let left_side_of_line = if end_of_hunk { @@ -465,7 +465,7 @@ impl DiffComponent { format!("{content}\n") }; - Spans::from(vec![ + Line::from(vec![ left_side_of_line, Span::styled( Cow::from(filled), @@ -666,7 +666,7 @@ impl DrawableComponent for DiffComponent { ); let txt = if self.pending { - vec![Spans::from(vec![Span::styled( + vec![Line::from(vec![Span::styled( Cow::from(strings::loading_text(&self.key_config)), self.theme.text(false, false), )])] diff --git a/src/components/externaleditor.rs b/src/components/externaleditor.rs index fd9bd8b6..61d41e85 100644 --- a/src/components/externaleditor.rs +++ b/src/components/externaleditor.rs @@ -19,7 +19,7 @@ use crossterm::{ use ratatui::{ backend::Backend, layout::Rect, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, BorderType, Borders, Clear, Paragraph}, Frame, }; @@ -129,7 +129,7 @@ impl DrawableComponent for ExternalEditorComponent { _rect: Rect, ) -> Result<()> { if self.visible { - let txt = Spans::from( + let txt = Line::from( strings::msg_opening_editor(&self.key_config) .split('\n') .map(|string| { diff --git a/src/components/file_find_popup.rs b/src/components/file_find_popup.rs index 43982839..8ec9e578 100644 --- a/src/components/file_find_popup.rs +++ b/src/components/file_find_popup.rs @@ -16,7 +16,7 @@ use fuzzy_matcher::FuzzyMatcher; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Margin, Rect}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Clear}, Frame, }; @@ -243,7 +243,7 @@ impl DrawableComponent for FileFindPopup { .unwrap_or_default(), width, ); - Spans::from( + Line::from( full_text .char_indices() .map(|(c_idx, c)| { diff --git a/src/components/file_revlog.rs b/src/components/file_revlog.rs index 3f0f0cae..7d6dbc2b 100644 --- a/src/components/file_revlog.rs +++ b/src/components/file_revlog.rs @@ -27,7 +27,7 @@ use crossterm::event::Event; use ratatui::{ backend::Backend, layout::{Constraint, Direction, Layout, Rect}, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{Block, Borders, Cell, Clear, Row, Table, TableState}, Frame, }; @@ -314,7 +314,7 @@ impl FileRevlogComponent { self.items .iter() .map(|entry| { - let spans = Spans::from(vec![ + let spans = Line::from(vec![ Span::styled( entry.hash_short.to_string(), self.theme.commit_hash(false), diff --git a/src/components/help.rs b/src/components/help.rs index e6a1c8eb..6fd6eee6 100644 --- a/src/components/help.rs +++ b/src/components/help.rs @@ -15,7 +15,7 @@ use ratatui::{ backend::Backend, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::{Modifier, Style}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, BorderType, Borders, Clear, Paragraph}, Frame, }; @@ -73,7 +73,7 @@ impl DrawableComponent for HelpComponent { ); f.render_widget( - Paragraph::new(Spans::from(vec![Span::styled( + Paragraph::new(Line::from(vec![Span::styled( Cow::from(format!("gitui {}", Version::new(),)), Style::default(), )])) @@ -207,15 +207,15 @@ impl HelpComponent { } } - fn get_text(&self) -> Vec { - let mut txt: Vec = Vec::new(); + fn get_text(&self) -> Vec { + let mut txt: Vec = Vec::new(); let mut processed = 0_u16; for (key, group) in &self.cmds.iter().group_by(|e| e.text.group) { - txt.push(Spans::from(Span::styled( + txt.push(Line::from(Span::styled( Cow::from(key.to_string()), Style::default().add_modifier(Modifier::REVERSED), ))); @@ -225,7 +225,7 @@ impl HelpComponent { processed += 1; - txt.push(Spans::from(Span::styled( + txt.push(Line::from(Span::styled( Cow::from(if is_selected { format!(">{}", command_info.text.name) } else { @@ -235,7 +235,7 @@ impl HelpComponent { ))); if is_selected { - txt.push(Spans::from(Span::styled( + txt.push(Line::from(Span::styled( Cow::from(format!( " {}\n", command_info.text.desc diff --git a/src/components/options_popup.rs b/src/components/options_popup.rs index 96968b60..73b4e5c2 100644 --- a/src/components/options_popup.rs +++ b/src/components/options_popup.rs @@ -17,7 +17,7 @@ use ratatui::{ backend::Backend, layout::{Alignment, Rect}, style::{Modifier, Style}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Clear, Paragraph}, Frame, }; @@ -57,15 +57,15 @@ impl OptionsPopupComponent { } } - fn get_text(&self, width: u16) -> Vec { - let mut txt: Vec = Vec::with_capacity(10); + fn get_text(&self, width: u16) -> Vec { + let mut txt: Vec = Vec::with_capacity(10); self.add_status(&mut txt, width); txt } - fn add_status(&self, txt: &mut Vec, width: u16) { + fn add_status(&self, txt: &mut Vec, width: u16) { Self::add_header(txt, "Status"); self.add_entry( @@ -111,8 +111,8 @@ impl OptionsPopupComponent { self.selection == kind } - fn add_header(txt: &mut Vec, header: &'static str) { - txt.push(Spans::from(vec![Span::styled( + fn add_header(txt: &mut Vec, header: &'static str) { + txt.push(Line::from(vec![Span::styled( header, //TODO: use style Style::default().add_modifier(Modifier::UNDERLINED), @@ -121,14 +121,14 @@ impl OptionsPopupComponent { fn add_entry( &self, - txt: &mut Vec, + txt: &mut Vec, width: u16, entry: &'static str, value: &str, selected: bool, ) { let half = usize::from(width / 2); - txt.push(Spans::from(vec![ + txt.push(Line::from(vec![ Span::styled( string_width_align(entry, half), self.theme.text(true, false), diff --git a/src/components/reset_popup.rs b/src/components/reset_popup.rs index f316c45a..a3b48428 100644 --- a/src/components/reset_popup.rs +++ b/src/components/reset_popup.rs @@ -17,7 +17,7 @@ use crossterm::event::Event; use ratatui::{ backend::Backend, layout::{Alignment, Rect}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Clear, Paragraph}, Frame, }; @@ -70,10 +70,10 @@ impl ResetPopupComponent { } } - fn get_text(&self, _width: u16) -> Vec { - let mut txt: Vec = Vec::with_capacity(10); + fn get_text(&self, _width: u16) -> Vec { + let mut txt: Vec = Vec::with_capacity(10); - txt.push(Spans::from(vec![ + txt.push(Line::from(vec![ Span::styled( String::from("Branch: "), self.theme.text(true, false), @@ -84,7 +84,7 @@ impl ResetPopupComponent { ), ])); - txt.push(Spans::from(vec![ + txt.push(Line::from(vec![ Span::styled( String::from("Reset to: "), self.theme.text(true, false), @@ -99,7 +99,7 @@ impl ResetPopupComponent { let (kind_name, kind_desc) = type_to_string(self.kind); - txt.push(Spans::from(vec![ + txt.push(Line::from(vec![ Span::styled( String::from("How: "), self.theme.text(true, false), diff --git a/src/components/submodules.rs b/src/components/submodules.rs index 3ec36268..e8cdac85 100644 --- a/src/components/submodules.rs +++ b/src/components/submodules.rs @@ -21,7 +21,7 @@ use ratatui::{ layout::{ Alignment, Constraint, Direction, Layout, Margin, Rect, }, - text::{Span, Spans, Text}, + text::{Line, Span, Text}, widgets::{Block, Borders, Clear, Paragraph}, Frame, }; @@ -399,7 +399,7 @@ impl SubmodulesListComponent { theme.text(true, selected), ); - txt.push(Spans::from(vec![span_name, span_hash])); + txt.push(Line::from(vec![span_name, span_hash])); } Text::from(txt) @@ -438,17 +438,17 @@ impl SubmodulesListComponent { ); Text::from(vec![ - Spans::from(vec![span_title_path]), - Spans::from(vec![span_path]), - Spans::from(vec![]), - Spans::from(vec![span_title_commit]), - Spans::from(vec![span_commit]), - Spans::from(vec![]), - Spans::from(vec![span_title_url]), - Spans::from(vec![span_url]), - Spans::from(vec![]), - Spans::from(vec![span_title_status]), - Spans::from(vec![span_status]), + Line::from(vec![span_title_path]), + Line::from(vec![span_path]), + Line::from(vec![]), + Line::from(vec![span_title_commit]), + Line::from(vec![span_commit]), + Line::from(vec![]), + Line::from(vec![span_title_url]), + Line::from(vec![span_url]), + Line::from(vec![]), + Line::from(vec![span_title_status]), + Line::from(vec![span_status]), ]) }, ) @@ -456,22 +456,22 @@ impl SubmodulesListComponent { fn get_local_info_text(&self, theme: &SharedTheme) -> Text { let mut spans = vec![ - Spans::from(vec![Span::styled( + Line::from(vec![Span::styled( "Current:", theme.text(false, false), )]), - Spans::from(vec![Span::styled( + Line::from(vec![Span::styled( self.repo_path.to_string(), theme.text(true, false), )]), - Spans::from(vec![Span::styled( + Line::from(vec![Span::styled( "Parent:", theme.text(false, false), )]), ]; if let Some(parent_info) = &self.submodule_parent { - spans.push(Spans::from(vec![Span::styled( + spans.push(Line::from(vec![Span::styled( parent_info.parent_gitpath.to_string_lossy(), theme.text(true, false), )])); diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 34547161..1f527b60 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -17,7 +17,7 @@ use ratatui::{ backend::Backend, layout::{Alignment, Rect}, style::Modifier, - text::{Spans, Text}, + text::{Line, Text}, widgets::{Clear, Paragraph}, Frame, }; @@ -237,7 +237,7 @@ impl TextInputComponent { Text::styled(text_before_cursor, style), ); if ends_in_nl { - txt.lines.push(Spans::default()); + txt.lines.push(Line::default()); } } @@ -330,7 +330,7 @@ fn text_append<'a>(txt: Text<'a>, append: Text<'a>) -> Text<'a> { let mut txt = txt; if let Some(last_line) = txt.lines.last_mut() { if let Some(first_line) = append.lines.first() { - last_line.0.extend(first_line.0.clone()); + last_line.spans.extend(first_line.spans.clone()); } if append.lines.len() > 1 { @@ -564,9 +564,12 @@ mod tests { let txt = comp.get_draw_text(); - assert_eq!(txt.lines[0].0.len(), 1); - assert_eq!(get_text(&txt.lines[0].0[0]), Some("a")); - assert_eq!(get_style(&txt.lines[0].0[0]), Some(&underlined)); + assert_eq!(txt.lines[0].spans.len(), 1); + assert_eq!(get_text(&txt.lines[0].spans[0]), Some("a")); + assert_eq!( + get_style(&txt.lines[0].spans[0]), + Some(&underlined) + ); } #[test] @@ -590,18 +593,18 @@ mod tests { let txt = comp.get_draw_text(); - assert_eq!(txt.lines[0].0.len(), 2); - assert_eq!(get_text(&txt.lines[0].0[0]), Some("a")); + assert_eq!(txt.lines[0].spans.len(), 2); + assert_eq!(get_text(&txt.lines[0].spans[0]), Some("a")); assert_eq!( - get_style(&txt.lines[0].0[0]), + get_style(&txt.lines[0].spans[0]), Some(¬_underlined) ); assert_eq!( - get_text(&txt.lines[0].0[1]), + get_text(&txt.lines[0].spans[1]), Some(symbol::WHITESPACE) ); assert_eq!( - get_style(&txt.lines[0].0[1]), + get_style(&txt.lines[0].spans[1]), Some(&underlined_whitespace) ); } @@ -627,13 +630,19 @@ mod tests { let txt = comp.get_draw_text(); assert_eq!(txt.lines.len(), 2); - assert_eq!(txt.lines[0].0.len(), 2); - assert_eq!(txt.lines[1].0.len(), 2); - assert_eq!(get_text(&txt.lines[0].0[0]), Some("a")); - assert_eq!(get_text(&txt.lines[0].0[1]), Some("\u{21b5}")); - assert_eq!(get_style(&txt.lines[0].0[1]), Some(&underlined)); - assert_eq!(get_text(&txt.lines[1].0[0]), Some("")); - assert_eq!(get_text(&txt.lines[1].0[1]), Some("b")); + assert_eq!(txt.lines[0].spans.len(), 2); + assert_eq!(txt.lines[1].spans.len(), 2); + assert_eq!(get_text(&txt.lines[0].spans[0]), Some("a")); + assert_eq!( + get_text(&txt.lines[0].spans[1]), + Some("\u{21b5}") + ); + assert_eq!( + get_style(&txt.lines[0].spans[1]), + Some(&underlined) + ); + assert_eq!(get_text(&txt.lines[1].spans[0]), Some("")); + assert_eq!(get_text(&txt.lines[1].spans[1]), Some("b")); } #[test] @@ -656,12 +665,15 @@ mod tests { let txt = comp.get_draw_text(); assert_eq!(txt.lines.len(), 2); - assert_eq!(txt.lines[0].0.len(), 2); - assert_eq!(txt.lines[1].0.len(), 1); - assert_eq!(get_text(&txt.lines[0].0[0]), Some("a")); - assert_eq!(get_text(&txt.lines[0].0[1]), Some("")); - assert_eq!(get_style(&txt.lines[0].0[0]), Some(&underlined)); - assert_eq!(get_text(&txt.lines[1].0[0]), Some("b")); + assert_eq!(txt.lines[0].spans.len(), 2); + assert_eq!(txt.lines[1].spans.len(), 1); + assert_eq!(get_text(&txt.lines[0].spans[0]), Some("a")); + assert_eq!(get_text(&txt.lines[0].spans[1]), Some("")); + assert_eq!( + get_style(&txt.lines[0].spans[0]), + Some(&underlined) + ); + assert_eq!(get_text(&txt.lines[1].spans[0]), Some("b")); } #[test] diff --git a/src/tabs/stashing.rs b/src/tabs/stashing.rs index 9991e211..93734ae3 100644 --- a/src/tabs/stashing.rs +++ b/src/tabs/stashing.rs @@ -19,7 +19,7 @@ use crossbeam_channel::Sender; use crossterm::event::Event; use ratatui::{ layout::{Alignment, Constraint, Direction, Layout}, - text::{Span, Spans}, + text::{Line, Span}, widgets::{Block, Borders, Paragraph}, }; use std::borrow::Cow; @@ -105,7 +105,7 @@ impl Stashing { Ok(()) } - fn get_option_text(&self) -> Vec { + fn get_option_text(&self) -> Vec { let bracket_open = Span::raw(Cow::from("[")); let bracket_close = Span::raw(Cow::from("]")); let option_on = @@ -115,7 +115,7 @@ impl Stashing { Span::styled(Cow::from("_"), self.theme.option(false)); vec![ - Spans::from(vec![ + Line::from(vec![ bracket_open.clone(), if self.options.stash_untracked { option_on.clone() @@ -125,7 +125,7 @@ impl Stashing { bracket_close.clone(), Span::raw(Cow::from(" stash untracked")), ]), - Spans::from(vec![ + Line::from(vec![ bracket_open, if self.options.keep_index { option_on diff --git a/src/ui/stateful_paragraph.rs b/src/ui/stateful_paragraph.rs index ea4f0180..4e31cb07 100644 --- a/src/ui/stateful_paragraph.rs +++ b/src/ui/stateful_paragraph.rs @@ -132,9 +132,8 @@ impl<'a> StatefulWidget for StatefulParagraph<'a> { } let style = self.style; - let mut styled = self.text.lines.iter().flat_map(|spans| { - spans - .0 + let mut styled = self.text.lines.iter().flat_map(|line| { + line.spans .iter() .flat_map(|span| span.styled_graphemes(style)) // Required given the way composers work but might be refactored out if we change diff --git a/src/ui/syntax_text.rs b/src/ui/syntax_text.rs index 7a90be1c..776196ed 100644 --- a/src/ui/syntax_text.rs +++ b/src/ui/syntax_text.rs @@ -3,7 +3,7 @@ use asyncgit::{ ProgressPercent, }; use once_cell::sync::Lazy; -use ratatui::text::{Span, Spans}; +use ratatui::text::{Line, Span}; use scopetime::scope_time; use std::{ ffi::OsStr, @@ -164,21 +164,21 @@ impl SyntaxText { impl<'a> From<&'a SyntaxText> for ratatui::text::Text<'a> { fn from(v: &'a SyntaxText) -> Self { - let mut result_lines: Vec = + let mut result_lines: Vec = Vec::with_capacity(v.lines.len()); for (syntax_line, line_content) in v.lines.iter().zip(v.text.lines()) { - let mut line_span = - Spans(Vec::with_capacity(syntax_line.items.len())); + let mut line_span: Line = + Vec::with_capacity(syntax_line.items.len()).into(); for (style, _, range) in &syntax_line.items { let item_content = &line_content[range.clone()]; let item_style = syntact_style_to_tui(style); line_span - .0 + .spans .push(Span::styled(item_content, item_style)); }