From 5fe858d771d286204d2ed911533869223ea20d2c Mon Sep 17 00:00:00 2001 From: Cyandev Date: Sun, 10 Mar 2024 13:14:31 +0800 Subject: Add scrollbar for mark list --- src/interactive/widgets/mark.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index a774c73..d50bd0e 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -17,7 +17,10 @@ use tui::{ layout::{Constraint, Direction, Layout, Rect}, style::{Color, Modifier, Style}, text::{Line, Span, Text}, - widgets::{Block, Borders, Paragraph, Widget}, + widgets::{ + Block, Borders, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, + Widget, + }, }; use tui_react::{ draw_text_nowrap_fn, @@ -411,12 +414,33 @@ impl MarkPane { inner_area }; + let line_count = marked.len(); let props = ListProps { block: None, entry_in_view, }; self.list.render(props, entries, list_area, buf); + let scrollbar = Scrollbar::default() + .orientation(ScrollbarOrientation::VerticalRight) + .begin_symbol(None) + .end_symbol(None); + let mut scrollbar_state = + ScrollbarState::new(line_count).position(selected.unwrap_or(self.list.offset)); + + scrollbar.render( + { + let mut scrollbar_area = list_area; + // The list has no blocks, so we need to increase + // the render area for scrollbar to make sure it + // will be drawn on the border. + scrollbar_area.width += 1; + scrollbar_area + }, + buf, + &mut scrollbar_state, + ); + if has_focus { let help_text = " . = o|.. = u ── ⇊ = Ctrl+d|↓ = j|⇈ = Ctrl+u|↑ = k "; let help_text_block_width = block_width(help_text); -- cgit v1.2.3 From a94c7d31ec152ff2427092054b99d8c4f3f74cfd Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 10 Mar 2024 07:52:10 +0100 Subject: fix possible overflow during substraction in mark pane It was there for quite a while. --- src/interactive/widgets/mark.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index d50bd0e..8959017 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -295,7 +295,8 @@ impl MarkPane { let num_path_graphemes = path.graphemes(true).count(); match num_path_graphemes + format.total_width() { n if n > area.width as usize => { - let desired_size = num_path_graphemes - (n - area.width as usize); + let desired_size = + num_path_graphemes.saturating_sub(n - area.width as usize); fit_string_graphemes_with_ellipsis( path, num_path_graphemes, -- cgit v1.2.3 From 8ab4ee72423bba54402525b4ea4593f0c582261e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 10 Mar 2024 08:08:02 +0100 Subject: update to the latest versions of `tui-react` and `ratatui` --- Cargo.lock | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- Cargo.toml | 14 +++++++------- 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 67a97a8..193406c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,6 +160,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" +[[package]] +name = "castaway" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a17ed5635fc8536268e5d4de1e22e81ac34419e5f052d4d51f4e01dcc263fcc" +dependencies = [ + "rustversion", +] + [[package]] name = "cc" version = "1.0.88" @@ -227,6 +236,19 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "compact_str" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86b9c4c00838774a6d902ef931eff7470720c51d90c2e32cfe15dc304737b3f" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "ryu", + "static_assertions", +] + [[package]] name = "crossbeam" version = "0.8.4" @@ -310,9 +332,9 @@ dependencies = [ [[package]] name = "crosstermion" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "400415b86f4dc01b9e4e129e822dad900e546287319da7ab229654978d3e07e1" +checksum = "3bb8ffe01d18963d7cdeb1b90d80ff1fc2adc8dd05517a8dfce4844f7157ecc4" dependencies = [ "crossterm", "ratatui", @@ -833,12 +855,13 @@ dependencies = [ [[package]] name = "ratatui" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5659e52e4ba6e07b2dad9f1158f578ef84a73762625ddb51536019f34d180eb" +checksum = "bcb12f8fbf6c62614b0d56eb352af54f6a22410c3b079eb53ee93c7b97dd31d8" dependencies = [ "bitflags 2.4.2", "cassowary", + "compact_str", "crossterm", "indoc", "itertools", @@ -897,6 +920,12 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + [[package]] name = "scopeguard" version = "1.2.0" @@ -980,6 +1009,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.11.0" @@ -988,18 +1023,18 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" [[package]] name = "strum" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "723b93e8addf9aa965ebe2d11da6d7540fa2283fcea14b3371ff055f7ba13f5f" dependencies = [ "strum_macros", ] [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "7a3417fc93d76740d974a01654a09777cb500428cc874ca9f45edfe0c4d4cd18" dependencies = [ "heck", "proc-macro2", @@ -1124,9 +1159,9 @@ dependencies = [ [[package]] name = "tui-react" -version = "0.22.0" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffacd73e2d4666c1aec4e85ab986354909e276f1dbff5c75f86bcebce566511" +checksum = "2914a701e00f3311d869175d83dbb7da374ba9a22a6876f3aa6af2673d3accc6" dependencies = [ "log", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index 4e8b2ca..50c3dab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,9 +31,9 @@ chrono = { version = "0.4.31", default-features = false, features = ["std"] } # 'tui' related unicode-segmentation = { version = "1.3.0", optional = true } unicode-width = { version = "0.1.5", optional = true } -crosstermion = { version = "0.13.0", default-features = false, optional = true } -tui = { package = "ratatui", version = "0.25.0", optional = true, default-features = false } -tui-react = { version = "0.22.0", optional = true } +crosstermion = { version = "0.14.0", default-features = false, optional = true } +tui = { package = "ratatui", version = "0.26.1", optional = true, default-features = false } +tui-react = { version = "0.23.2", optional = true } open = { version = "5.0", optional = true } wild = "2.0.4" owo-colors = "4.0.0" @@ -44,15 +44,15 @@ gix-path = "0.10.1" bstr = "1.8.0" simplelog = "0.12.1" log = "0.4.20" -log-panics = { version = "2", features = ["with-backtrace"]} +log-panics = { version = "2", features = ["with-backtrace"] } crossbeam = "0.8" [[bin]] -name="dua" -path="src/main.rs" +name = "dua" +path = "src/main.rs" [lib] -name="dua" +name = "dua" [profile.release] panic = 'abort' -- cgit v1.2.3 From 24a6c29b3f48289cb6374aa66e84357edb5d0d54 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 10 Mar 2024 08:16:45 +0100 Subject: fix: mark-pane help bar now shows closest to the selected item. Previously this would only work in the first screen, but not when the list was long enough for scrolling. --- src/interactive/widgets/mark.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs index 8959017..67f465e 100644 --- a/src/interactive/widgets/mark.rs +++ b/src/interactive/widgets/mark.rs @@ -359,8 +359,8 @@ impl MarkPane { let list_area = if self.has_focus { let (help_line_area, list_area) = { - let help_at_bottom = - selected.unwrap_or(0) >= inner_area.height.saturating_sub(1) as usize / 2; + let help_at_bottom = selected.unwrap_or(0).saturating_sub(self.list.offset) + >= inner_area.height.saturating_sub(1) as usize / 2; let constraints = { let mut c = vec![Constraint::Length(1), Constraint::Max(256)]; if help_at_bottom { -- cgit v1.2.3