summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2024-03-10 08:23:13 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2024-03-10 08:23:13 +0100
commitcaa1e7261bad1b0e2b10628aa14c9d2b6868a14a (patch)
tree27ead6a81510e7f24d7677324f82349e7c345e12
parent0c511ffa0f15e16520353ff712f6bcc11318e379 (diff)
parent24a6c29b3f48289cb6374aa66e84357edb5d0d54 (diff)
fix: avoid crashes when the terminal is resized to unusually small sizes.
-rw-r--r--Cargo.lock55
-rw-r--r--Cargo.toml14
-rw-r--r--src/interactive/widgets/mark.rs33
3 files changed, 81 insertions, 21 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 67a97a8..193406c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -161,6 +161,15 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -228,6 +237,19 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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",
@@ -898,6 +921,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -981,6 +1010,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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'
diff --git a/src/interactive/widgets/mark.rs b/src/interactive/widgets/mark.rs
index a774c73..67f465e 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,
@@ -292,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,
@@ -355,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 {
@@ -411,12 +415,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);