Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(tui): harden responsive text sizing and layout truncation across compact screens
Samir Hossainsf0470b52c94f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d69aefe..c06df8c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -44,6 +44,24 @@- Updated macOS Homebrew installation with explicit `brew trust` step required by Homebrew 6.0+ for third-party taps.- Streamlined quickstart section to reference in-app interactive help (`?`) and `docs/controls.md`, preventing documentation drift.### Fixed+- **Responsive Text Sizing & Layout Truncation**:+ - Raised Details footer split threshold (`DETAILS_FOOTER_SPLIT_THRESHOLD`) to 106 columns, ensuring shortcuts use a clean 2-row layout on terminals between 80 and 105 columns without clipping.+ - Omitted `[Ctrl+P] Provider` hint from the Details footer when in Addon mode or viewing addon streams, recovering 18 columns of footer space.+ - Added line-width budgeting to Details metadata: audios and extra metadata (Genre, Director, Cast) now dynamically truncate to available row width without wrapping beyond their allocated lines.+ - Synchronized Settings tab hit-testing (`category_tab_rects`) with compact rendering (`popup_area.width < 58`), resolving mouse click target divergence on compact terminals.+ - Added dynamic subtext and label truncation in Settings rows, preventing 2-row Paragraph wrapping and off-screen line displacement.+ - Replaced hardcoded path truncation in Settings download directory with dynamic middle truncation (`truncate_middle_width`), maximizing displayed path length while fitting compact rows.+ - Added dynamic description truncation to Home discover categories card, preventing overflow on narrow (50–54 col) screens.+ - Added responsive compact labels (`[Try Provider (P)]` and `[Clear (c)]`) and narrowed separation to No-Results buttons when terminal width is under 56 columns.+ - Removed obsolete `Ctrl+P` hint from search bar mode pill in Addon mode, replacing it with `[Addon Mode]`.+ - Added available width clamping to non-landing search bar placeholders and status messages to prevent 1-row Paragraph wrapping.+ - Omitted redundant media type separator in search results metadata when terminal width is under 36 columns and release year is present, keeping provider badges intact.+ - Budgeted list entry lengths in TV Playlists and Addon Manager popups to fit within inner popup bounds regardless of installed badge counts.+ - Raised Help menu two-column threshold to 102 columns to prevent keybinding description truncation.+ - Added compact title formatting to download gauge when width is under 60 columns.+ - Added compact button formatting (`[u] Update [o] Web [Esc] Back`) to Update Modal on terminals under 60 columns.+ - Added compact header formatting to Updating progress modal when inner width is under 42 columns.+ - Added title boundary protection to `ModalFrame`, truncating overly long titles to preserve border integrity.- **Resilient Configuration & Accurate Metadata**:- Safeguarded user TV playlists (`tv_config.json`) and HTTP addons (`addons_config.json`): replaced destructive error-swallowing deletion with timestamped `.corrupt.{timestamp}` file rotation and sanitized logging on JSON parse failures.- Eliminated fabricated S01E01 fallback in addon metadata adapter, accurately reporting empty series episodes when an upstream catalog entry lacks episode records instead of injecting unplayable dummy data.diff --git a/src/tui/app/run.rs b/src/tui/app/run.rsindex 38f4d39..4d4ea29 100644--- a/src/tui/app/run.rs+++ b/src/tui/app/run.rs@@ -668,20 +668,37 @@ impl App {.unwrap_or("Downloading...");let budget = (dl_area.width as usize).saturating_sub(10);- let status_text =- crate::tui::text::truncate_width(status, budget.saturating_sub(30).max(8));+ let is_compact_gauge = dl_area.width < 60;+ let status_sub = if is_compact_gauge { 16 } else { 30 };+ let status_text = crate::tui::text::truncate_width(+ status,+ budget.saturating_sub(status_sub).max(8),+ );let title_text = if self.state.download_queue_total > 0 {let total = self.state.download_queue_total;let remaining = self.state.download_queue.len();let current = total - remaining;- format!(- " Download: S{:02}E{:02} ({}/{}) | {} [X] Cancel ",- self.state.selected_season,- self.state.selected_episode,- current,- total,- status_text- )+ if is_compact_gauge {+ format!(+ " S{:02}E{:02} ({}/{}) | {} [X] ",+ self.state.selected_season,+ self.state.selected_episode,+ current,+ total,+ status_text+ )+ } else {+ format!(+ " Download: S{:02}E{:02} ({}/{}) | {} [X] Cancel ",+ self.state.selected_season,+ self.state.selected_episode,+ current,+ total,+ status_text+ )+ }+ } else if is_compact_gauge {+ format!(" {} [X] ", status_text)} else {format!(" Download: {} [X] Cancel ", status_text)};@@ -940,31 +957,69 @@ impl App {text.push(Line::from(""));+ let is_compact_modal = inner_area.width < 56;let buttons = match env {- crate::updater::apply::InstallationEnvironment::Homebrew => vec![- Span::styled("[b]", self.theme.shortcut),- Span::styled(" Copy 'brew upgrade' ", self.theme.text),- Span::styled("[o]", self.theme.shortcut),- Span::styled(" Open Release Page ", self.theme.text),- Span::styled("[Esc]", self.theme.shortcut),- Span::styled(" Dismiss", self.theme.text),- ],+ crate::updater::apply::InstallationEnvironment::Homebrew => {+ if is_compact_modal {+ vec![+ Span::styled("[b]", self.theme.shortcut),+ Span::styled(" Copy 'brew upgrade' ", self.theme.text),+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Web ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Back", self.theme.text),+ ]+ } else {+ vec![+ Span::styled("[b]", self.theme.shortcut),+ Span::styled(" Copy 'brew upgrade' ", self.theme.text),+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Open Release Page ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Dismiss", self.theme.text),+ ]+ }+ }crate::updater::apply::InstallationEnvironment::Termux- | crate::updater::apply::InstallationEnvironment::ReadOnly => vec![- Span::styled("[o]", self.theme.shortcut),- Span::styled(" Open Release Page ", self.theme.text),- Span::styled("[Esc]", self.theme.shortcut),- Span::styled(" Dismiss", self.theme.text),- ],+ | crate::updater::apply::InstallationEnvironment::ReadOnly => {+ if is_compact_modal {+ vec![+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Web ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Back", self.theme.text),+ ]+ } else {+ vec![+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Open Release Page ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Dismiss", self.theme.text),+ ]+ }+ }crate::updater::apply::InstallationEnvironment::DirectReplace- | crate::updater::apply::InstallationEnvironment::WindowsHelper => vec![- Span::styled("[u]", self.theme.shortcut),- Span::styled(" Update Now ", self.theme.text),- Span::styled("[o]", self.theme.shortcut),- Span::styled(" Open Release Page ", self.theme.text),- Span::styled("[Esc]", self.theme.shortcut),- Span::styled(" Dismiss", self.theme.text),- ],+ | crate::updater::apply::InstallationEnvironment::WindowsHelper => {+ if is_compact_modal {+ vec![+ Span::styled("[u]", self.theme.shortcut),+ Span::styled(" Update ", self.theme.text),+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Web ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Back", self.theme.text),+ ]+ } else {+ vec![+ Span::styled("[u]", self.theme.shortcut),+ Span::styled(" Update Now ", self.theme.text),+ Span::styled("[o]", self.theme.shortcut),+ Span::styled(" Open Release Page ", self.theme.text),+ Span::styled("[Esc]", self.theme.shortcut),+ Span::styled(" Dismiss", self.theme.text),+ ]+ }+ }};text.push(Line::from(buttons).alignment(Alignment::Center));@@ -1012,8 +1067,22 @@ impl App {.as_deref().unwrap_or("Applying update...");- let text = vec![- Line::from(vec![+ let is_compact_header = inner_area.width < 42;+ let header_spans = if is_compact_header {+ vec![+ Span::styled(+ format!("{spinner} "),+ self.theme+ .accent+ .add_modifier(ratatui::style::Modifier::BOLD),+ ),+ Span::styled(+ format!("v{} → v{}", env!("CARGO_PKG_VERSION"), target_version),+ self.theme.highlight,+ ),+ ]+ } else {+ vec![Span::styled(format!("{spinner} "),self.theme@@ -1030,8 +1099,11 @@ impl App {format!("v{} → v{}", env!("CARGO_PKG_VERSION"), target_version),self.theme.highlight,),- ])- .alignment(Alignment::Center),+ ]+ };++ let text = vec![+ Line::from(header_spans).alignment(Alignment::Center),Line::from(""),Line::from(vec![Span::styled(crate::tui::text::truncate_width(diff --git a/src/tui/overlay.rs b/src/tui/overlay.rsindex 0ad03ea..27362d7 100644--- a/src/tui/overlay.rs+++ b/src/tui/overlay.rs@@ -610,16 +610,21 @@ pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {const UPDATE_SEGMENT: u16 = 18;const OPEN_SEGMENT: u16 = 26;const DISMISS_SEGMENT: u16 = 12;- let footer_width = UPDATE_SEGMENT + OPEN_SEGMENT + DISMISS_SEGMENT;let popup_area = centered(area, desired_w, desired_h, min_w.min(area.width), max_w);+ let (update_seg, open_seg, dismiss_seg) = if popup_area.width < 58 {+ (12, 10, 10)+ } else {+ (UPDATE_SEGMENT, OPEN_SEGMENT, DISMISS_SEGMENT)+ };+ let footer_width = update_seg + open_seg + dismiss_seg;+let button_row_y = popup_area.y + popup_area.height.saturating_sub(2);let inner_width = popup_area.width.saturating_sub(2);let footer_start = popup_area.x + 1 + inner_width.saturating_sub(footer_width) / 2;- let update_btn_end_x = footer_start + UPDATE_SEGMENT;- let open_btn_end_x = update_btn_end_x + OPEN_SEGMENT;- let open_button_midpoint_x = update_btn_end_x + OPEN_SEGMENT / 2;-+ let update_btn_end_x = footer_start + update_seg;+ let open_btn_end_x = update_btn_end_x + open_seg;+ let open_button_midpoint_x = update_btn_end_x + open_seg / 2;UpdateModalLayout {popup_area,display_count,diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rsindex e0c980a..44520a9 100644--- a/src/tui/screens/details.rs+++ b/src/tui/screens/details.rs@@ -82,7 +82,7 @@ impl DetailsLayoutTier {};(content_rows as u16 + 2).clamp(minimum, maximum)}- pub(crate) fn footer_height(self, width: u16) -> u16 {+ pub fn footer_height(self, width: u16) -> u16 {if width >= DETAILS_FOOTER_SPLIT_THRESHOLD {1} else {@@ -91,7 +91,7 @@ impl DetailsLayoutTier {}}-pub const DETAILS_FOOTER_SPLIT_THRESHOLD: u16 = 80;+pub const DETAILS_FOOTER_SPLIT_THRESHOLD: u16 = 106;pub(crate) fn visible_selector_panes(available_panes: &[crate::tui::state::DetailsPane],@@ -529,16 +529,37 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)}});+ let bullet_w = crate::tui::text::width(bullet_sep);+ let provider_name = details.id.provider.label();+ let provider_w = if !provider_name.is_empty() {+ bullet_w + crate::tui::text::width(provider_name)+ } else {+ 0+ };+ let current_badge_w: usize = badge_spans+ .iter()+ .map(|s| crate::tui::text::width(&s.content))+ .sum();+if let Some(audios) = audio_str {- badge_spans.push(Span::styled(bullet_sep, theme.overlay1));- badge_spans.push(Span::styled(- "Audio: ",- theme.subtext1.add_modifier(Modifier::BOLD),- ));- badge_spans.push(Span::styled(audios, theme.accent));+ let label_w = 7;+ if current_badge_w + provider_w + bullet_w + label_w + 4 <= text_width {+ badge_spans.push(Span::styled(bullet_sep, theme.overlay1));+ badge_spans.push(Span::styled(+ "Audio: ",+ theme.subtext1.add_modifier(Modifier::BOLD),+ ));+ let available_audio_w =+ text_width.saturating_sub(current_badge_w + provider_w + bullet_w + label_w);+ let display_audios = if crate::tui::text::width(&audios) > available_audio_w {+ crate::tui::text::truncate_width(&audios, available_audio_w)+ } else {+ audios+ };+ badge_spans.push(Span::styled(display_audios, theme.accent));+ }}- let provider_name = details.id.provider.label();if !provider_name.is_empty() {badge_spans.push(Span::styled(bullet_sep, theme.overlay1));badge_spans.push(Span::styled(provider_name.to_string(), theme.subtext1));@@ -554,49 +575,92 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)}let mut extra_meta_spans = Vec::new();+ let mut extra_meta_w = 0;if !details.genres.is_empty() {- extra_meta_spans.push(Span::styled(- "Genre: ",- theme.subtext1.add_modifier(Modifier::BOLD),- ));- extra_meta_spans.push(Span::styled(- genres.clone(),- theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),- ));+ let label_w = 7;+ let val_w = crate::tui::text::width(&genres);+ if label_w + 4 <= text_width {+ extra_meta_spans.push(Span::styled(+ "Genre: ",+ theme.subtext1.add_modifier(Modifier::BOLD),+ ));+ let available_genre_w = text_width.saturating_sub(label_w);+ let display_genres = if val_w > available_genre_w {+ crate::tui::text::truncate_width(&genres, available_genre_w)+ } else {+ genres.clone()+ };+ extra_meta_w += label_w + crate::tui::text::width(&display_genres);+ extra_meta_spans.push(Span::styled(+ display_genres,+ theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),+ ));+ }}if let Some(dir) = details.director.as_deref().filter(|d| !d.trim().is_empty() && *d != "N/A"){- if !extra_meta_spans.is_empty() {- extra_meta_spans.push(Span::styled(bullet_sep, theme.overlay1));+ let sep_w = if !extra_meta_spans.is_empty() {+ bullet_w+ } else {+ 0+ };+ let label_w = 10;+ let val_w = crate::tui::text::width(dir);+ if extra_meta_w + sep_w + label_w + 4 <= text_width {+ if !extra_meta_spans.is_empty() {+ extra_meta_spans.push(Span::styled(bullet_sep, theme.overlay1));+ }+ extra_meta_spans.push(Span::styled(+ "Director: ",+ theme.subtext1.add_modifier(Modifier::BOLD),+ ));+ let available_dir_w = text_width.saturating_sub(extra_meta_w + sep_w + label_w);+ let display_dir = if val_w > available_dir_w {+ crate::tui::text::truncate_width(dir, available_dir_w)+ } else {+ dir.to_string()+ };+ extra_meta_w += sep_w + label_w + crate::tui::text::width(&display_dir);+ extra_meta_spans.push(Span::styled(+ display_dir,+ theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),+ ));}- extra_meta_spans.push(Span::styled(- "Director: ",- theme.subtext1.add_modifier(Modifier::BOLD),- ));- extra_meta_spans.push(Span::styled(- dir.to_string(),- theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),- ));}if let Some(cast) = details.stars.as_deref().filter(|s| !s.trim().is_empty() && *s != "N/A"){- if !extra_meta_spans.is_empty() {- extra_meta_spans.push(Span::styled(bullet_sep, theme.overlay1));+ let sep_w = if !extra_meta_spans.is_empty() {+ bullet_w+ } else {+ 0+ };+ let label_w = 6;+ let val_w = crate::tui::text::width(cast);+ if extra_meta_w + sep_w + label_w + 4 <= text_width {+ if !extra_meta_spans.is_empty() {+ extra_meta_spans.push(Span::styled(bullet_sep, theme.overlay1));+ }+ extra_meta_spans.push(Span::styled(+ "Cast: ",+ theme.subtext1.add_modifier(Modifier::BOLD),+ ));+ let available_cast_w = text_width.saturating_sub(extra_meta_w + sep_w + label_w);+ let display_cast = if val_w > available_cast_w {+ crate::tui::text::truncate_width(cast, available_cast_w)+ } else {+ cast.to_string()+ };+ extra_meta_spans.push(Span::styled(+ display_cast,+ theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),+ ));}- extra_meta_spans.push(Span::styled(- "Cast: ",- theme.subtext1.add_modifier(Modifier::BOLD),- ));- extra_meta_spans.push(Span::styled(- cast.to_string(),- theme_color(theme.subtext1, theme.text.fg.unwrap_or(Color::White)),- ));}let has_extra_meta = !extra_meta_spans.is_empty();@@ -1711,6 +1775,11 @@ fn details_footer(} else {"Favorite"};+ let show_provider = !state.is_addon_mode+ && !state+ .selected_details+ .as_ref()+ .is_some_and(|d| d.id.provider == crate::providers::ProviderKind::Addons);let mut primary = Vec::new();let mut secondary = Vec::new();@@ -1724,22 +1793,26 @@ fn details_footer(theme,));secondary.extend(footer_group("f", fav_label, false, theme));- secondary.extend(footer_group(- crate::tui::text::CTRL_P_STR,- "Provider",- false,- theme,- ));+ if show_provider {+ secondary.extend(footer_group(+ crate::tui::text::CTRL_P_STR,+ "Provider",+ false,+ theme,+ ));+ }secondary.extend(footer_group("Esc", "Back", false, theme));} else if is_languages {primary.extend(footer_group("Enter", "Select", true, theme));primary.extend(footer_group("f", fav_label, false, theme));- secondary.extend(footer_group(- crate::tui::text::CTRL_P_STR,- "Provider",- false,- theme,- ));+ if show_provider {+ secondary.extend(footer_group(+ crate::tui::text::CTRL_P_STR,+ "Provider",+ false,+ theme,+ ));+ }secondary.extend(footer_group("Tab", "Streams", false, theme));secondary.extend(footer_group("Esc", "Back", false, theme));} else if is_seasons {@@ -1755,12 +1828,14 @@ fn details_footer(theme,));primary.extend(footer_group("f", fav_label, false, theme));- secondary.extend(footer_group(- crate::tui::text::CTRL_P_STR,- "Provider",- false,- theme,- ));+ if show_provider {+ secondary.extend(footer_group(+ crate::tui::text::CTRL_P_STR,+ "Provider",+ false,+ theme,+ ));+ }secondary.extend(footer_group("Tab", "Streams", false, theme));secondary.extend(footer_group("Esc", "Back", false, theme));} else if is_episodes {@@ -1776,23 +1851,27 @@ fn details_footer(theme,));primary.extend(footer_group("f", fav_label, false, theme));- secondary.extend(footer_group(- crate::tui::text::CTRL_P_STR,- "Provider",- false,- theme,- ));+ if show_provider {+ secondary.extend(footer_group(+ crate::tui::text::CTRL_P_STR,+ "Provider",+ false,+ theme,+ ));+ }secondary.extend(footer_group("Tab", "Streams", false, theme));secondary.extend(footer_group("Esc", "Back", false, theme));} else {primary.extend(footer_group("Enter", "Select", true, theme));primary.extend(footer_group("f", fav_label, false, theme));- secondary.extend(footer_group(- crate::tui::text::CTRL_P_STR,- "Provider",- false,- theme,- ));+ if show_provider {+ secondary.extend(footer_group(+ crate::tui::text::CTRL_P_STR,+ "Provider",+ false,+ theme,+ ));+ }secondary.extend(footer_group("Tab", "Streams", false, theme));secondary.extend(footer_group("Esc", "Back", false, theme));}@@ -2171,7 +2250,7 @@ mod tests {state.details_pane = crate::tui::state::DetailsPane::Streams;state.subtitle_list = vec![("English".to_string(), "http://sub".to_string())];- let (primary, secondary) = details_footer(&state, &theme, 100);+ let (primary, secondary) = details_footer(&state, &theme, 120);let mut all_spans = primary;all_spans.extend(secondary);let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();@@ -2179,10 +2258,25 @@ mod tests {assert!(!footer_text.contains("[o] Open With"));assert!(footer_text.contains("[d] Download"));assert!(footer_text.contains("[f] Favorite"));+ assert!(footer_text.contains("Provider"));assert!(footer_text.contains("[Esc] Back"));+ let (compact_primary, compact_secondary) = details_footer(&state, &theme, 90);+ let mut compact_spans = compact_primary;+ compact_spans.extend(compact_secondary);+ let compact_text: String = compact_spans.iter().map(|s| s.content.as_ref()).collect();+ assert!(compact_text.contains("[d] Save"));++ state.is_addon_mode = true;+ let (addon_primary, addon_secondary) = details_footer(&state, &theme, 120);+ let mut addon_spans = addon_primary;+ addon_spans.extend(addon_secondary);+ let addon_text: String = addon_spans.iter().map(|s| s.content.as_ref()).collect();+ assert!(!addon_text.contains("Provider"));+ state.is_addon_mode = false;+state.details_pane = crate::tui::state::DetailsPane::Seasons;- let (primary, secondary) = details_footer(&state, &theme, 100);+ let (primary, secondary) = details_footer(&state, &theme, 120);let mut all_spans = primary;all_spans.extend(secondary);let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();@@ -2193,7 +2287,7 @@ mod tests {assert!(footer_text.contains("[Esc] Back"));state.details_pane = crate::tui::state::DetailsPane::Episodes;- let (primary, secondary) = details_footer(&state, &theme, 100);+ let (primary, secondary) = details_footer(&state, &theme, 120);let mut all_spans = primary;all_spans.extend(secondary);let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rsindex 693768a..a36729f 100644--- a/src/tui/screens/help.rs+++ b/src/tui/screens/help.rs@@ -139,7 +139,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {let max_lines = left_col.len().max(right_col.len());let capacity = area.height.saturating_sub(6).max(4) as usize;- let two_columns = area.width >= 86 && capacity >= max_lines.saturating_sub(4);+ let two_columns = area.width >= 102 && capacity >= max_lines.saturating_sub(4);if !two_columns && all_lines.len() > capacity {let max_scroll = all_lines.len().saturating_sub(capacity);diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex d411a45..98b22a8 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -324,36 +324,55 @@ fn render_search_state()]));lines.push(Line::from(""));+ let is_compact_btn = area.width < 56;+ let sep = if is_compact_btn { " " } else { " " };let pills = if state.is_tv_mode {+ let (btn1_label, btn2_label) = if is_compact_btn {+ ("[ Reload (", "[ Clear (")+ } else {+ ("[ Reload Playlists (", "[ Clear Search (")+ };vec![- Span::styled("[ Reload Playlists (", theme.subtext1),+ Span::styled(btn1_label, theme.subtext1),Span::styled("r", theme.shortcut),Span::styled(") ]", theme.subtext1),- Span::raw(" "),- Span::styled("[ Clear Search (", theme.subtext1),+ Span::raw(sep),+ Span::styled(btn2_label, theme.subtext1),Span::styled("c", theme.shortcut),Span::styled(") ]", theme.subtext1),]} else if state.is_addon_mode {+ let (btn1_label, btn2_label) = if is_compact_btn {+ ("[ Addons (", "[ Clear (")+ } else {+ ("[ Addon Manager (", "[ Clear Search (")+ };vec![- Span::styled("[ Addon Manager (", theme.subtext1),+ Span::styled(btn1_label, theme.subtext1),Span::styled(ctrl_p, theme.shortcut),Span::styled(") ]", theme.subtext1),- Span::raw(" "),- Span::styled("[ Clear Search (", theme.subtext1),+ Span::raw(sep),+ Span::styled(btn2_label, theme.subtext1),Span::styled("c", theme.shortcut),Span::styled(") ]", theme.subtext1),]} else {+ let btn2_label = if is_compact_btn {+ "[ Clear ("+ } else {+ "[ Clear Search ("+ };+ let btn1_label = if is_compact_btn {+ "[ Try Provider (".to_string()+ } else {+ format!("[ Try on {} (", next_provider.label())+ };vec![- Span::styled(- format!("[ Try on {} (", next_provider.label()),- theme.subtext1,- ),+ Span::styled(btn1_label, theme.subtext1),Span::styled(ctrl_p, theme.shortcut),Span::styled(") ]", theme.subtext1),- Span::raw(" "),- Span::styled("[ Clear Search (", theme.subtext1),+ Span::raw(sep),+ Span::styled(btn2_label, theme.subtext1),Span::styled("c", theme.shortcut),Span::styled(") ]", theme.subtext1),]@@ -459,15 +478,26 @@ pub(crate) fn no_results_button_hitboxes(is_tv_mode: bool,is_addon_mode: bool,) -> (Rect, Rect) {- let btn1_w = if is_tv_mode {- 24- } else if is_addon_mode {- 19 + ctrl_p.len() as u16+ let is_compact_btn = area.width < 56;+ let (btn1_w, btn2_w, sep_w) = if is_compact_btn {+ let b1 = if is_tv_mode {+ 14+ } else if is_addon_mode {+ 12 + ctrl_p.len() as u16+ } else {+ 18 + ctrl_p.len() as u16+ };+ (b1, 13, 2)} else {- (14 + next_provider_label.len() + ctrl_p.len()) as u16+ let b1 = if is_tv_mode {+ 24+ } else if is_addon_mode {+ 19 + ctrl_p.len() as u16+ } else {+ (14 + next_provider_label.len() + ctrl_p.len()) as u16+ };+ (b1, 20, 8)};- let btn2_w = 20;- let sep_w = 8;let total_w = btn1_w + sep_w + btn2_w;let start_x = area.x + area.width.saturating_sub(total_w) / 2;let card_y = area.y + area.height.saturating_sub(3) / 3;@@ -713,9 +743,18 @@ pub(crate) fn render_discover_landing(for (curr_y, (title, desc)) in (inner_area.y..inner_area.bottom()).zip(presets) {let pointer = if state.basic_terminal { " - " } else { " · " };- let tag_len = crate::tui::text::width(desc);+ let pointer_w = crate::tui::text::width(pointer);let title_w = crate::tui::text::width(title);- let margins_len = 6;+ let margins_len = 2 + pointer_w + 1;+ let max_desc_w = (inner_area.width as usize).saturating_sub(title_w + margins_len + 1);+ let display_desc = if max_desc_w >= 4 && crate::tui::text::width(desc) > max_desc_w {+ crate::tui::text::truncate_width(desc, max_desc_w)+ } else if max_desc_w < 4 {+ String::new()+ } else {+ desc.to_string()+ };+ let tag_len = crate::tui::text::width(&display_desc);let pad_len = (inner_area.width as usize).saturating_sub(margins_len + title_w + tag_len);let line = Line::from(vec![@@ -723,7 +762,7 @@ pub(crate) fn render_discover_landing(Span::styled(pointer, theme.accent),Span::styled(title, theme.text.add_modifier(Modifier::BOLD)),Span::raw(" ".repeat(pad_len)),- Span::styled(desc, theme.text_dim),+ Span::styled(display_desc, theme.text_dim),Span::raw(" "),]);@@ -896,8 +935,7 @@ fn render_search_bar(if is_ultra_compact {"[Addons]".to_string()} else {- let sep = if state.basic_terminal { "-" } else { "·" };- format!("[Addons {sep} {ctrl_p}]")+ "[Addon Mode]".to_string()}} else {let label = state.active_provider.label();@@ -936,8 +974,7 @@ fn render_search_bar(let text = if is_ultra_compact {"[Addons]".to_string()} else {- let sep = if state.basic_terminal { "-" } else { "·" };- format!("[Addons {sep} {ctrl_p}]")+ "[Addon Mode]".to_string()};let style = if state.basic_terminal {theme.teal@@ -990,12 +1027,16 @@ fn render_search_bar(&& !state.status_message.is_empty()&& is_query_empty&& !editing;+ let available_text_w =+ (search_split[0].width as usize).saturating_sub(prefix_width as usize + 2);+ let raw_placeholder = if has_status {+ state.status_message.as_str()+ } else {+ dynamic_search_placeholder(state)+ };+ let placeholder_text = crate::tui::text::truncate_width(raw_placeholder, available_text_w);let search_line = if is_query_empty {- let placeholder_text = if has_status {- state.status_message.as_str()- } else {- dynamic_search_placeholder(state)- };+ let placeholder_text = placeholder_text.as_str();if editing && !modal_active {let cursor_char = if state.basic_terminal { "█" } else { "▎" };@@ -1890,14 +1931,16 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)theme.text_dim,));}- if res.release_year != "Unknown" && !res.release_year.is_empty() {+ let has_year = res.release_year != "Unknown" && !res.release_year.is_empty();+ if has_year {row2_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));}- row2_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));- row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));-+ if text_area.width >= 36 || !has_year {+ row2_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));+ }row2_spans.push(crate::tui::widgets::badge::provider_badge_span(res.provider,theme,@@ -1999,13 +2042,16 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)TvManagerRow::Playlist(index) => {let source =state.tv_playlists.get(*index).cloned().unwrap_or_default();- let url_budget = (inner_area.width as usize).saturating_sub(6).max(12);+ let index_str = format!("{}", index + 1);+ let url_budget = (inner_area.width as usize)+ .saturating_sub(index_str.len() + 6)+ .max(10);let display_source =crate::tui::text::truncate_middle_width(&source, url_budget);ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![ratatui::text::Span::raw(" "),ratatui::text::Span::styled(- format!("{} {}", index + 1, display_source),+ format!("{} {}", index_str, display_source),theme.text,),]))@@ -2138,31 +2184,38 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)} else {ratatui::text::Span::styled("[ ] ", theme.text_dim)};- let name_budget = (inner_area.width as usize)- .saturating_sub(3 + 4 + 12)- .max(10);- let addon_label = format!("{} v{} ", a.name, a.version.as_deref().unwrap_or("1.0"));- let name = ratatui::text::Span::styled(- crate::tui::text::truncate_width(&addon_label, name_budget),- if is_selected {- theme.text.add_modifier(ratatui::style::Modifier::BOLD)- } else {- theme.text- },- );let mut badges = Vec::new();+ let mut badges_w = 0;if a.is_core() {badges.push(ratatui::text::Span::styled("[Core] ", theme.lavender));+ badges_w += 7;}if a.provides_meta {badges.push(ratatui::text::Span::styled("[Meta] ", theme.sapphire));+ badges_w += 7;}if a.provides_stream {badges.push(ratatui::text::Span::styled("[Streams] ", theme.rating));+ badges_w += 10;}if a.provides_catalog {badges.push(ratatui::text::Span::styled("[Catalog]", theme.teal));+ badges_w += 9;}+ let prefix_w = 2;+ let check_w = 4;+ let name_budget = (inner_area.width as usize)+ .saturating_sub(prefix_w + check_w + badges_w + 2)+ .max(8);+ let addon_label = format!("{} v{} ", a.name, a.version.as_deref().unwrap_or("1.0"));+ let name = ratatui::text::Span::styled(+ crate::tui::text::truncate_width(&addon_label, name_budget),+ if is_selected {+ theme.text.add_modifier(ratatui::style::Modifier::BOLD)+ } else {+ theme.text+ },+ );let mut spans = vec![ratatui::text::Span::raw(" "), prefix, check, name];spans.extend(badges);items.push(ratatui::widgets::ListItem::new(ratatui::text::Line::from(@@ -3263,7 +3316,7 @@ mod tests {}addon_rendered.push('\n');}- assert!(addon_rendered.contains("[Addons"));+ assert!(addon_rendered.contains("[Addon Mode]"));assert!(addon_rendered.contains("Search movies and series via addons…"));}diff --git a/src/tui/widgets/modal.rs b/src/tui/widgets/modal.rsindex dab490a..41aa1ab 100644--- a/src/tui/widgets/modal.rs+++ b/src/tui/widgets/modal.rs@@ -37,8 +37,10 @@ impl<'a> ModalFrame<'a> {} else {Style::default().bg(self.theme.mantle.fg.unwrap_or(self.theme.base))};+ let title_budget = (area.width as usize).saturating_sub(4);+ let display_title = crate::tui::text::truncate_width(self.title.trim(), title_budget);let block = Block::default()- .title(format!(" {} ", self.title.trim()))+ .title(format!(" {display_title} ")).title_style(self.theme.title).borders(Borders::ALL).border_type(overlay::border_type(self.basic_terminal))diff --git a/src/tui/widgets/settings.rs b/src/tui/widgets/settings.rsindex 0027bcf..f6b49c3 100644--- a/src/tui/widgets/settings.rs+++ b/src/tui/widgets/settings.rs@@ -24,9 +24,21 @@ pub fn category_tab_rects() -> Vec<(SettingsCategory, Rect)> {let mut results = Vec::new();let mut current_x = tabs_area.x;+ let compact = tabs_area.width < 52;+ let gap = if compact { 2 } else { 5 };for cat in SettingsCategory::ALL {- let width = crate::tui::text::width(cat.title()) as u16;+ let title = if compact {+ match cat {+ SettingsCategory::General => "1:Gen",+ SettingsCategory::ContentModes => "2:Modes",+ SettingsCategory::Appearance => "3:Theme",+ SettingsCategory::StorageInfo => "4:Info",+ }+ } else {+ cat.title()+ };+ let width = crate::tui::text::width(title) as u16;if current_x + width <= tabs_area.right() {results.push((cat,@@ -38,7 +50,7 @@ pub fn category_tab_rects(},));}- current_x = current_x.saturating_add(width).saturating_add(5);+ current_x = current_x.saturating_add(width).saturating_add(gap);}results}@@ -358,7 +370,6 @@ fn render_row(let cursor_width = crate::tui::text::width(cursor);let label_width = crate::tui::text::width(row.label);- let total_left_width = cursor_width + label_width;let right_width: usize = row.value_spans@@ -367,11 +378,20 @@ fn render_row(.sum();let right_margin = 1;- let pad = (area.width as usize).saturating_sub(total_left_width + right_width + right_margin);+ let area_width = area.width as usize;+ let max_label_w = area_width.saturating_sub(cursor_width + right_width + right_margin + 1);+ let display_label = if label_width > max_label_w && max_label_w >= 4 {+ crate::tui::text::truncate_width(row.label, max_label_w)+ } else {+ row.label.to_string()+ };+ let display_label_w = crate::tui::text::width(&display_label);+ let pad =+ area_width.saturating_sub(cursor_width + display_label_w + right_width + right_margin);let mut line1_spans = Vec::new();line1_spans.push(Span::styled(cursor, cursor_style));- line1_spans.push(Span::styled(row.label, label_style));+ line1_spans.push(Span::styled(display_label, label_style));if pad > 0 {line1_spans.push(Span::raw(" ".repeat(pad)));} else {@@ -379,13 +399,20 @@ fn render_row(}line1_spans.extend(row.value_spans);line1_spans.push(Span::raw(" ".repeat(right_margin)));+let subtext_indent = " ";- let subtext_width = crate::tui::text::width(row.subtext);- let subtext_pad = (area.width as usize).saturating_sub(subtext_indent.len() + subtext_width);+ let max_subtext_w = area_width.saturating_sub(subtext_indent.len());+ let display_subtext = if crate::tui::text::width(row.subtext) > max_subtext_w {+ crate::tui::text::truncate_width(row.subtext, max_subtext_w)+ } else {+ row.subtext.to_string()+ };+ let subtext_width = crate::tui::text::width(&display_subtext);+ let subtext_pad = area_width.saturating_sub(subtext_indent.len() + subtext_width);let mut line2_spans = Vec::new();line2_spans.push(Span::raw(subtext_indent));line2_spans.push(Span::styled(- row.subtext,+ display_subtext,if row.is_selected {theme.subtext1} else {@@ -395,7 +422,6 @@ fn render_row(if subtext_pad > 0 {line2_spans.push(Span::raw(" ".repeat(subtext_pad)));}-let lines = if area.height >= 2 {vec![Line::from(line1_spans), Line::from(line2_spans)]} else {@@ -470,7 +496,9 @@ fn render_general_settings(frame: &mut Frame, area: Rect, state: &AppState, themlet input_str = input.as_str();let cursor_idx = input.cursor().min(input_str.len());let (before, after) = input_str.split_at(cursor_idx);- let truncated_before = crate::tui::text::truncate_width(before, 26);+ let input_budget = (row_area.width as usize).saturating_sub(21).clamp(10, 60);+ let truncated_before =+ crate::tui::text::truncate_width(before, input_budget.saturating_sub(4));if state.basic_terminal {vec![Span::styled(truncated_before, theme.text),@@ -500,7 +528,8 @@ fn render_general_settings(frame: &mut Frame, area: Rect, state: &AppState, them.unwrap_or_else(|| {crate::logging::sanitize_path(crate::service::resolve_download_dir(None))});- let truncated = crate::tui::text::truncate_width(&path_str, 28);+ let path_budget = (row_area.width as usize).saturating_sub(21).clamp(10, 60);+ let truncated = crate::tui::text::truncate_middle_width(&path_str, path_budget);vec![Span::styled(truncated,if state.basic_terminal {@@ -1110,6 +1139,24 @@ mod tests {let clicked_subtext =settings_row_at(popup, SettingsCategory::General, 40, row_rects[0].y + 1);assert_eq!(clicked_subtext, Some(0));++ let compact_popup = Rect::new(2, 2, 54, 16);+ assert_eq!(+ settings_category_tab_at(compact_popup, 6, 3, false, SettingsCategory::General),+ Some(SettingsCategory::General)+ );+ assert_eq!(+ settings_category_tab_at(compact_popup, 14, 3, false, SettingsCategory::General),+ Some(SettingsCategory::ContentModes)+ );+ assert_eq!(+ settings_category_tab_at(compact_popup, 23, 3, false, SettingsCategory::General),+ Some(SettingsCategory::Appearance)+ );+ assert_eq!(+ settings_category_tab_at(compact_popup, 32, 3, false, SettingsCategory::General),+ Some(SettingsCategory::StorageInfo)+ );}#[test]fn test_render_settings_modal_suppresses_selection_during_popup() {diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rsindex 6d45c9b..6234ae2 100644--- a/tests/tui_acceptance.rs+++ b/tests/tui_acceptance.rs@@ -809,3 +809,50 @@ async fn test_ctrl_p_scoped_strictly_to_streaming_mode() {app.handle_action(Action::Key(ctrl_p)).await;assert!(!app.state().addon_manager_popup);}+#[tokio::test]+async fn test_tui_layout_truncation_and_bounds() {+ let sizes = [(50, 14), (60, 18), (80, 24), (120, 30)];+ let mut app = App::new();++ for (w, h) in sizes {+ let backend = TestBackend::new(w, h);+ let mut terminal = Terminal::new(backend).unwrap();++ app.state_mut().active_screen = Screen::Home;+ app.state_mut().has_search_settled = true;+ app.state_mut().search_results.clear();+ app.state_mut().search_query.set_content("some_query");+ let res = terminal.draw(|frame| app.draw(frame));+ assert!(res.is_ok());++ let text: String = terminal+ .backend()+ .buffer()+ .content()+ .iter()+ .map(|c| c.symbol())+ .collect();+ if w < 56 {+ assert!(text.contains("Try Provider") || text.contains("Clear"));+ } else {+ assert!(text.contains("Clear Search"));+ }++ app.state_mut().show_settings_popup = true;+ let res_settings = terminal.draw(|frame| app.draw(frame));+ assert!(res_settings.is_ok());+ app.state_mut().show_settings_popup = false;++ app.state_mut().download_progress = Some(50.0);+ app.state_mut().download_status = Some("Downloading item".to_string());+ let res_download = terminal.draw(|frame| app.draw(frame));+ assert!(res_download.is_ok());+ app.state_mut().download_progress = None;+ }++ let tier = moviebox_tui::tui::screens::details::DetailsLayoutTier::Narrow;+ assert_eq!(tier.footer_height(80), 2);+ assert_eq!(tier.footer_height(105), 2);+ assert_eq!(tier.footer_height(106), 1);+ assert_eq!(tier.footer_height(120), 1);+}