From 88f318f073601d781c3b36fbb7d3771fabc1cf6c Mon Sep 17 00:00:00 2001 From: extrawurst Date: Tue, 17 Sep 2024 12:12:43 +0200 Subject: [PATCH] update crossterm and ratatui --- Cargo.lock | 74 +++++++++++++++++++++++------------- Cargo.toml | 6 +-- deny.toml | 2 +- src/app.rs | 2 +- src/components/mod.rs | 2 +- src/components/textinput.rs | 8 ++-- src/main.rs | 2 +- src/popups/branchlist.rs | 4 +- src/popups/confirm.rs | 2 +- src/popups/externaleditor.rs | 2 +- src/popups/fetch.rs | 2 +- src/popups/help.rs | 2 +- src/popups/msg.rs | 6 +-- src/popups/pull.rs | 2 +- src/popups/push.rs | 2 +- src/popups/push_tags.rs | 2 +- src/popups/taglist.rs | 4 +- src/ui/stateful_paragraph.rs | 34 +++++++---------- 18 files changed, 85 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c77a5bcf17..9a0ea3499c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -480,13 +480,14 @@ checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "compact_str" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" dependencies = [ "castaway", "cfg-if", "itoa", + "rustversion", "ryu", "serde", "static_assertions", @@ -558,15 +559,15 @@ checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crossterm" -version = "0.27.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ "bitflags 2.6.0", "crossterm_winapi", - "libc", - "mio", + "mio 1.0.2", "parking_lot", + "rustix", "serde", "signal-hook", "signal-hook-mio", @@ -1662,6 +1663,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "hmac" version = "0.12.1" @@ -1759,6 +1766,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "instability" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b23a0c8dfe501baac4adf6ebbfa6eddf8f0c07f56b058cc1288017e32397846c" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "invalidstring" version = "0.1.3" @@ -1995,6 +2012,19 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "log", + "wasi", + "windows-sys 0.52.0", +] + [[package]] name = "notify" version = "6.1.1" @@ -2009,7 +2039,7 @@ dependencies = [ "kqueue", "libc", "log", - "mio", + "mio 0.8.11", "walkdir", "windows-sys 0.48.0", ] @@ -2089,9 +2119,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ea5043e58958ee56f3e15a90aee535795cd7dfd319846288d93c5b57d85cbe" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "onig" @@ -2412,19 +2442,19 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.27.0" +version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16546c5b5962abf8ce6e2881e722b4e0ae3b6f1a08a26ae3573c55853ca68d3" +checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d" dependencies = [ "bitflags 2.6.0", "cassowary", "compact_str", "crossterm", + "instability", "itertools", "lru", "paste", "serde", - "stability", "strum", "strum_macros", "unicode-segmentation", @@ -2762,12 +2792,12 @@ dependencies = [ [[package]] name = "signal-hook-mio" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" dependencies = [ "libc", - "mio", + "mio 1.0.2", "signal-hook", ] @@ -2888,16 +2918,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "stability" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d904e7009df136af5297832a3ace3370cd14ff1546a232f4f185036c2736fcac" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -3091,9 +3111,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tui-textarea" -version = "0.5.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00524c1366ee838839dd327d1f339ff51846ad4ea85bfa1332859e79adec612c" +checksum = "29c07084342a575cea919eea996b9658a358c800b03d435df581c1d7c60e065a" dependencies = [ "crossterm", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index 8060abf1de..c58efaba0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ bytesize = { version = "1.3", default-features = false } chrono = { version = "0.4", default-features = false, features = ["clock"] } clap = { version = "4.5", features = ["env", "cargo"] } crossbeam-channel = "0.5" -crossterm = { version = "0.27", features = ["serde"] } +crossterm = { version = "0.28", features = ["serde"] } dirs = "5.0" easy-cast = "0.5" filetreelist = { path = "./filetreelist", version = "0.5" } @@ -39,7 +39,7 @@ notify-debouncer-mini = "0.4" once_cell = "1" # pin until upgrading this does not introduce a duplicte dependency parking_lot_core = "=0.9.9" -ratatui = { version = "0.27", default-features = false, features = [ +ratatui = { version = "0.28", default-features = false, features = [ 'crossterm', 'serde', ] } @@ -57,7 +57,7 @@ syntect = { version = "5.2", default-features = false, features = [ "default-themes", "html", ] } -tui-textarea = "0.5" +tui-textarea = "0.6" two-face = { version = "0.4.0", default-features = false } unicode-segmentation = "1.11" unicode-truncate = "1.0" diff --git a/deny.toml b/deny.toml index 4e4d4543ce..61616cc18a 100644 --- a/deny.toml +++ b/deny.toml @@ -22,4 +22,4 @@ version = "1.0.3" [bans] multiple-versions = "deny" -skip-tree = [{ name = "windows-sys" }, { name = "bitflags" }] +skip-tree = [{ name = "windows-sys" }, { name = "bitflags" }, { name = "mio" }] diff --git a/src/app.rs b/src/app.rs index a7f7996235..cd7f1aca62 100644 --- a/src/app.rs +++ b/src/app.rs @@ -227,7 +227,7 @@ impl App { /// pub fn draw(&self, f: &mut Frame) -> Result<()> { - let fsize = f.size(); + let fsize = f.area(); self.cmdbar.borrow_mut().refresh_width(fsize.width); diff --git a/src/components/mod.rs b/src/components/mod.rs index 4f1f3f4006..f20d3f981a 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -82,7 +82,7 @@ macro_rules! draw_popups { ] .as_ref(), ) - .split(f.size())[0]; + .split(f.area())[0]; ($($self.$element.draw(&mut f, size)?) , +); diff --git a/src/components/textinput.rs b/src/components/textinput.rs index 914f52fdc8..8c9224ac0c 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -623,18 +623,18 @@ impl DrawableComponent for TextInputComponent { let area = if self.embed { rect } else if self.input_type == InputType::Multiline { - let area = ui::centered_rect(60, 20, f.size()); + let area = ui::centered_rect(60, 20, f.area()); ui::rect_inside( Size::new(10, 3), - f.size().into(), + f.area().into(), area, ) } else { - let area = ui::centered_rect(60, 1, f.size()); + let area = ui::centered_rect(60, 1, f.area()); ui::rect_inside( Size::new(10, 3), - Size::new(f.size().width, 3), + Size::new(f.area().width, 3), area, ) }; diff --git a/src/main.rs b/src/main.rs index a5dc103939..e85dca8530 100644 --- a/src/main.rs +++ b/src/main.rs @@ -302,7 +302,7 @@ fn shutdown_terminal() { fn draw(terminal: &mut Terminal, app: &App) -> io::Result<()> { if app.requires_redraw() { - terminal.resize(terminal.size()?)?; + terminal.clear()?; } terminal.draw(|f| { diff --git a/src/popups/branchlist.rs b/src/popups/branchlist.rs index 0421e5f094..ba53239664 100644 --- a/src/popups/branchlist.rs +++ b/src/popups/branchlist.rs @@ -64,10 +64,10 @@ impl DrawableComponent for BranchListPopup { let area = ui::centered_rect( PERCENT_SIZE.width, PERCENT_SIZE.height, - f.size(), + f.area(), ); let area = - ui::rect_inside(MIN_SIZE, f.size().into(), area); + ui::rect_inside(MIN_SIZE, f.area().into(), area); let area = area.intersection(rect); f.render_widget(Clear, area); diff --git a/src/popups/confirm.rs b/src/popups/confirm.rs index a588f425d9..cb6f731268 100644 --- a/src/popups/confirm.rs +++ b/src/popups/confirm.rs @@ -35,7 +35,7 @@ impl DrawableComponent for ConfirmPopup { self.theme.text_danger(), ); - let area = ui::centered_rect(50, 20, f.size()); + let area = ui::centered_rect(50, 20, f.area()); f.render_widget(Clear, area); f.render_widget( popup_paragraph(&title, txt, &self.theme, true, true), diff --git a/src/popups/externaleditor.rs b/src/popups/externaleditor.rs index dc0d5aef68..4f9856e572 100644 --- a/src/popups/externaleditor.rs +++ b/src/popups/externaleditor.rs @@ -131,7 +131,7 @@ impl DrawableComponent for ExternalEditorPopup { .collect::>(), ); - let area = ui::centered_rect_absolute(25, 3, f.size()); + let area = ui::centered_rect_absolute(25, 3, f.area()); f.render_widget(Clear, area); f.render_widget( Paragraph::new(txt) diff --git a/src/popups/fetch.rs b/src/popups/fetch.rs index daf015f20c..94d8865d84 100644 --- a/src/popups/fetch.rs +++ b/src/popups/fetch.rs @@ -119,7 +119,7 @@ impl DrawableComponent for FetchPopup { if self.visible { let progress = self.progress.unwrap_or_default().progress; - let area = ui::centered_rect_absolute(30, 3, f.size()); + let area = ui::centered_rect_absolute(30, 3, f.area()); f.render_widget(Clear, area); f.render_widget( diff --git a/src/popups/help.rs b/src/popups/help.rs index 8d93a5ac5a..ebf687ad5e 100644 --- a/src/popups/help.rs +++ b/src/popups/help.rs @@ -39,7 +39,7 @@ impl DrawableComponent for HelpPopup { self.selection.saturating_sub(scroll_threshold); let area = - ui::centered_rect_absolute(SIZE.0, SIZE.1, f.size()); + ui::centered_rect_absolute(SIZE.0, SIZE.1, f.area()); f.render_widget(Clear, area); f.render_widget( diff --git a/src/popups/msg.rs b/src/popups/msg.rs index 759c3b2679..f3cacf023c 100644 --- a/src/popups/msg.rs +++ b/src/popups/msg.rs @@ -38,7 +38,7 @@ impl DrawableComponent for MsgPopup { return Ok(()); } - let max_width = f.size().width.max(MINIMUM_WIDTH); + let max_width = f.area().width.max(MINIMUM_WIDTH); // determine the maximum width of text block let width = self @@ -53,7 +53,7 @@ impl DrawableComponent for MsgPopup { .expect("can't fail because we're clamping to u16 value"); let area = - ui::centered_rect_absolute(width, POPUP_HEIGHT, f.size()); + ui::centered_rect_absolute(width, POPUP_HEIGHT, f.area()); // Wrap lines and break words if there is not enough space let wrapped_msg = bwrap::wrap_maybrk!( @@ -67,7 +67,7 @@ impl DrawableComponent for MsgPopup { let height = POPUP_HEIGHT .saturating_sub(BORDER_WIDTH) - .min(f.size().height.saturating_sub(BORDER_WIDTH)); + .min(f.area().height.saturating_sub(BORDER_WIDTH)); let top = self.scroll.update_no_selection(line_num, height.into()); diff --git a/src/popups/pull.rs b/src/popups/pull.rs index 44549fd270..1b25869b92 100644 --- a/src/popups/pull.rs +++ b/src/popups/pull.rs @@ -205,7 +205,7 @@ impl DrawableComponent for PullPopup { let (state, progress) = PushPopup::get_progress(&self.progress); - let area = ui::centered_rect_absolute(30, 3, f.size()); + let area = ui::centered_rect_absolute(30, 3, f.area()); f.render_widget(Clear, area); f.render_widget( diff --git a/src/popups/push.rs b/src/popups/push.rs index 82787cce30..08152cefea 100644 --- a/src/popups/push.rs +++ b/src/popups/push.rs @@ -234,7 +234,7 @@ impl DrawableComponent for PushPopup { let (state, progress) = Self::get_progress(&self.progress); - let area = ui::centered_rect_absolute(30, 3, f.size()); + let area = ui::centered_rect_absolute(30, 3, f.area()); f.render_widget(Clear, area); f.render_widget( diff --git a/src/popups/push_tags.rs b/src/popups/push_tags.rs index e6e09048e2..4532d3a411 100644 --- a/src/popups/push_tags.rs +++ b/src/popups/push_tags.rs @@ -162,7 +162,7 @@ impl DrawableComponent for PushTagsPopup { let (state, progress) = Self::get_progress(&self.progress); - let area = ui::centered_rect_absolute(30, 3, f.size()); + let area = ui::centered_rect_absolute(30, 3, f.area()); f.render_widget(Clear, area); f.render_widget( diff --git a/src/popups/taglist.rs b/src/popups/taglist.rs index c9e840f7eb..76fefb2d3d 100644 --- a/src/popups/taglist.rs +++ b/src/popups/taglist.rs @@ -62,10 +62,10 @@ impl DrawableComponent for TagListPopup { let area = ui::centered_rect( PERCENT_SIZE.width, PERCENT_SIZE.height, - f.size(), + f.area(), ); let area = - ui::rect_inside(MIN_SIZE, f.size().into(), area); + ui::rect_inside(MIN_SIZE, f.area().into(), area); let area = area.intersection(rect); let tag_name_width = diff --git a/src/ui/stateful_paragraph.rs b/src/ui/stateful_paragraph.rs index 368c07b8f8..3b2253ef5e 100644 --- a/src/ui/stateful_paragraph.rs +++ b/src/ui/stateful_paragraph.rs @@ -1,7 +1,7 @@ use easy_cast::Cast; use ratatui::{ buffer::Buffer, - layout::{Alignment, Rect}, + layout::{Alignment, Position, Rect}, style::Style, text::{StyledGrapheme, Text}, widgets::{Block, StatefulWidget, Widget, Wrap}, @@ -98,16 +98,6 @@ impl<'a> StatefulParagraph<'a> { self.wrap = Some(wrap); self } - - // pub const fn style(mut self, style: Style) -> Self { - // self.style = style; - // self - // } - - // pub const fn alignment(mut self, alignment: Alignment) -> Self { - // self.alignment = alignment; - // self - // } } impl<'a> StatefulWidget for StatefulParagraph<'a> { @@ -173,18 +163,20 @@ impl<'a> StatefulWidget for StatefulParagraph<'a> { self.alignment, ); for StyledGrapheme { symbol, style } in current_line { - buf.get_mut( + buf.cell_mut(Position::new( text_area.left() + x, text_area.top() + y - state.scroll.y, - ) - .set_symbol(if symbol.is_empty() { - // If the symbol is empty, the last char which rendered last time will - // leave on the line. It's a quick fix. - " " - } else { - symbol - }) - .set_style(*style); + )) + .map(|cell| { + cell.set_symbol(if symbol.is_empty() { + // If the symbol is empty, the last char which rendered last time will + // leave on the line. It's a quick fix. + " " + } else { + symbol + }) + .set_style(*style) + }); x += Cast::::cast(symbol.width()); } }