Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

refactor(ui): clean structured help layout, remove s subtitle shortcut, and clean code comments

Samir Hossainsaf6c9f8b240f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2709d2e..b9d12c5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,8 +3,9 @@
## [Unreleased]
### Added
+- **Structured Categorized In-App Help Dialog (`src/tui/screens/help.rs`)**: Redesigned the interactive keybinding help menu (`?`) with balanced side-by-side columns: left column features dedicated `Navigation` and mode-specific `Actions` (`Play`, `Download`, `Favorite`, `Provider`), right column features `Content Modes` and `Commands & Shortcuts` (`/settings`, `/browse`, `/history`, `/favorites`, `/theme`, `/exit`). Eliminates split orphaned headers and guarantees clean 18-character key padding across all terminal sizes.
- **`/exit` Slash Command (`src/tui/commands.rs`, `src/tui/app/search.rs`)**: Added `/exit` (with `/quit` and `/q` aliases) to the slash command engine, allowing users to cleanly exit the application and restore the terminal state directly from the search bar.
-- **Streamlined Playback & "Open With" Removal (`src/tui/`)**: Removed the redundant `[o] Open With` action and shortcuts from the Details footer, keyboard handlers, mouse hitboxes, and help dialogs in favor of configuring default media players (`mpv`, `VLC`, `IINA`, `Android`) directly in the Settings Hub (`/settings`).
+- **Streamlined Playback & Shortcut Simplification (`src/tui/`)**: Removed the redundant `[o] Open With` and dedicated `[s] Subtitles` picker shortcuts from Details footer action bars, keyboard handlers, mouse hitboxes, and help dialogs in favor of automatic subtitle stream handling and configuring default media players (`mpv`, `VLC`, `IINA`, `Android`) directly in the Settings Hub (`/settings`).
- **Unified `f` Shortcut for Favorites (`src/tui/app/keyboard.rs`, `src/tui/screens/help.rs`)**: Standardized favorite / unfavorite toggling across all screens exclusively to `f` / `F`, removing redundant `*` keybindings and streamlining in-app help overlays and documentation.
- **Responsive Details Screen Layout & Narrow Terminal Polish (`src/tui/screens/details.rs`, `src/tui/app/mouse.rs`)**:
- **Narrow-Screen Dynamic Selector Pane Focus**: On compact terminal widths (<85 columns), renders the active selector pane (Audio, Seasons, or Episodes) with 100% available horizontal width instead of horizontally cramming 3 unreadable 14-character columns that cut off titles, language names, and season numbers.
diff --git a/docs/controls.md b/docs/controls.md
index 69af5b1..1feb537 100644
--- a/docs/controls.md
+++ b/docs/controls.md
@@ -64,7 +64,6 @@ All popup dialogs (Theme picker, Browse categories, Player picker, TV Manager, A
- **`d`**: Download current episode or full season batch.
- **`r`**: Refresh search results / stream list.
- **`f`**: Favorite / unfavorite the selected title (Home & Details screens).
-- **`s`**: Open subtitle language picker on the Details screen.
- **`/settings`**: Open interactive Settings & Preferences Hub.
- **`/browse`**: Open curated browse categories (Trending, Popular, Top Rated, etc.).
- **`/history`**: Open watch history (`Space` or `P` to instantly resume recorded episode/movie).
@@ -82,7 +81,6 @@ All popup dialogs (Theme picker, Browse categories, Player picker, TV Manager, A
- **`d`**: Download HTTP stream release.
- **`r`**: Refresh addon catalog search results.
- **`f`**: Favorite / unfavorite the selected title (Home & Details screens).
-- **`s`**: Open subtitle language picker on the Details screen.
- **`/history`**: Open watch history (`Space` or `P` to instantly resume recorded episode/movie).
- **`/favorites`**: Open your starred titles.
- **`/clear`**: Clear active search query and return to landing.
diff --git a/src/cache.rs b/src/cache.rs
index dd353c8..0d99f1d 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -577,8 +577,6 @@ mod tests {
let destination = dir.join("not-a-file-target-dir");
fs::create_dir_all(&destination).expect("destination directory");
atomic_write_file(&destination.parent().unwrap().join("seed"), b"seed").ok();
- // Renaming a file onto an existing directory always fails; the
- // destination must survive untouched.
let result = atomic_write_file(&destination, b"payload");
assert!(result.is_err());
assert!(destination.is_dir(), "existing destination was destroyed");
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index e7319ed..a4f4e40 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -1059,17 +1059,6 @@ impl App {
self.action_sender.send(Action::ToggleFavorite).ok();
}
}
- KeyCode::Char('s') | KeyCode::Char('S') => {
- if !self.state.subtitle_popup
- && !self.state.player_picker_popup
- && !self.state.show_season_download_confirm
- && !self.state.show_episode_download_confirm
- && !self.state.subtitle_list.is_empty()
- {
- self.state.subtitle_popup = true;
- self.state.subtitle_list_state.select(Some(0));
- }
- }
KeyCode::Up | KeyCode::Char('k') | KeyCode::Char('K') => {
self.action_sender.send(Action::MoveUp).ok();
@@ -1305,22 +1294,4 @@ mod tests {
assert!(app.state.search_results.is_empty());
assert_eq!(app.state.search_list_state.selected(), None);
}
-
- #[tokio::test]
- async fn test_details_screen_s_key_opens_subtitles_popup() {
- let mut app = App::new();
- app.state.active_screen = crate::tui::state::Screen::Details;
- app.state.input_mode = InputMode::Normal;
- app.state.subtitle_list = vec![
- ("English".to_string(), "http://sub/en.srt".to_string()),
- ("Spanish".to_string(), "http://sub/es.srt".to_string()),
- ];
- app.state.subtitle_popup = false;
-
- app.handle_key(KeyEvent::new(KeyCode::Char('s'), KeyModifiers::empty()))
- .await;
-
- assert!(app.state.subtitle_popup);
- assert_eq!(app.state.subtitle_list_state.selected(), Some(0));
- }
}
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index c5d2387..e8689f8 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -1062,7 +1062,6 @@ impl App {
PlaySelect,
Download,
Favorite,
- Subtitles,
StreamsTab,
Back,
}
@@ -1075,10 +1074,6 @@ impl App {
let d_label_len = if compact { 4 } else { 8 };
primary.push((FooterAction::Download, 3 + 1 + d_label_len));
secondary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
- if !self.state.subtitle_list.is_empty() {
- let s_label_len = if compact { 4 } else { 9 };
- secondary.push((FooterAction::Subtitles, 3 + 1 + s_label_len));
- }
secondary.push((FooterAction::Back, 5 + 1 + 4));
} else if is_languages {
primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
@@ -1146,12 +1141,6 @@ impl App {
FooterAction::Favorite => {
self.action_sender.send(Action::ToggleFavorite).ok();
}
- FooterAction::Subtitles => {
- if !self.state.subtitle_list.is_empty() {
- self.state.subtitle_popup = true;
- self.state.subtitle_list_state.select(Some(0));
- }
- }
FooterAction::StreamsTab => {
self.action_sender.send(Action::TabPane).ok();
}
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index a33b8a3..8232303 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -2055,14 +2055,6 @@ fn details_footer(
theme,
));
secondary.extend(footer_group("f", fav_label, false, theme));
- if !state.subtitle_list.is_empty() {
- secondary.extend(footer_group(
- "s",
- if compact { "Subs" } else { "Subtitles" },
- false,
- theme,
- ));
- }
secondary.extend(footer_group("Esc", "Back", false, theme));
} else if is_languages {
primary.extend(footer_group("Enter", "Select", true, theme));
@@ -2327,7 +2319,6 @@ 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("[s] Subtitles"));
assert!(footer_text.contains("[Esc] Back"));
state.details_pane = crate::tui::state::DetailsPane::Seasons;
@@ -2397,14 +2388,11 @@ mod tests {
DetailsPane::Episodes,
];
- // Width < 85 should only return the active pane
let narrow = visible_selector_panes(&all_panes, DetailsPane::Languages, 50);
assert_eq!(narrow, vec![DetailsPane::Languages]);
let narrow_season = visible_selector_panes(&all_panes, DetailsPane::Seasons, 60);
assert_eq!(narrow_season, vec![DetailsPane::Seasons]);
-
- // Width >= 85 should return all 3 panes
let wide = visible_selector_panes(&all_panes, DetailsPane::Languages, 100);
assert_eq!(wide.len(), 3);
}
diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rs
index 31a5c74..ea5e919 100644
--- a/src/tui/screens/help.rs
+++ b/src/tui/screens/help.rs
@@ -2,250 +2,151 @@ use crate::tui::{state::AppState, theme::Theme};
use ratatui::{
Frame,
layout::{Alignment, Rect},
+ style::Modifier,
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
};
-pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
- let mode_title = if state.is_tv_mode {
- "TV Mode"
- } else if state.is_addon_mode {
- "Addon Mode"
- } else {
- "Streaming Mode"
- };
+fn help_row(key: &str, desc: &str, theme: &Theme) -> Line<'static> {
+ Line::from(vec![
+ Span::styled(
+ format!(" {:<17} ", key),
+ theme.header.add_modifier(Modifier::BOLD),
+ ),
+ Span::styled(desc.to_string(), theme.text),
+ ])
+}
+
+fn help_section_header(title: &str, theme: &Theme) -> Line<'static> {
+ Line::from(vec![Span::styled(
+ format!(" {title}"),
+ theme.title.add_modifier(Modifier::BOLD),
+ )])
+}
+
+pub fn build_help_columns(
+ state: &AppState,
+ theme: &Theme,
+) -> (Vec<Line<'static>>, Vec<Line<'static>>) {
+ let mut left = Vec::new();
+ let mut right = Vec::new();
- let mut help_text: Vec<Line> = vec![Line::from(vec![Span::styled(
- " Mode Switching & Navigation",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )])];
+ left.push(help_section_header("Navigation", theme));
+ left.push(help_row(
+ "[↑] [↓] / [k] [j]",
+ "Scroll & Navigate Lists",
+ theme,
+ ));
+ left.push(help_row(
+ "[←] [→] / [Tab]",
+ "Switch Panes / Step Grid",
+ theme,
+ ));
+ left.push(help_row("[Home] / [End]", "Top / Bottom of List", theme));
+ left.push(help_row("[PgUp] / [PgDn]", "Page Up / Down", theme));
+ left.push(help_row("[Esc] / [c]", "Back / Clear Search", theme));
+ left.push(help_row(
+ "[Ctrl+U] / [W]",
+ "Clear Line / Delete Word",
+ theme,
+ ));
+ left.push(Line::from(""));
+ if state.is_tv_mode {
+ left.push(help_section_header("TV Actions", theme));
+ left.push(help_row("[Enter]", "Play Selected Channel", theme));
+ left.push(help_row("[r]", "Reload M3U Playlists", theme));
+ left.push(help_row("/config", "Manage TV Playlists", theme));
+ left.push(help_row("/list", "Show All TV Channels", theme));
+ } else if state.is_addon_mode {
+ left.push(help_section_header("Addon Actions", theme));
+ left.push(help_row("[Enter]", "Select Title / Play Stream", theme));
+ left.push(help_row("[d]", "Download Video Stream", theme));
+ left.push(help_row("[f]", "Favorite / Unfavorite Title", theme));
+ left.push(help_row("[s]", "Subtitles Picker (Details)", theme));
+ left.push(help_row("[Ctrl+P]", "Open Addon Manager", theme));
+ left.push(help_row("[r]", "Refresh Catalog / Streams", theme));
+ } else {
+ left.push(help_section_header("Streaming Actions", theme));
+ left.push(help_row("[Enter]", "Play with Default Player", theme));
+ left.push(help_row("[d]", "Download Episode / Season", theme));
+ left.push(help_row("[f]", "Favorite / Unfavorite Title", theme));
+ left.push(help_row("[s]", "Subtitles Picker (Details)", theme));
+ left.push(help_row(
+ "[Ctrl+P]",
+ &format!("Switch Provider ({})", state.active_provider.label()),
+ theme,
+ ));
+ left.push(help_row("[r]", "Refresh Results / Streams", theme));
+ }
+ right.push(help_section_header("Content Modes", theme));
if state.streaming_enabled {
- let key = format!(" [{}]", crate::tui::text::ctrl_key("S"));
- let padded = format!("{:<19}", key);
- help_text.push(Line::from(vec![
- Span::styled(padded, theme.header),
- Span::styled("Switch to Streaming Mode", theme.text),
- ]));
+ let key = format!("[{}]", crate::tui::text::ctrl_key("S"));
+ right.push(help_row(&key, "Switch to Streaming Mode", theme));
}
if state.tv_enabled {
- let key = format!(" [{}]", crate::tui::text::ctrl_key("T"));
- let padded = format!("{:<19}", key);
- help_text.push(Line::from(vec![
- Span::styled(padded, theme.header),
- Span::styled("Switch to TV Mode", theme.text),
- ]));
+ let key = format!("[{}]", crate::tui::text::ctrl_key("T"));
+ right.push(help_row(&key, "Switch to Live TV Mode", theme));
}
if state.addons_enabled {
- let key = format!(" [{}]", crate::tui::text::ctrl_key("A"));
- let padded = format!("{:<19}", key);
- help_text.push(Line::from(vec![
- Span::styled(padded, theme.header),
- Span::styled("Switch to Addon Mode", theme.text),
- ]));
+ let key = format!("[{}]", crate::tui::text::ctrl_key("A"));
+ right.push(help_row(&key, "Switch to Addon Mode", theme));
}
+ right.push(Line::from(""));
- help_text.extend(vec![
- Line::from(vec![
- Span::styled(" [↑] / [↓] ", theme.header),
- Span::styled("Scroll Lists / Navigate", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [←] / [→] ", theme.header),
- Span::styled("Move Cursor / Switch Details Pane", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [Home] / [End] ", theme.header),
- Span::styled("Jump Start / End of List or Line", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [PgUp] / [PgDn]", theme.header),
- Span::styled("Page Up / Down in Lists", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [Tab] ", theme.header),
- Span::styled("Auto-complete / Toggle Dialog Button", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [Ctrl+U] ", theme.header),
- Span::styled("Clear Search / Input Line", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [Ctrl+W] ", theme.header),
- Span::styled("Delete Backward Word", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [c] ", theme.header),
- Span::styled("Clear Search (Normal Mode)", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [Esc] ", theme.header),
- Span::styled("Go Back / Clear Input / Dismiss", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [?] ", theme.header),
- Span::styled("Toggle Help Menu", theme.text),
- ]),
- Line::from(vec![
- Span::styled(" [q] ", theme.header),
- Span::styled("Quit Application", theme.text),
- ]),
- Line::from(vec![]),
- ]);
-
+ right.push(help_section_header("Commands & Shortcuts", theme));
+ right.push(help_row("/settings", "Preferences & Modes", theme));
if state.is_tv_mode {
- help_text.push(Line::from(vec![Span::styled(
- " TV Mode Controls",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )]));
- help_text.push(Line::from(vec![
- Span::styled(" [Enter] ", theme.header),
- Span::styled("Play Selected Channel", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [r] ", theme.header),
- Span::styled("Reload TV Playlists", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /config ", theme.header),
- Span::styled("Manage M3U Playlists", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /list ", theme.header),
- Span::styled("Show All TV Channels", theme.text),
- ]));
+ right.push(help_row("/list", "Show All TV Channels", theme));
} else if state.is_addon_mode {
- help_text.push(Line::from(vec![Span::styled(
- " Addon Mode Controls",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )]));
- help_text.push(Line::from(vec![
- Span::styled(" [Ctrl+P] ", theme.header),
- Span::styled("Open Addons Manager", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [←] [→] / [Tab]", theme.header),
- Span::styled("Switch Details Pane (Seasons/Streams)", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [d] ", theme.header),
- Span::styled("Download Video Stream", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [f] ", theme.header),
- Span::styled("Favorite / Unfavorite Title", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [s] ", theme.header),
- Span::styled("Open Subtitles Picker (Details)", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /favorites ", theme.header),
- Span::styled("Favorited Titles", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /browse ", theme.header),
- Span::styled("Browse Addon Catalogs", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /config ", theme.header),
- Span::styled("Manage Addons", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [r] ", theme.header),
- Span::styled("Refresh Catalog / Streams", theme.text),
- ]));
+ right.push(help_row("/browse", "Browse Addon Catalogs", theme));
} else {
- help_text.push(Line::from(vec![Span::styled(
- " Streaming Controls",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )]));
- help_text.push(Line::from(vec![
- Span::styled(" [Ctrl+P] ", theme.header),
- Span::styled(
- format!("Switch Provider ({})", state.active_provider.label()),
- theme.text,
- ),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [←] [→] / [Tab]", theme.header),
- Span::styled("Switch Details Pane (Audio/Seasons/Streams)", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [d] ", theme.header),
- Span::styled("Download Episode / Season Batch", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [f] ", theme.header),
- Span::styled("Favorite / Unfavorite Title", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [s] ", theme.header),
- Span::styled("Open Subtitles Picker (Details)", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /browse ", theme.header),
- Span::styled("Browse Movies & Series Categories", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /history ", theme.header),
- Span::styled("Watch History ([Space] Direct Resume)", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /favorites ", theme.header),
- Span::styled("Favorited Titles", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" [r] ", theme.header),
- Span::styled("Refresh Results / Streams", theme.text),
- ]));
+ right.push(help_row("/browse", "Browse Curated Categories", theme));
}
-
- help_text.push(Line::from(vec![]));
-
- help_text.push(Line::from(vec![Span::styled(
- " System & Commands",
- theme.header.add_modifier(ratatui::style::Modifier::BOLD),
- )]));
- help_text.push(Line::from(vec![
- Span::styled(" /settings ", theme.header),
- Span::styled("Preferences, Modes & Configuration", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /theme ", theme.header),
- Span::styled("Open Visual Theme Swatch Picker", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /clear ", theme.header),
- Span::styled("Clear Search & Return to Landing", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /exit ", theme.header),
- Span::styled("Exit Application and Return to Shell", theme.text),
- ]));
- help_text.push(Line::from(vec![
- Span::styled(" /help ", theme.header),
- Span::styled("Toggle Interactive Help Menu", theme.text),
- ]));
-
- let content_width = help_text.iter().map(Line::width).max().unwrap_or(42) as u16;
- let capacity = area.height.saturating_sub(6).max(4) as usize;
-
- let mut two_columns = area.width >= 90;
- if two_columns && capacity < help_text.len().div_ceil(2) {
- two_columns = false;
+ if !state.is_tv_mode {
+ right.push(help_row(
+ "/history",
+ "Watch History ([Space] Resume)",
+ theme,
+ ));
+ right.push(help_row("/favorites", "Starred Titles", theme));
}
+ right.push(help_row("/theme", "Visual Theme Swatches", theme));
+ right.push(help_row("/clear", "Clear Search Results", theme));
+ right.push(help_row("/exit", "Exit App ([q] / Ctrl+C)", theme));
+ right.push(help_row("[?]", "Toggle This Help Menu", theme));
- let required_lines = if two_columns {
- help_text.len().div_ceil(2)
+ (left, right)
+}
+
+pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
+ let mode_title = if state.is_tv_mode {
+ "TV Mode"
+ } else if state.is_addon_mode {
+ "Addon Mode"
} else {
- help_text.len()
+ "Streaming Mode"
};
- if required_lines > capacity && !two_columns {
- let max_scroll = help_text.len().saturating_sub(capacity);
+ let (left_col, right_col) = build_help_columns(state, theme);
+
+ let mut all_lines = left_col.clone();
+ all_lines.push(Line::from(""));
+ all_lines.extend(right_col.clone());
+
+ let left_width = left_col.iter().map(Line::width).max().unwrap_or(40);
+ let right_width = right_col.iter().map(Line::width).max().unwrap_or(40);
+ let content_width = left_width.max(right_width) as u16;
+
+ 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);
+
+ if !two_columns && all_lines.len() > capacity {
+ let max_scroll = all_lines.len().saturating_sub(capacity);
let scroll = state.help_scroll.min(max_scroll);
- let window: Vec<Line> = help_text[scroll..scroll + capacity.min(help_text.len())].to_vec();
+ let window: Vec<Line> = all_lines[scroll..scroll + capacity.min(all_lines.len())].to_vec();
let position = if max_scroll > 0 {
format!(" · {}/{scroll_max}", scroll + 1, scroll_max = max_scroll)
} else {
@@ -275,12 +176,16 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
}
let desired_width = if two_columns {
- content_width.saturating_mul(2).saturating_add(8)
+ (left_width + right_width + 8) as u16
} else {
- content_width.saturating_add(4)
+ content_width.saturating_add(6)
};
- let desired_height = required_lines as u16 + 2;
+ let desired_height = if two_columns {
+ (max_lines as u16 + 2).min(area.height.saturating_sub(2))
+ } else {
+ (all_lines.len() as u16 + 2).min(area.height.saturating_sub(2))
+ };
let popup_chunk = crate::tui::overlay::centered(area, desired_width, desired_height, 46, 120);
@@ -305,17 +210,78 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
])
.split(inner);
- let mid = help_text.len().div_ceil(2);
- let left = help_text[..mid].to_vec();
- let right = help_text[mid..].to_vec();
-
- frame.render_widget(Paragraph::new(left).alignment(Alignment::Left), chunks[0]);
- frame.render_widget(Paragraph::new(right).alignment(Alignment::Left), chunks[1]);
+ frame.render_widget(
+ Paragraph::new(left_col).alignment(Alignment::Left),
+ chunks[0],
+ );
+ frame.render_widget(
+ Paragraph::new(right_col).alignment(Alignment::Left),
+ chunks[1],
+ );
} else {
- let p = Paragraph::new(help_text)
+ let p = Paragraph::new(all_lines)
.block(block)
.alignment(Alignment::Left);
frame.render_widget(p, popup_chunk);
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_build_help_columns_streaming_mode() {
+ let state = AppState::default();
+ let theme = Theme::mocha();
+ let (left, right) = build_help_columns(&state, &theme);
+
+ let left_text = left
+ .iter()
+ .map(Line::to_string)
+ .collect::<Vec<_>>()
+ .join("\n");
+ let right_text = right
+ .iter()
+ .map(Line::to_string)
+ .collect::<Vec<_>>()
+ .join("\n");
+
+ assert!(left_text.contains("Navigation"));
+ assert!(left_text.contains("Streaming Actions"));
+ assert!(left_text.contains("Play with Default Player"));
+ assert!(left_text.contains("Download Episode / Season"));
+
+ assert!(right_text.contains("Content Modes"));
+ assert!(right_text.contains("Commands & Shortcuts"));
+ assert!(right_text.contains("/settings"));
+ assert!(right_text.contains("/exit"));
+ }
+
+ #[test]
+ fn test_help_modal_renders_two_columns_without_panic() {
+ let backend = ratatui::backend::TestBackend::new(100, 30);
+ let mut terminal = ratatui::Terminal::new(backend).unwrap();
+ let state = AppState::default();
+ let theme = Theme::mocha();
+
+ terminal
+ .draw(|frame| {
+ draw(frame, frame.area(), &state, &theme);
+ })
+ .unwrap();
+
+ let buffer = terminal.backend().buffer();
+ let content = buffer
+ .content()
+ .iter()
+ .map(|cell| cell.symbol())
+ .collect::<String>();
+
+ assert!(content.contains("Help · Streaming Mode"));
+ assert!(content.contains("Navigation"));
+ assert!(content.contains("Streaming Actions"));
+ assert!(content.contains("Commands & Shortcuts"));
+ }
+}
diff --git a/src/tui/text.rs b/src/tui/text.rs
index a8769d5..b5ae6ee 100644
--- a/src/tui/text.rs
+++ b/src/tui/text.rs
@@ -634,7 +634,6 @@ mod tests {
assert_eq!(buf.len_graphemes(), 2);
assert_eq!(buf.cursor(), 2);
- // Compound emoji with ZWJ sequence: Family (👨‍👩‍👧‍👦)
let family = "👨‍👩‍👧‍👦";
buf.insert_str(family);
assert_eq!(buf.len_graphemes(), 3);
@@ -689,17 +688,16 @@ mod tests {
buf.move_end();
assert!(!buf.delete_forwards());
assert_eq!(buf.as_str(), "abc");
-
- buf.set_cursor(1); // after 'a'
- assert!(buf.delete_backwards()); // deletes 'a'
+ buf.set_cursor(1);
+ assert!(buf.delete_backwards());
assert_eq!(buf.as_str(), "bc");
assert_eq!(buf.cursor(), 0);
- assert!(buf.delete_forwards()); // deletes 'b'
+ assert!(buf.delete_forwards());
assert_eq!(buf.as_str(), "c");
assert_eq!(buf.cursor(), 0);
- assert!(buf.delete_forwards()); // deletes 'c'
+ assert!(buf.delete_forwards());
assert_eq!(buf.as_str(), "");
assert!(buf.is_empty());
assert!(!buf.delete_forwards());
diff --git a/src/tui/theme.rs b/src/tui/theme.rs
index 59a2051..666080f 100644
--- a/src/tui/theme.rs
+++ b/src/tui/theme.rs
@@ -279,7 +279,6 @@ impl Theme {
_ => base,
}
}
- /// Returns a 3-point color swatch (Accent, Surface, Base) for a given theme name/kind.
pub fn palette_swatch_spans(theme_name: &str, basic_terminal: bool) -> Vec<Span<'static>> {
let kind = ThemeKind::parse(theme_name);
let sample = Self::from_kind(kind);