Skip to content

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

refactor(tui): streamline tv manager, modal layouts, and settings geometry

Samir Hossainscc7cf944cb88
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 82f864b..f1aac88 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,20 @@
- Bound parallel sibling provider queries in `get_ext_captions` (`src/service.rs`) with individual 8-second `tokio::time::timeout` futures, preventing single uncommunicative sibling mirrors from delaying caption availability.
- **Overview Modal Persistence Across Screen Transitions**:
- Reset `show_overview_modal` and `overview_modal_scroll` flags within `reset_transient_overlays` (`src/tui/app/tv.rs`), preventing overview backdrops from lingering across mode changes.
+- **Details Header Metadata Position Jitter**:
+ - Top-aligned metadata paragraph rendering and synopsis hitboxes in `src/tui/screens/details.rs`, preventing vertical layout jumps when stream details or synopsis text expand during background metadata fetches.
+- **TV Playlists Management Interface Streamlining**:
+ - Streamlined the TV mode playlist configuration popup to match the clean design of Addons mode, replacing noisy section headers and bracket buttons with a unified list, `✓` status indicators, dynamic auto-sizing, and a single `+ Add playlist` prompt.
+- **TV Mode Search Bar Provider Pill Removal**:
+ - Removed the redundant `[Live TV · ^T]` pill from the search input box in TV mode (`src/tui/screens/home.rs`), reclaiming search input width and keeping the search bar minimal.
+- **Maintenance Settings Menu Organization**:
+ - Reordered actions in `/settings` → Maintenance so safe diagnostic tools appear first (`Check for Updates`, `Re-check BDIX Network`), followed by cleanup actions (`Clear Disk Cache`, `Clear Watch History`), and ending with the external repository link.
+- **Settings Modal Balanced Geometry & Dynamic Height**:
+ - Auto-sized `/settings` modal height dynamically to fit the exact row count of the active category and balanced modal width to 60 columns in `src/tui/overlay.rs` and `src/tui/widgets/settings.rs`, removing the oversized right-side void and bottom blank areas while maintaining uniform margins around all borders.
+- **Modal Backdrop Dimming for Background Deck & Search**:
+ - Dimmed favorites/continue-watching card items and the search bar provider pill when modal popups (such as the provider picker) are active in `src/tui/screens/home.rs`, ensuring background elements properly recede visually.
+- **Update Check In-Flight Notification Replacement**:
+ - Replaced the in-flight `"Checking for updates"` notification toast with the final outcome toast (`Up to date` or `Update check failed`) upon completion in `src/tui/app/system.rs`, avoiding duplicate stacked update notifications.
- **Details Pane Season & Episode Mouse Hitbox Scrolling Offsets**:
- Factored `ListState::offset()` into row hitbox calculations in `src/tui/app/mouse.rs`, ensuring mouse clicks accurately select the intended season or episode row in scrolled lists.
- **Dynamic Application User-Agent Header**:
diff --git a/docs/config.md b/docs/config.md
index 0001fa3..9bcf639 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -30,7 +30,7 @@ All settings in `config.json` can be configured interactively inside the applica
- **General**: Toggle automatic update checks, choose default media player (`mpv`, `VLC`, `IINA`, `Android`), and edit download folder path.
- **Content Modes**: Toggle Streaming Mode, open the Streaming Sources selector (to enable/disable MovieBox, 4KHDHub, CircleFTP, DhakaFlix), and toggle Live TV.
- **Appearance**: Open the visual theme swatch picker to select among 6 built-in color themes.
-- **Maintenance**: Purge disk cache, clear watch history, query GitHub for release updates, open GitHub repository, and trigger a manual local network BDIX re-probe.
+- **Maintenance**: Query GitHub for release updates, trigger a manual local network BDIX re-probe, purge disk cache, clear watch history, and open the GitHub repository.
## Persisted configuration (`config.json`)
The central configuration file is located at `~/.config/moviebox-tui/config.json` (or `%APPDATA%\MovieBox-Tui\config.json` on Windows). In addition to settings toggled via `/settings`, custom player binary paths can be directly set here:
diff --git a/docs/tv-mode.md b/docs/tv-mode.md
index f18a1fc..b1cac33 100644
--- a/docs/tv-mode.md
+++ b/docs/tv-mode.md
@@ -12,9 +12,8 @@ file path, and the app parses, groups, dedupes, and lets you search and play the
## Adding playlists
-1. `/config` opens the playlist manager, split into **URL playlists** and
- **File playlists**.
-2. Select `[ Add URL ]` or `[ Add file ]`, type the source, `Enter` to add.
+1. `/config` opens the playlist manager.
+2. Select `+ Add playlist`, type the URL or local file path, `Enter` to add.
- URL example: `https://example.com/playlist.m3u`
- File example: `~/playlists/mine.m3u`
3. Sources persist in `tv_config.json` (under the config dir). Local file playlists are
diff --git a/src/providers/tv/parser.rs b/src/providers/tv/parser.rs
index abd4ece..eb8c482 100644
--- a/src/providers/tv/parser.rs
+++ b/src/providers/tv/parser.rs
@@ -30,7 +30,7 @@ impl M3UParser {
&self,
url: &str,
) -> Result<Vec<Channel>, Box<dyn std::error::Error>> {
- let trimmed = url.trim();
+ let trimmed = url.trim().trim_matches(|c| c == '"' || c == '\'').trim();
let is_remote = crate::net::is_http_url(trimmed);
let content = if is_remote {
let file_path = self.cache_dir.join(cache_filename(trimmed));
@@ -77,7 +77,18 @@ impl M3UParser {
}
}
} else {
- let path = std::path::PathBuf::from(trimmed);
+ let path = if let Some(stripped) = trimmed
+ .strip_prefix("~/")
+ .or_else(|| trimmed.strip_prefix("~\\"))
+ {
+ dirs::home_dir()
+ .map(|h| h.join(stripped))
+ .unwrap_or_else(|| std::path::PathBuf::from(trimmed))
+ } else if trimmed == "~" {
+ dirs::home_dir().unwrap_or_else(|| std::path::PathBuf::from(trimmed))
+ } else {
+ std::path::PathBuf::from(trimmed)
+ };
let metadata = tokio::fs::metadata(&path)
.await
.map_err(|error| format!("failed to read playlist file {}: {error}", trimmed))?;
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index 99135f1..be5d4bc 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -801,6 +801,9 @@ impl App {
KeyCode::PageDown => {
self.state.step_tv_manager_selected(5);
}
+ KeyCode::Char('r') => {
+ self.action_sender.send(Action::TvReloadPlaylists).ok();
+ }
KeyCode::Char('d') | KeyCode::Delete => {
use crate::tui::state::TvManagerRow;
if let Some(TvManagerRow::Playlist(index)) = self
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index d2bd947..f03c673 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -331,9 +331,12 @@ impl App {
}
fn reload_tv_playlists(&self) {
+ let Ok(handle) = tokio::runtime::Handle::try_current() else {
+ return;
+ };
let playlists = self.state.tv_playlists.clone();
let sender = self.action_sender.clone();
- tokio::spawn(async move {
+ handle.spawn(async move {
let parser = crate::providers::tv::M3UParser::new();
let mut all_channels = Vec::new();
let mut failed = 0usize;
@@ -369,20 +372,9 @@ impl App {
.send(Action::TvPlaylistRemove(index))
.ok();
}
- TvManagerRow::AddUrl => {
+ TvManagerRow::AddPlaylist => {
self.action_sender.send(Action::TvInputToggle(false)).ok();
}
- TvManagerRow::AddFile => {
- self.action_sender.send(Action::TvInputToggle(true)).ok();
- }
- TvManagerRow::Reload => {
- self.action_sender.send(Action::TvReloadPlaylists).ok();
- }
- TvManagerRow::Done => {
- self.reset_transient_overlays();
- self.state.tv_config_popup = false;
- }
- TvManagerRow::Header(_) => {}
}
}
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index 7f09081..e91042b 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -486,19 +486,10 @@ impl App {
self.state.tv_manager_selected = clicked_idx;
if let Some(r) = rows.get(clicked_idx) {
match r {
- crate::tui::state::TvManagerRow::AddUrl => {
+ crate::tui::state::TvManagerRow::AddPlaylist => {
self.action_sender.send(Action::TvInputToggle(false)).ok();
}
- crate::tui::state::TvManagerRow::AddFile => {
- self.action_sender.send(Action::TvInputToggle(true)).ok();
- }
- crate::tui::state::TvManagerRow::Reload => {
- self.action_sender.send(Action::TvReloadPlaylists).ok();
- }
- crate::tui::state::TvManagerRow::Done => {
- self.state.tv_config_popup = false;
- }
- _ => {}
+ crate::tui::state::TvManagerRow::Playlist(_) => {}
}
}
}
diff --git a/src/tui/app/search.rs b/src/tui/app/search.rs
index 2983c93..2a2376f 100644
--- a/src/tui/app/search.rs
+++ b/src/tui/app/search.rs
@@ -131,13 +131,10 @@ impl App {
{
self.action_sender.send(Action::ShowAddonManager).ok();
} else {
- let ctrl_p = crate::tui::text::CTRL_P_STR;
self.state.notify(
NotificationKind::Info,
- "Configuration",
- format!(
- "Use /settings for preferences, or switch to Addons ({ctrl_p}) to configure addons."
- ),
+ "Config",
+ "Use /settings for preferences, or switch provider.",
);
}
Some(true)
@@ -744,8 +741,8 @@ impl App {
mod tests {
use super::*;
- #[test]
- fn test_handle_search_command_config_in_streaming_mode_shows_guidance() {
+ #[tokio::test]
+ async fn test_handle_search_command_config_in_streaming_mode_shows_guidance() {
let mut app = App::new();
app.state.active_provider = ProviderKind::MovieBox;
app.state.is_tv_mode = false;
@@ -756,12 +753,12 @@ mod tests {
assert!(!app.state.addon_manager_popup);
assert!(!app.state.tv_config_popup);
assert_eq!(app.state.notifications.len(), 1);
- assert_eq!(app.state.notifications[0].title, "Configuration");
+ assert_eq!(app.state.notifications[0].title, "Config");
assert!(app.state.notifications[0].message.contains("/settings"));
}
- #[test]
- fn test_handle_search_command_config_in_addons_mode_opens_addon_manager() {
+ #[tokio::test]
+ async fn test_handle_search_command_config_in_addons_mode_opens_addon_manager() {
let mut app = App::new();
app.state.active_provider = ProviderKind::Addons;
app.state.is_tv_mode = false;
@@ -772,8 +769,8 @@ mod tests {
assert!(app.state.notifications.is_empty());
}
- #[test]
- fn test_handle_search_command_config_in_tv_mode_opens_tv_config() {
+ #[tokio::test]
+ async fn test_handle_search_command_config_in_tv_mode_opens_tv_config() {
let mut app = App::new();
app.state.is_tv_mode = true;
diff --git a/src/tui/app/system.rs b/src/tui/app/system.rs
index e188401..1065859 100644
--- a/src/tui/app/system.rs
+++ b/src/tui/app/system.rs
@@ -523,6 +523,24 @@ impl App {
crate::tui::state::SettingsCategory::StorageInfo => {
match self.state.settings_selected_row {
0 => {
+ self.state.manual_update_check = true;
+ self.state.notify(
+ NotificationKind::Info,
+ "Checking for updates",
+ "Checking GitHub releases...",
+ );
+ self.action_sender.send(Action::CheckForUpdates).ok();
+ }
+ 1 => {
+ self.state.bdix_probed = false;
+ self.action_sender.send(Action::CheckBdixNetwork).ok();
+ self.state.notify(
+ NotificationKind::Info,
+ "BDIX Check",
+ "Probing local network mirrors...",
+ );
+ }
+ 2 => {
self.state.notify(
NotificationKind::Info,
"Clearing Cache",
@@ -530,7 +548,7 @@ impl App {
);
self.action_sender.send(Action::ClearCache).ok();
}
- 1 => {
+ 3 => {
self.state.history.clear();
self.state.homepage_cache.clear();
if self
@@ -548,16 +566,7 @@ impl App {
"Watch history cleared",
);
}
- 2 => {
- self.state.manual_update_check = true;
- self.state.notify(
- NotificationKind::Info,
- "Checking for updates",
- "Checking GitHub releases...",
- );
- self.action_sender.send(Action::CheckForUpdates).ok();
- }
- 3 => {
+ 4 => {
const REPO_URL: &str = "https://github.com/mesamirh/MovieBox-Tui";
match open::that(REPO_URL) {
Ok(()) => {
@@ -577,15 +586,6 @@ impl App {
}
}
}
- 4 => {
- self.state.bdix_probed = false;
- self.action_sender.send(Action::CheckBdixNetwork).ok();
- self.state.notify(
- NotificationKind::Info,
- "BDIX Check",
- "Probing local network mirrors...",
- );
- }
_ => {}
}
}
@@ -699,6 +699,10 @@ impl App {
.as_secs();
self.persist_config();
+ self.state
+ .notifications
+ .retain(|n| !n.title.eq_ignore_ascii_case("Checking for updates"));
+
match result {
Ok(None) => {
if self.state.manual_update_check {
diff --git a/src/tui/app/tv.rs b/src/tui/app/tv.rs
index 818571a..5212505 100644
--- a/src/tui/app/tv.rs
+++ b/src/tui/app/tv.rs
@@ -166,21 +166,16 @@ impl App {
});
if self.state.tv_channels.is_empty() {
let status = if failed > 0 {
- format!(
- "No TV channels found. {failed} playlist(s) failed to load. Add a playlist (/config)."
- )
+ format!("No channels. {failed} failed. Add playlist (/config).")
} else {
- "No TV channels found. Add a playlist (/config).".to_string()
+ "No channels. Add playlist (/config).".to_string()
};
self.state.set_status_long(status);
} else {
- let mut status = format!(
- "{} TV channels imported from {} playlist(s).",
- self.state.tv_channels.len(),
- self.state.tv_playlists.len().max(1)
- );
+ let count = self.state.tv_channels.len();
+ let mut status = format!("{count} channels loaded.");
if failed > 0 {
- status.push_str(&format!(" {failed} playlist(s) failed to load."));
+ status.push_str(&format!(" {failed} failed."));
}
self.state.set_status_long(status);
}
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index 66f845f..68eaf39 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -105,20 +105,20 @@ pub fn tv_config_layout(
total_rows: usize,
input_active: bool,
) -> Rect {
- let content_width = longest_source_width.max(48).max(crate::tui::text::width(
- "[ Add URL ] [ Add file ] [ Reload ] [ Done ]",
- ));
- let min_width = 44u16.min(area.width.saturating_sub(2));
- let popup_width = 68u16
- .max(content_width.saturating_add(6) as u16)
- .min(area.width.saturating_sub(2))
- .max(min_width);
- let popup_height = if input_active {
- 5u16
+ let (popup_width, popup_height) = if input_active {
+ let w = 52u16.min(area.width.saturating_sub(2)).max(28);
+ (w, 5u16)
} else {
- (total_rows.min(10) as u16)
- .saturating_add(4)
+ let longest_line = (longest_source_width as u16).saturating_add(6).max(24);
+ let w = longest_line
+ .saturating_add(2)
+ .min(area.width.saturating_sub(2))
+ .max(28);
+ let h = (total_rows as u16)
+ .saturating_add(2)
.min(area.height.saturating_sub(2))
+ .max(3);
+ (w, h)
};
let available_width = area.width.saturating_sub(2).max(1);
let width = popup_width.min(available_width);
@@ -160,8 +160,8 @@ pub fn addon_manager_layout(
pub fn settings_modal_layout(area: Rect, category: crate::tui::state::SettingsCategory) -> Rect {
let min_width = 44u16.min(area.width.saturating_sub(2));
- let popup_width = 68u16.min(area.width.saturating_sub(2)).max(min_width);
- let content_height = (category.row_count() as u16).max(5);
+ let popup_width = 58u16.min(area.width.saturating_sub(2)).max(min_width);
+ let content_height = category.row_count() as u16;
let popup_height = (content_height + 4).min(area.height.saturating_sub(2));
let available_width = area.width.saturating_sub(2).max(1);
let width = popup_width.min(available_width);
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 1172852..24df18c 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -320,10 +320,7 @@ fn compute_synopsis_area(
return Rect::default();
}
- let rendered_count =
- fixed_lines + if include_spacer { 1 } else { 0 } + actual_synopsis_lines + reserved_bottom;
- let top_offset = total_height.saturating_sub(rendered_count) / 2;
- let synopsis_rel_y = top_offset + fixed_lines + if include_spacer { 1 } else { 0 };
+ let synopsis_rel_y = fixed_lines + if include_spacer { 1 } else { 0 };
let abs_y = meta_area.y + synopsis_rel_y as u16;
let height = actual_synopsis_lines as u16;
@@ -838,21 +835,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
rendered_lines.push(Line::from(extra_meta_spans));
}
- let top_offset = total_height.saturating_sub(rendered_lines.len()) / 2;
- let final_lines = if top_offset > 0 {
- let mut padded = Vec::with_capacity(total_height);
- for _ in 0..top_offset {
- padded.push(Line::from(""));
- }
- padded.extend(rendered_lines);
- padded
- } else {
- rendered_lines
- };
-
- let meta_p = Paragraph::new(final_lines);
+ let meta_p = Paragraph::new(rendered_lines);
frame.render_widget(meta_p, meta_area);
-
let streams_count = state.selected_resources.len();
render_workflow(
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 98de896..42e7a8a 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -605,11 +605,21 @@ pub(crate) fn render_landing_deck(frame: &mut Frame, area: Rect, state: &AppStat
let pad_len = (inner_area.width as usize)
.saturating_sub(margins_len + hl_sym_len + title_width + tag_len);
+ let title_style = if modal_active {
+ theme.muted
+ } else {
+ theme.text
+ };
+ let tag_style = if modal_active {
+ theme.muted
+ } else {
+ theme.text_dim
+ };
let line = Line::from(vec![
Span::raw(left_margin),
- Span::styled(truncated_title, theme.text),
+ Span::styled(truncated_title, title_style),
Span::raw(" ".repeat(pad_len)),
- Span::styled(right_tag, theme.text_dim),
+ Span::styled(right_tag, tag_style),
Span::raw(right_margin),
]);
ListItem::new(line)
@@ -640,11 +650,21 @@ pub(crate) fn render_landing_deck(frame: &mut Frame, area: Rect, state: &AppStat
let pad_len = (inner_area.width as usize)
.saturating_sub(margins_len + hl_sym_len + title_width + tag_len);
+ let title_style = if modal_active {
+ theme.muted
+ } else {
+ theme.text
+ };
+ let tag_style = if modal_active {
+ theme.muted
+ } else {
+ theme.text_dim
+ };
let line = Line::from(vec![
Span::raw(left_margin),
- Span::styled(truncated_title, theme.text),
+ Span::styled(truncated_title, title_style),
Span::raw(" ".repeat(pad_len)),
- Span::styled(right_tag, theme.text_dim),
+ Span::styled(right_tag, tag_style),
Span::raw(right_margin),
]);
ListItem::new(line)
@@ -866,11 +886,6 @@ fn render_search_bar(
} else {
crate::tui::text::CTRL_P_STR
};
- let ctrl_t = if is_ultra_compact {
- "T"
- } else {
- crate::tui::text::CTRL_T_STR
- };
let is_query_empty = state.search_query.is_empty();
let (pill_text, pill_style) = if state.show_provider_popup {
@@ -882,11 +897,9 @@ fn render_search_bar(
format!("[{label} {sep} {ctrl_p}]")
};
let style = if state.basic_terminal {
- theme.sapphire.add_modifier(Modifier::BOLD)
+ theme.muted
} else {
- let bg = theme.surface1_color();
- let fg = theme.sapphire.fg.unwrap_or(theme.base);
- Style::default().bg(bg).fg(fg).add_modifier(Modifier::BOLD)
+ theme.muted.add_modifier(Modifier::BOLD)
};
(text, style)
} else if modal_active {
@@ -897,12 +910,7 @@ fn render_search_bar(
"[Enter] Search".to_string()
}
} else if state.is_tv_mode {
- if is_ultra_compact {
- "[TV]".to_string()
- } else {
- let sep = if state.basic_terminal { "-" } else { "·" };
- format!("[Live TV {sep} {ctrl_t}]")
- }
+ String::new()
} else if state.active_provider == crate::providers::models::ProviderKind::Addons {
"[Addons]".to_string()
} else {
@@ -924,18 +932,7 @@ fn render_search_bar(
("[Enter] Search".to_string(), theme.accent)
}
} else if state.is_tv_mode {
- let text = if is_ultra_compact {
- "[TV]".to_string()
- } else {
- let sep = if state.basic_terminal { "-" } else { "·" };
- format!("[Live TV {sep} {ctrl_t}]")
- };
- let style = if state.basic_terminal {
- theme.lavender
- } else {
- theme.lavender.add_modifier(Modifier::BOLD)
- };
- (text, style)
+ (String::new(), Style::default())
} else if state.active_provider == crate::providers::models::ProviderKind::Addons {
let text = "[Addons]".to_string();
let style = if state.basic_terminal {
@@ -986,7 +983,7 @@ fn render_search_bar(
let editing = view == SearchViewState::Editing;
let real_cursor = editing && !state.basic_terminal && !modal_active;
let prefix_style = if modal_active {
- theme.text_dim
+ theme.muted
} else if editing {
theme.accent
} else {
@@ -1008,19 +1005,29 @@ fn render_search_bar(
let search_line = if is_query_empty {
let placeholder_text: &str = placeholder_text.as_ref();
if has_status {
+ let status_style = if modal_active {
+ theme.muted
+ } else {
+ theme.accent
+ };
Line::from(vec![
Span::styled(prefix, prefix_style),
- Span::styled(placeholder_text, theme.accent),
+ Span::styled(placeholder_text, status_style),
])
} else {
+ let placeholder_style = if modal_active {
+ theme.muted
+ } else {
+ theme.text_dim
+ };
Line::from(vec![
Span::styled(prefix, prefix_style),
- Span::styled(placeholder_text, theme.text_dim),
+ Span::styled(placeholder_text, placeholder_style),
])
}
} else {
let text_style = if modal_active {
- theme.text_dim
+ theme.muted
} else {
theme.text
};
@@ -1905,85 +1912,73 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
total_rows,
state.tv_input_active,
);
- let title = format!(
- "TV Playlists · {}/{}",
- state.tv_manager_selected.saturating_add(1),
- total_rows.max(1)
- );
- let inner_area = crate::tui::widgets::ModalFrame::new(&title, theme, state.basic_terminal)
+ let title = if state.tv_input_active {
+ "Add TV Playlist"
+ } else {
+ "TV Playlists"
+ };
+ let inner_area = crate::tui::widgets::ModalFrame::new(title, theme, state.basic_terminal)
.render(frame, popup_area, area);
if state.tv_input_active {
- let label = if state.tv_input_is_file {
- "Enter playlist file path:"
- } else {
- "Enter playlist URL:"
- };
crate::tui::widgets::render_single_line_input(
frame,
inner_area,
- label,
+ "Enter playlist URL or file path:",
&state.tv_input_buffer,
theme,
state.basic_terminal,
);
} else {
- let items: Vec<ratatui::widgets::ListItem> = rows
- .iter()
- .map(|row| {
- use crate::tui::state::TvManagerRow;
- match row {
- TvManagerRow::Header(label) => {
- ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled(label.to_string(), theme.muted),
- ]))
- }
- TvManagerRow::Playlist(index) => {
- let source =
- state.tv_playlists.get(*index).cloned().unwrap_or_default();
- 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_str, display_source),
- theme.text,
- ),
- ]))
- }
- TvManagerRow::AddUrl => {
- ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled("[ Add URL ]", theme.sapphire),
- ]))
- }
- TvManagerRow::AddFile => {
- ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled("[ Add file ]", theme.sapphire),
- ]))
- }
- TvManagerRow::Reload => {
- ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled("[ Reload ]", theme.rating),
- ]))
- }
- TvManagerRow::Done => {
- ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled("[ Done ]", theme.success),
- ]))
- }
- }
- })
- .collect();
+ let mut items = Vec::with_capacity(state.tv_playlists.len() + 1);
+
+ for (idx, source) in state.tv_playlists.iter().enumerate() {
+ let is_selected = state.tv_manager_selected == idx;
+ let (prefix, prefix_style) = if state.basic_terminal {
+ (
+ "* ",
+ theme.success.add_modifier(ratatui::style::Modifier::BOLD),
+ )
+ } else {
+ (
+ "✓ ",
+ theme.success.add_modifier(ratatui::style::Modifier::BOLD),
+ )
+ };
+ let name_style = if is_selected {
+ theme.text.add_modifier(ratatui::style::Modifier::BOLD)
+ } else {
+ theme.text
+ };
+ let name_budget = (inner_area.width as usize).saturating_sub(6).max(8);
+ let truncated = crate::tui::text::truncate_middle_width(source, name_budget);
+ let item = ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
+ ratatui::text::Span::raw(" "),
+ ratatui::text::Span::styled(prefix, prefix_style),
+ ratatui::text::Span::styled(truncated, name_style),
+ ratatui::text::Span::raw(" "),
+ ]));
+ items.push(item);
+ }
+ let is_add_selected = state.tv_manager_selected == state.tv_playlists.len();
+ let add_style = if is_add_selected {
+ theme.text.add_modifier(ratatui::style::Modifier::BOLD)
+ } else {
+ theme.sapphire
+ };
+ let add_prefix_style = if is_add_selected {
+ theme.text.add_modifier(ratatui::style::Modifier::BOLD)
+ } else {
+ theme.sapphire
+ };
+ let add_item = ratatui::widgets::ListItem::new(ratatui::text::Line::from(vec![
+ ratatui::text::Span::raw(" "),
+ ratatui::text::Span::styled("+ ", add_prefix_style),
+ ratatui::text::Span::styled("Add playlist", add_style),
+ ratatui::text::Span::raw(" "),
+ ]));
+ items.push(add_item);
let list = ratatui::widgets::List::new(items)
.highlight_style(crate::tui::overlay::selection_style(
theme,
@@ -2362,18 +2357,9 @@ pub fn search_bar_provider_pill_rect(search_card_area: Rect, state: &AppState) -
} else {
crate::tui::text::CTRL_P_STR
};
- let ctrl_t = if is_ultra_compact {
- "T"
- } else {
- crate::tui::text::CTRL_T_STR
- };
let sep = if state.basic_terminal { "-" } else { "·" };
let pill_text = if state.is_tv_mode {
- if is_ultra_compact {
- "[TV]".to_string()
- } else {
- format!("[Live TV {sep} {ctrl_t}]")
- }
+ String::new()
} else if state.active_provider == crate::providers::models::ProviderKind::Addons {
"[Addons]".to_string()
} else {
@@ -2385,6 +2371,9 @@ pub fn search_bar_provider_pill_rect(search_card_area: Rect, state: &AppState) -
}
};
let pill_width = crate::tui::text::width(&pill_text) as u16;
+ if pill_width == 0 {
+ return Rect::default();
+ }
let search_split = Layout::default()
.direction(Direction::Horizontal)
.constraints([
@@ -3432,7 +3421,7 @@ mod tests {
}
tv_rendered.push('\n');
}
- assert!(tv_rendered.contains("[Live TV"));
+ assert!(!tv_rendered.contains("[Live TV"));
assert!(tv_rendered.contains("Search live TV channels…"));
let mut addon_state = AppState {
active_provider: crate::providers::models::ProviderKind::Addons,
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 8b5ca06..dd15f3b 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -1151,12 +1151,8 @@ pub fn step_list_selection(state: &mut ListState, total_items: usize, step: isiz
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TvManagerRow {
- Header(&'static str),
Playlist(usize),
- AddUrl,
- AddFile,
- Reload,
- Done,
+ AddPlaylist,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -1164,112 +1160,38 @@ pub enum AddonManagerRow {
Addon(usize),
AddUrl,
}
-pub fn step_header_aware_list<F>(current: usize, total: usize, step: isize, is_header: F) -> usize
-where
- F: Fn(usize) -> bool,
-{
- if total == 0 {
- return 0;
- }
- if step == 0 {
- return current;
- }
-
- if step < -1 {
- let jump = (-step) as usize;
- let mut target = current.saturating_sub(jump);
- while target > 0 && is_header(target) {
- target = target.saturating_sub(1);
- }
- if is_header(target) {
- if let Some(first_valid) = (0..total).find(|&i| !is_header(i)) {
- target = first_valid;
- }
- }
- return target;
- } else if step > 1 {
- let jump = step as usize;
- let mut target = (current + jump).min(total.saturating_sub(1));
- while target < total && is_header(target) {
- target += 1;
- }
- if target >= total || is_header(target) {
- if let Some(last_valid) = (0..total).rposition(|i| !is_header(i)) {
- target = last_valid;
- }
- }
- return target;
- }
-
- let forward = step > 0;
- let mut next = if forward {
- if current + 1 >= total { 0 } else { current + 1 }
- } else if current == 0 {
- total.saturating_sub(1)
- } else {
- current - 1
- };
-
- while next != current && is_header(next) {
- next = if forward {
- if next + 1 >= total { 0 } else { next + 1 }
- } else if next == 0 {
- total.saturating_sub(1)
- } else {
- next - 1
- };
- }
-
- next
-}
impl AppState {
pub fn tv_manager_rows(&self) -> Vec<TvManagerRow> {
- let mut rows = vec![TvManagerRow::Header("URL playlists")];
- for (index, source) in self.tv_playlists.iter().enumerate() {
- if crate::tui::text::is_http_url(source) {
- rows.push(TvManagerRow::Playlist(index));
- }
- }
- rows.push(TvManagerRow::AddUrl);
- rows.push(TvManagerRow::Header("File playlists"));
- for (index, source) in self.tv_playlists.iter().enumerate() {
- if !crate::tui::text::is_http_url(source) {
- rows.push(TvManagerRow::Playlist(index));
- }
+ let mut rows = Vec::with_capacity(self.tv_playlists.len() + 1);
+ for index in 0..self.tv_playlists.len() {
+ rows.push(TvManagerRow::Playlist(index));
}
- rows.push(TvManagerRow::AddFile);
- rows.push(TvManagerRow::Reload);
- rows.push(TvManagerRow::Done);
+ rows.push(TvManagerRow::AddPlaylist);
rows
}
pub fn step_tv_manager_selected(&mut self, step: isize) {
- let rows = self.tv_manager_rows();
- self.tv_manager_selected =
- step_header_aware_list(self.tv_manager_selected, rows.len(), step, |idx| {
- matches!(rows.get(idx), Some(TvManagerRow::Header(_)))
- });
+ let rows_len = self.tv_manager_rows().len();
+ if rows_len == 0 {
+ self.tv_manager_selected = 0;
+ return;
+ }
+ if step > 0 {
+ self.tv_manager_selected = (self.tv_manager_selected + step as usize) % rows_len;
+ } else {
+ let back = (-step) as usize % rows_len;
+ self.tv_manager_selected = (self.tv_manager_selected + rows_len - back) % rows_len;
+ }
}
pub fn first_tv_manager_selected(&mut self) {
- let rows = self.tv_manager_rows();
- if let Some(idx) = rows
- .iter()
- .position(|r| !matches!(r, TvManagerRow::Header(_)))
- {
- self.tv_manager_selected = idx;
- }
+ self.tv_manager_selected = 0;
}
pub fn last_tv_manager_selected(&mut self) {
- let rows = self.tv_manager_rows();
- if let Some(idx) = rows
- .iter()
- .rposition(|r| !matches!(r, TvManagerRow::Header(_)))
- {
- self.tv_manager_selected = idx;
- }
+ let total = self.tv_manager_rows().len();
+ self.tv_manager_selected = total.saturating_sub(1);
}
pub fn addon_manager_rows(&self) -> Vec<AddonManagerRow> {
diff --git a/src/tui/widgets/settings.rs b/src/tui/widgets/settings.rs
index 68aae9d..25279f7 100644
--- a/src/tui/widgets/settings.rs
+++ b/src/tui/widgets/settings.rs
@@ -20,8 +20,8 @@ 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 };
+ let compact = tabs_area.width < 50;
+ let gap = if compact { 2 } else { 3 };
for cat in SettingsCategory::ALL {
let title = if compact {
@@ -156,10 +156,10 @@ fn render_tabs(frame: &mut Frame, area: Rect, popup_area: Rect, state: &AppState
let mut line0_spans = Vec::new();
let mut line1_spans = Vec::new();
- let compact = popup_area.width < 58;
+ let compact = popup_area.width < 56;
for (i, cat) in SettingsCategory::ALL.iter().enumerate() {
if i > 0 {
- let gap = if compact { " " } else { " " };
+ let gap = if compact { " " } else { " " };
line0_spans.push(Span::raw(gap));
line1_spans.push(Span::raw(gap));
}
@@ -197,7 +197,7 @@ fn render_tabs(frame: &mut Frame, area: Rect, popup_area: Rect, state: &AppState
let tabs_render_area = Rect {
x: popup_area.x + 3,
y: area.y,
- width: popup_area.width.saturating_sub(6),
+ width: popup_area.width.saturating_sub(4),
height: area.height.min(2),
};
let lines = if area.height >= 2 {
@@ -312,8 +312,8 @@ fn render_row(
.map(|s| crate::tui::text::width(&s.content))
.sum();
- let right_margin = 1;
- let left_margin = 1;
+ let right_margin = 3;
+ let left_margin = 2;
let area_width = area.width as usize;
let max_label_w = area_width.saturating_sub(left_margin + right_width + right_margin + 1);
let display_label = if label_width > max_label_w && max_label_w >= 4 {
@@ -602,30 +602,43 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
if let Some(&row_area) = row_rects.first() {
let is_selected = state.settings_selected_row == 0;
let is_active_selected = is_selected && !has_active_popup;
- let glyph = if state.basic_terminal { ">" } else { "▸" };
- let value_spans = vec![Span::styled(
- format!("Purge {glyph}"),
- if has_active_popup {
- theme.muted
- } else if state.basic_terminal {
- if is_active_selected {
- theme.text.add_modifier(Modifier::BOLD)
- } else {
+ let value_spans = if state.is_checking_updates {
+ vec![Span::styled(
+ "Checking...",
+ if has_active_popup {
+ theme.muted
+ } else if state.basic_terminal {
theme.text_dim
- }
- } else if is_active_selected {
- theme.error.add_modifier(Modifier::BOLD)
- } else {
- theme.error
- },
- )];
+ } else {
+ theme.sapphire
+ },
+ )]
+ } else {
+ let glyph = if state.basic_terminal { ">" } else { "▸" };
+ vec![Span::styled(
+ format!("Check {glyph}"),
+ if has_active_popup {
+ theme.muted
+ } else if state.basic_terminal {
+ if is_active_selected {
+ theme.text.add_modifier(Modifier::BOLD)
+ } else {
+ theme.text_dim
+ }
+ } else if is_active_selected {
+ theme.sapphire.add_modifier(Modifier::BOLD)
+ } else {
+ theme.sapphire
+ },
+ )]
+ };
render_row(
frame,
row_area,
SettingRow {
is_selected,
has_active_popup,
- label: "Clear Disk Cache",
+ label: "Check for Updates",
value_spans,
},
theme,
@@ -636,9 +649,9 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
if let Some(&row_area) = row_rects.get(1) {
let is_selected = state.settings_selected_row == 1;
let is_active_selected = is_selected && !has_active_popup;
- let glyph = if state.basic_terminal { ">" } else { "▸" };
+ let glyph = if state.basic_terminal { "->" } else { "▸" };
let value_spans = vec![Span::styled(
- format!("Clear {glyph}"),
+ format!("Run {glyph}"),
if has_active_popup {
theme.muted
} else if state.basic_terminal {
@@ -648,9 +661,9 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
theme.text_dim
}
} else if is_active_selected {
- theme.error.add_modifier(Modifier::BOLD)
+ theme.sapphire.add_modifier(Modifier::BOLD)
} else {
- theme.error
+ theme.sapphire
},
)];
render_row(
@@ -659,7 +672,7 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
SettingRow {
is_selected,
has_active_popup,
- label: "Clear Watch History",
+ label: "Re-check BDIX Network",
value_spans,
},
theme,
@@ -670,43 +683,30 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
if let Some(&row_area) = row_rects.get(2) {
let is_selected = state.settings_selected_row == 2;
let is_active_selected = is_selected && !has_active_popup;
- let value_spans = if state.is_checking_updates {
- vec![Span::styled(
- "Checking...",
- if has_active_popup {
- theme.muted
- } else if state.basic_terminal {
- theme.text_dim
- } else {
- theme.sapphire
- },
- )]
- } else {
- let glyph = if state.basic_terminal { ">" } else { "▸" };
- vec![Span::styled(
- format!("Check {glyph}"),
- if has_active_popup {
- theme.muted
- } else if state.basic_terminal {
- if is_active_selected {
- theme.text.add_modifier(Modifier::BOLD)
- } else {
- theme.text_dim
- }
- } else if is_active_selected {
- theme.sapphire.add_modifier(Modifier::BOLD)
+ let glyph = if state.basic_terminal { ">" } else { "▸" };
+ let value_spans = vec![Span::styled(
+ format!("Purge {glyph}"),
+ if has_active_popup {
+ theme.muted
+ } else if state.basic_terminal {
+ if is_active_selected {
+ theme.text.add_modifier(Modifier::BOLD)
} else {
- theme.sapphire
- },
- )]
- };
+ theme.text_dim
+ }
+ } else if is_active_selected {
+ theme.error.add_modifier(Modifier::BOLD)
+ } else {
+ theme.error
+ },
+ )];
render_row(
frame,
row_area,
SettingRow {
is_selected,
has_active_popup,
- label: "Check for Updates",
+ label: "Clear Disk Cache",
value_spans,
},
theme,
@@ -717,9 +717,9 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
if let Some(&row_area) = row_rects.get(3) {
let is_selected = state.settings_selected_row == 3;
let is_active_selected = is_selected && !has_active_popup;
- let glyph = if state.basic_terminal { "->" } else { "↗" };
+ let glyph = if state.basic_terminal { ">" } else { "▸" };
let value_spans = vec![Span::styled(
- format!("Open {glyph}"),
+ format!("Clear {glyph}"),
if has_active_popup {
theme.muted
} else if state.basic_terminal {
@@ -729,9 +729,9 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
theme.text_dim
}
} else if is_active_selected {
- theme.lavender.add_modifier(Modifier::BOLD)
+ theme.error.add_modifier(Modifier::BOLD)
} else {
- theme.lavender
+ theme.error
},
)];
render_row(
@@ -740,19 +740,20 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
SettingRow {
is_selected,
has_active_popup,
- label: "GitHub Repository",
+ label: "Clear Watch History",
value_spans,
},
theme,
state.basic_terminal,
);
}
+
if let Some(&row_area) = row_rects.get(4) {
let is_selected = state.settings_selected_row == 4;
let is_active_selected = is_selected && !has_active_popup;
- let glyph = if state.basic_terminal { "->" } else { "▸" };
+ let glyph = if state.basic_terminal { "->" } else { "↗" };
let value_spans = vec![Span::styled(
- format!("Run {glyph}"),
+ format!("Open {glyph}"),
if has_active_popup {
theme.muted
} else if state.basic_terminal {
@@ -762,9 +763,9 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
theme.text_dim
}
} else if is_active_selected {
- theme.sapphire.add_modifier(Modifier::BOLD)
+ theme.lavender.add_modifier(Modifier::BOLD)
} else {
- theme.sapphire
+ theme.lavender
},
)];
render_row(
@@ -773,7 +774,7 @@ fn render_storage_settings(frame: &mut Frame, area: Rect, state: &AppState, them
SettingRow {
is_selected,
has_active_popup,
- label: "Re-check BDIX Network",
+ label: "GitHub Repository",
value_spans,
},
theme,
diff --git a/tests/settings_hub.rs b/tests/settings_hub.rs
index 6811ba2..53fc83d 100644
--- a/tests/settings_hub.rs
+++ b/tests/settings_hub.rs
@@ -327,8 +327,7 @@ async fn test_settings_hub_clear_cache_activation_and_notification() {
))
.await;
assert_eq!(app.state().settings_category, SettingsCategory::StorageInfo);
- assert_eq!(app.state().settings_selected_row, 0);
-
+ app.state_mut().settings_selected_row = 2;
app.handle_action(Action::SettingsActivateRow).await;
let clearing = app.state().notifications.back();
assert_eq!(clearing.map(|n| n.title.as_str()), Some("Clearing Cache"));
@@ -360,7 +359,7 @@ async fn test_settings_hub_browser_open_row_activation() {
SettingsCategory::StorageInfo,
))
.await;
- app.state_mut().settings_selected_row = 3;
+ app.state_mut().settings_selected_row = 4;
app.handle_action(Action::SettingsActivateRow).await;
let notification = app.state().notifications.back();
assert!(notification.is_some());
@@ -393,7 +392,7 @@ async fn test_settings_hub_clear_watch_history_activation() {
SettingsCategory::StorageInfo,
))
.await;
- app.state_mut().settings_selected_row = 1;
+ app.state_mut().settings_selected_row = 3;
app.handle_action(Action::SettingsActivateRow).await;
assert!(app.state().history.recent.is_empty());