Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat: bump version to 0.1.7, optimize dependencies, improve middle-truncation logic
Samir Hossains440fbc4cfe14
diff --git a/Cargo.lock b/Cargo.lockindex ef3ff93..a435b26 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -810,13 +810,13 @@ dependencies = [[[package]]name = "displaydoc"-version = "0.2.6"+version = "0.2.7"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f"+checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"dependencies = ["proc-macro2","quote",- "syn 2.0.119",+ "syn 3.0.3",][[package]]@@ -2000,7 +2000,7 @@ dependencies = [[[package]]name = "moviebox-tui"-version = "0.1.6"+version = "0.1.7"dependencies = ["base64","crossterm",@@ -2020,6 +2020,8 @@ dependencies = ["serde_json","thiserror 2.0.19","tokio",+ "unicode-segmentation",+ "unicode-width","url",]@@ -3863,9 +3865,7 @@ dependencies = ["bytes","libc","mio",- "parking_lot","pin-project-lite",- "signal-hook-registry","socket2","tokio-macros","windows-sys 0.61.2",diff --git a/Cargo.toml b/Cargo.tomlindex 6ad3f5d..66f276c 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,7 +1,7 @@[package]name = "moviebox-tui"exclude = ["assets/", ".github/", "scripts/", "install.sh", "install.ps1"]-version = "0.1.6"+version = "0.1.7"edition = "2024"description = "A terminal client for finding and streaming movies, TV shows, and anime from the MovieBox catalog."repository = "https://github.com/mesamirh/MovieBox-Tui"@@ -30,8 +30,10 @@ self_update = { version = "0.44.0", default-features = false, features = ["archiserde = { version = "1.0.228", features = ["derive"] }serde_json = "1.0.150"thiserror = "2.0.18"-tokio = { version = "1.52.3", features = ["full"] }+tokio = { version = "1.52.3", features = ["rt-multi-thread", "macros", "sync", "time", "fs", "io-util"] }url = "2.5.8"+unicode-segmentation = "1.12.0"+unicode-width = "0.2.0"[lib]name = "moviebox_tui"diff --git a/src/tui/overlay.rs b/src/tui/overlay.rsindex 81f07bd..c81af5d 100644--- a/src/tui/overlay.rs+++ b/src/tui/overlay.rs@@ -370,15 +370,5 @@ fn notification_style(}fn middle_truncate(value: &str, maximum_width: usize) -> String {- if crate::tui::text::width(value) <= maximum_width {- return value.to_string();- }- let side = maximum_width.saturating_sub(1) / 2;- let start = crate::tui::text::truncate_width(value, side);- let reversed = value.chars().rev().collect::<String>();- let end = crate::tui::text::truncate_width(&reversed, side)- .chars()- .rev()- .collect::<String>();- format!("{start}…{end}")+ crate::tui::text::truncate_middle_width(value, maximum_width)}diff --git a/src/tui/text.rs b/src/tui/text.rsindex 41ac1e6..926cd52 100644--- a/src/tui/text.rs+++ b/src/tui/text.rs@@ -5,14 +5,6 @@ pub fn width(value: &str) -> usize {UnicodeWidthStr::width(value)}-pub fn grapheme_count(value: &str) -> usize {- value.graphemes(true).count()-}--pub fn take_graphemes(value: &str, count: usize) -> String {- value.graphemes(true).take(count).collect()-}-pub fn remove_last_grapheme(value: &mut String) {if let Some((index, _)) = value.grapheme_indices(true).next_back() {value.truncate(index);@@ -41,3 +33,44 @@ pub fn truncate_width(value: &str, max_width: usize) -> String {output.push_str("...");output}++pub fn truncate_middle_width(value: &str, max_width: usize) -> String {+ if width(value) <= max_width {+ return value.to_string();+ }+ if max_width == 0 {+ return String::new();+ }+ if max_width <= 3 {+ return ".".repeat(max_width);+ }++ let content_width = max_width - 1;+ let start_width = content_width.div_ceil(2);+ let end_width = content_width - start_width;++ let mut start = String::new();+ let mut used = 0;+ for grapheme in value.graphemes(true) {+ let grapheme_width = width(grapheme);+ if used + grapheme_width > start_width {+ break;+ }+ start.push_str(grapheme);+ used += grapheme_width;+ }++ let mut end = Vec::new();+ used = 0;+ for grapheme in value.graphemes(true).rev() {+ let grapheme_width = width(grapheme);+ if used + grapheme_width > end_width {+ break;+ }+ end.push(grapheme);+ used += grapheme_width;+ }+ end.reverse();++ format!("{start}…{}", end.concat())+}