Skip to content

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

refactor: eliminate dead code, centralize shared utilities, and harden cross-platform spawning

Samir Hossains132f00a47f85
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 560304f..f7ef9f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,18 @@
- Added automated GitHub Actions deployment workflow (`.github/workflows/pages.yml`) publishing the documentation site to GitHub Pages on every push to `main`.
- Added documentation build integrity validation step in CI hygiene pipeline (`.github/workflows/ci.yml`).
+
+### Changed
+- **Codebase Cleanups, Dead Code Removal & Shared Logic Centralization**:
+ - Removed obsolete compatibility forwarders and dead code (`render_favorites_landing`, `remove_last_grapheme`, `pad_to_width`, `ctrl_key`, and unused shortcut constants).
+ - Centralized `theme_color` in `src/tui/theme.rs`, eliminating duplicate definitions across widgets and screens.
+ - Centralized favorite status lookups for active details into `AppState::is_selected_details_favorited`, unifying 30-line duplicate calculations in details screen rendering and mouse hitbox detection.
+ - Unified subtitle picker label formatting (`"None"` -> `"No subtitles"`, language sanitization) into `format_subtitle_label`.
+ - Consolidated details pane border, title, and selection styling through `pane_styles`, eliminating over 50 lines of duplicate style branching.
+ - Streamlined details footer action definitions into declarative primary/secondary group builders, cutting redundant code blocks while preserving exact keybindings and layout.
+ - Hardened cross-platform process spawning by unifying the Windows `CREATE_NO_WINDOW` (`0x08000000`) flag into a canonical constant in `player.rs`.
+ - Decoupled network URL validation by moving `is_http_url` to `crate::net`, eliminating backend network provider dependencies on the TUI text formatting module.
+
### Fixed
- **Global Modal Background Unfocus & Dimming**:
- Automatically unfocused and dimmed all background components across Details, Home, and Runner views whenever any modal or popup dialog is active, replacing bright active borders, focus bullets, and selection highlight rectangles with dimmed styling (`theme.muted`).
diff --git a/docs/architecture.md b/docs/architecture.md
index 3a690f1..99444cd 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -19,6 +19,7 @@ src/
logging.rs file logging (rotation, sanitization)
models.rs shared domain models (SearchResult, BrowseMetrics, StreamPool,
Notification, SubjectIdentity)
+ net.rs fallback DNS resolution, HTTP client builder, URL validation
player.rs player detection (OnceLock) and command construction (mpv/VLC/IINA/Android)
providers/
mod.rs provider module tree
diff --git a/docs/cross-platform.md b/docs/cross-platform.md
index 0382580..193fffe 100644
--- a/docs/cross-platform.md
+++ b/docs/cross-platform.md
@@ -13,7 +13,7 @@ the release checks in [`release-checklist.md`](release-checklist.md).
| Platform | Notes |
| :--- | :--- |
| macOS | IINA preferred player (via the installed IINA `iina-cli`); VLC/mpv `.app` paths detected. `process_group(0)` on spawn. |
-| Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries; handle-safe atomic download replacement (dropping file handles before renames); background update helper spawned with `CREATE_NO_WINDOW` (`0x08000000`). |
+| Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries; handle-safe atomic download replacement (dropping file handles before renames); background process spawning (registry queries, yt-dlp downloader, and update helper) hardened with canonical `CREATE_NO_WINDOW` (`0x08000000`). |
| Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. |
| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution. Android playback delegates to external video players (VLC for Android, Just Player, MX Player, MPV Android) via Termux intent dispatchers (`termux-open`, `termux-open-url`, `termux-am`), requiring `pkg install -y termux-tools termux-am`. To protect against Android 10+ SELinux execute restrictions (exit code 126), system `/system/bin/am` fallbacks are strictly avoided in Termux; `LD_PRELOAD` is preserved for Termux applets while `PATH` is sanitized for system calls. Android intent playback supports unauthenticated streams (CircleFTP, DhakaFlix, IPTV) and standard CDN streams (4KHDHub). Real-device chooser behavior is a release prerequisite. |
diff --git a/src/net.rs b/src/net.rs
index dca441a..c4fc2da 100644
--- a/src/net.rs
+++ b/src/net.rs
@@ -74,6 +74,11 @@ pub fn http_client_builder() -> reqwest::ClientBuilder {
.pool_max_idle_per_host(8)
}
+pub fn is_http_url(source: &str) -> bool {
+ let trimmed = source.trim();
+ trimmed.starts_with("http://") || trimmed.starts_with("https://")
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -116,4 +121,13 @@ mod tests {
let _clone = original.clone();
let _builder = http_client_builder();
}
+ #[test]
+ fn test_is_http_url() {
+ assert!(is_http_url("http://example.com"));
+ assert!(is_http_url("https://example.com/playlist.m3u8"));
+ assert!(is_http_url(" https://example.com "));
+ assert!(!is_http_url("/local/path/file.m3u"));
+ assert!(!is_http_url("stremio://addon.example.com"));
+ assert!(!is_http_url(""));
+ }
}
diff --git a/src/player.rs b/src/player.rs
index 643d816..5b38f83 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -2,6 +2,8 @@ pub mod tracker;
use std::{path::Path, process::Command};
+pub const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlayerKind {
Mpv,
@@ -589,7 +591,7 @@ fn query_windows_registry_value(key: &str, value_name: Option<&str>) -> Option<S
} else {
cmd.arg("/ve");
}
- cmd.creation_flags(0x08000000);
+ cmd.creation_flags(CREATE_NO_WINDOW);
let output = cmd.output().ok()?;
if !output.status.success() {
@@ -1523,4 +1525,8 @@ mod tests {
.any(|c| c.contains("C:") && c.contains("vlc.exe"))
);
}
+ #[test]
+ fn test_create_no_window_constant() {
+ assert_eq!(CREATE_NO_WINDOW, 0x0800_0000);
+ }
}
diff --git a/src/providers/addons/adapter.rs b/src/providers/addons/adapter.rs
index 3fb4736..daf3d03 100644
--- a/src/providers/addons/adapter.rs
+++ b/src/providers/addons/adapter.rs
@@ -524,7 +524,7 @@ pub fn stream_item_to_release(
episode: usize,
) -> Option<Release> {
let url = stream.url.as_ref()?.trim();
- if !crate::tui::text::is_http_url(url) {
+ if !crate::net::is_http_url(url) {
return None;
}
diff --git a/src/providers/addons/client.rs b/src/providers/addons/client.rs
index 995a5c4..d69da18 100644
--- a/src/providers/addons/client.rs
+++ b/src/providers/addons/client.rs
@@ -28,7 +28,7 @@ impl AddonClient {
let mut url = raw.trim().to_string();
if url.starts_with("stremio://") {
url = format!("https://{}", &url["stremio://".len()..]);
- } else if !crate::tui::text::is_http_url(&url) {
+ } else if !crate::net::is_http_url(&url) {
url = format!("https://{url}");
}
if !url.ends_with("/manifest.json") && !url.contains("/manifest.json?") {
diff --git a/src/providers/tv/parser.rs b/src/providers/tv/parser.rs
index 8ce6657..ed98608 100644
--- a/src/providers/tv/parser.rs
+++ b/src/providers/tv/parser.rs
@@ -30,7 +30,7 @@ impl M3UParser {
url: &str,
) -> Result<Vec<Channel>, Box<dyn std::error::Error>> {
let trimmed = url.trim();
- let is_remote = crate::tui::text::is_http_url(trimmed);
+ let is_remote = crate::net::is_http_url(trimmed);
let content = if is_remote {
let file_path = self.cache_dir.join(cache_filename(trimmed));
let mut needs_download = true;
diff --git a/src/tui/app/download.rs b/src/tui/app/download.rs
index 08bf670..b98c16c 100644
--- a/src/tui/app/download.rs
+++ b/src/tui/app/download.rs
@@ -251,7 +251,7 @@ impl App {
.arg(&link);
#[cfg(target_os = "windows")]
{
- cmd.creation_flags(0x08000000);
+ cmd.creation_flags(crate::player::CREATE_NO_WINDOW);
}
cmd.stdout(std::process::Stdio::piped());
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index 16578ac..07bdd3b 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -34,7 +34,7 @@ impl App {
self.action_sender.send(Action::Quit).ok();
return None;
}
- if !self.has_active_modal() {
+ if !self.state.has_active_modal() {
if let KeyCode::Char('t') = key.code {
if self.state.tv_enabled {
self.action_sender.send(Action::ToggleTvMode).ok();
@@ -82,7 +82,7 @@ impl App {
&& self.state.input_mode != InputMode::Editing
&& !self.state.tv_input_active
&& !self.state.addon_input_active
- && !self.has_active_modal()
+ && !self.state.has_active_modal()
{
self.action_sender.send(Action::CancelDownload).ok();
return None;
@@ -1205,10 +1205,6 @@ impl App {
}
None
}
-
- fn has_active_modal(&self) -> bool {
- self.state.has_active_modal()
- }
}
#[cfg(test)]
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index 6f8b8dd..53a5022 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -281,13 +281,7 @@ impl App {
.state
.subtitle_list
.iter()
- .map(|(name, _)| {
- if name == "None" {
- "No subtitles".to_string()
- } else {
- crate::tui::text::sanitize_language_label(name)
- }
- })
+ .map(|(name, _)| crate::tui::text::format_subtitle_label(name))
.collect::<Vec<_>>();
let confirm_label = if self.state.is_download_subtitle_popup {
"Download"
@@ -1149,30 +1143,7 @@ impl App {
let is_languages = self.state.details_pane == DetailsPane::Languages;
let compact = width < crate::tui::screens::details::DETAILS_FOOTER_SPLIT_THRESHOLD;
- let is_favorited = if let Some(details) = &self.state.selected_details {
- let details_subject_id = self.state.active_subject_id.as_deref().unwrap_or("");
- let title = &details.title;
- let type_val = if details.is_series() { 2 } else { 1 };
- let year = details.year.as_deref().unwrap_or("N/A");
- let provider = self
- .state
- .search_results
- .iter()
- .find(|r| r.id == details_subject_id)
- .map(|r| r.provider)
- .unwrap_or(self.state.active_provider);
- self.state
- .favorites
- .is_favorite(&crate::models::SubjectIdentity {
- provider: provider.cache_key(),
- subject_id: details_subject_id,
- title,
- stype: type_val,
- release_year: year,
- })
- } else {
- false
- };
+ let is_favorited = self.state.is_selected_details_favorited();
let fav_label_len = if is_favorited { 10 } else { 8 };
enum FooterAction {
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index b223ba2..b846dcc 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -969,13 +969,7 @@ impl App {
.state
.subtitle_list
.iter()
- .map(|(name, _)| {
- if name == "None" {
- "No subtitles".to_string()
- } else {
- crate::tui::text::sanitize_language_label(name)
- }
- })
+ .map(|(name, _)| crate::tui::text::format_subtitle_label(name))
.collect::<Vec<_>>();
let confirm_label = if self.state.is_download_subtitle_popup {
"Download"
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 05e7101..09faa01 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -3,7 +3,10 @@ pub(crate) use crate::tui::widgets::{
extract_media_tags, loading_spinner as stream_loading_spinner, render_poster_placeholder,
resolution_badge_spans,
};
-use crate::tui::{state::AppState, theme::Theme};
+use crate::tui::{
+ state::AppState,
+ theme::{Theme, theme_color},
+};
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Layout, Rect},
@@ -813,30 +816,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let language_focused =
!modal_active && state.details_pane == crate::tui::state::DetailsPane::Languages;
- let lang_border = if modal_active {
- theme.muted
- } else if language_focused {
- focused_border_style(theme)
- } else {
- unfocused_border_style(theme)
- };
- let lang_title_style = if modal_active {
- theme.muted
- } else if language_focused {
- focused_title_style(theme)
- } else {
- unfocused_title_style(theme)
- };
- let lang_highlight_style = if modal_active {
- theme.muted
- } else {
- selection_style(language_focused, state.basic_terminal, theme)
- };
- let lang_highlight_symbol = if modal_active {
- " "
- } else {
- selection_symbol(language_focused, state.basic_terminal)
- };
+ let (lang_border, lang_title_style, lang_highlight_style, lang_highlight_symbol) =
+ pane_styles(language_focused, modal_active, state.basic_terminal, theme);
let lang_list = List::new(lang_items)
.block(
Block::default()
@@ -881,30 +862,12 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let seasons_focused =
!modal_active && state.details_pane == crate::tui::state::DetailsPane::Seasons;
- let seasons_border = if modal_active {
- theme.muted
- } else if seasons_focused {
- focused_border_style(theme)
- } else {
- unfocused_border_style(theme)
- };
- let seasons_title_style = if modal_active {
- theme.muted
- } else if seasons_focused {
- focused_title_style(theme)
- } else {
- unfocused_title_style(theme)
- };
- let seasons_highlight_style = if modal_active {
- theme.muted
- } else {
- selection_style(seasons_focused, state.basic_terminal, theme)
- };
- let seasons_highlight_symbol = if modal_active {
- " "
- } else {
- selection_symbol(seasons_focused, state.basic_terminal)
- };
+ let (
+ seasons_border,
+ seasons_title_style,
+ seasons_highlight_style,
+ seasons_highlight_symbol,
+ ) = pane_styles(seasons_focused, modal_active, state.basic_terminal, theme);
let seasons_list = List::new(seasons_items)
.block(
Block::default()
@@ -1010,30 +973,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let episodes_focused =
!modal_active && state.details_pane == crate::tui::state::DetailsPane::Episodes;
- let eps_border = if modal_active {
- theme.muted
- } else if episodes_focused {
- focused_border_style(theme)
- } else {
- unfocused_border_style(theme)
- };
- let eps_title_style = if modal_active {
- theme.muted
- } else if episodes_focused {
- focused_title_style(theme)
- } else {
- unfocused_title_style(theme)
- };
- let eps_highlight_style = if modal_active {
- theme.muted
- } else {
- selection_style(episodes_focused, state.basic_terminal, theme)
- };
- let eps_highlight_symbol = if modal_active {
- " "
- } else {
- selection_symbol(episodes_focused, state.basic_terminal)
- };
+ let (eps_border, eps_title_style, eps_highlight_style, eps_highlight_symbol) =
+ pane_styles(episodes_focused, modal_active, state.basic_terminal, theme);
let eps_list = List::new(ep_items)
.block(
Block::default()
@@ -1074,13 +1015,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let streams_focused =
!modal_active && state.details_pane == crate::tui::state::DetailsPane::Streams;
- let streams_border = if modal_active {
- theme.muted
- } else if streams_focused {
- focused_border_style(theme)
- } else {
- unfocused_border_style(theme)
- };
+ let (streams_border, streams_title_style, streams_highlight_style, streams_highlight_symbol) =
+ pane_styles(streams_focused, modal_active, state.basic_terminal, theme);
let list = &state.selected_resources;
let visible_count = list.len();
@@ -1125,13 +1061,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.borders(Borders::ALL)
.border_type(crate::tui::overlay::border_type(state.basic_terminal))
.title(ratatui::text::Line::from(streams_title).alignment(Alignment::Left))
- .title_style(if modal_active {
- theme.muted
- } else if streams_focused {
- focused_title_style(theme)
- } else {
- unfocused_title_style(theme)
- })
+ .title_style(streams_title_style)
.border_style(streams_border)
.padding(ratatui::widgets::Padding::horizontal(1));
@@ -1294,16 +1224,6 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
stream_chunks[0],
);
- let streams_highlight_style = if modal_active {
- theme.muted
- } else {
- selection_style(streams_focused, state.basic_terminal, theme)
- };
- let streams_highlight_symbol = if modal_active {
- " "
- } else {
- selection_symbol(streams_focused, state.basic_terminal)
- };
let streams_list = List::new(list_items.clone())
.highlight_style(streams_highlight_style)
.highlight_symbol(streams_highlight_symbol);
@@ -1314,16 +1234,6 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
&mut state.resource_list_state,
);
} else {
- let streams_highlight_style = if modal_active {
- theme.muted
- } else {
- selection_style(streams_focused, state.basic_terminal, theme)
- };
- let streams_highlight_symbol = if modal_active {
- " "
- } else {
- selection_symbol(streams_focused, state.basic_terminal)
- };
let streams_list = List::new(list_items)
.highlight_style(streams_highlight_style)
.highlight_symbol(streams_highlight_symbol);
@@ -1671,10 +1581,6 @@ fn pane_title(
Line::from(title)
}
-fn theme_color(style: Style, fallback: ratatui::style::Color) -> ratatui::style::Color {
- style.fg.unwrap_or(fallback)
-}
-
fn focused_border_style(theme: &Theme) -> Style {
theme.lavender
}
@@ -1691,6 +1597,32 @@ fn unfocused_title_style(theme: &Theme) -> Style {
theme.subtext1
}
+fn pane_styles(
+ focused: bool,
+ modal_active: bool,
+ basic_terminal: bool,
+ theme: &Theme,
+) -> (Style, Style, Style, &'static str) {
+ if modal_active {
+ (theme.muted, theme.muted, theme.muted, " ")
+ } else {
+ (
+ if focused {
+ focused_border_style(theme)
+ } else {
+ unfocused_border_style(theme)
+ },
+ if focused {
+ focused_title_style(theme)
+ } else {
+ unfocused_title_style(theme)
+ },
+ selection_style(focused, basic_terminal, theme),
+ selection_symbol(focused, basic_terminal),
+ )
+ }
+}
+
fn metadata_style(theme: &Theme) -> Style {
theme.subtext1
}
@@ -1923,27 +1855,10 @@ fn details_footer(
) -> (Vec<Span<'static>>, Vec<Span<'static>>) {
let compact = width < DETAILS_FOOTER_SPLIT_THRESHOLD;
let is_streams = state.details_pane == crate::tui::state::DetailsPane::Streams;
- let is_languages = state.details_pane == crate::tui::state::DetailsPane::Languages;
let is_seasons = state.details_pane == crate::tui::state::DetailsPane::Seasons;
let is_episodes = state.details_pane == crate::tui::state::DetailsPane::Episodes;
- let is_favorited = if let Some(details) = &state.selected_details {
- let details_subject_id = state.active_subject_id.as_deref().unwrap_or("");
- let title = &details.title;
- let type_val = if details.is_series() { 2 } else { 1 };
- let year = details.year.as_deref().unwrap_or("N/A");
- state
- .favorites
- .is_favorite(&crate::models::SubjectIdentity {
- provider: state.provider_for_subject(details_subject_id).cache_key(),
- subject_id: details_subject_id,
- title,
- stype: type_val,
- release_year: year,
- })
- } else {
- false
- };
+ let is_favorited = state.is_selected_details_favorited();
let fav_label = if is_favorited {
"Unfavorite"
} else {
@@ -1955,108 +1870,49 @@ fn details_footer(
.as_ref()
.is_some_and(|d| d.id.provider == crate::providers::ProviderKind::Addons);
- let mut primary = Vec::new();
- let mut secondary = Vec::new();
-
- if is_streams {
- primary.extend(footer_group("Enter", "Play", true, theme, modal_active));
- primary.extend(footer_group(
- "d",
- if compact { "Save" } else { "Download" },
- false,
- theme,
- modal_active,
- ));
- secondary.extend(footer_group("f", fav_label, false, theme, modal_active));
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
- } else if is_languages {
- primary.extend(footer_group("Enter", "Select", true, theme, modal_active));
- primary.extend(footer_group("f", fav_label, false, theme, modal_active));
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
- secondary.extend(footer_group("Tab", "Streams", false, theme, modal_active));
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
+ let (enter_label, d_label) = if is_streams {
+ ("Play", Some(if compact { "Save" } else { "Download" }))
} else if is_seasons {
- primary.extend(footer_group("Enter", "Select", true, theme, modal_active));
- primary.extend(footer_group(
- "d",
- if compact {
+ (
+ "Select",
+ Some(if compact {
"Download"
} else {
"Download Season"
- },
- false,
- theme,
- modal_active,
- ));
- primary.extend(footer_group("f", fav_label, false, theme, modal_active));
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
- secondary.extend(footer_group("Tab", "Streams", false, theme, modal_active));
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
+ }),
+ )
} else if is_episodes {
- primary.extend(footer_group("Enter", "Select", true, theme, modal_active));
- primary.extend(footer_group(
- "d",
- if compact {
+ (
+ "Select",
+ Some(if compact {
"Download"
} else {
"Download Episode"
- },
+ }),
+ )
+ } else {
+ ("Select", None)
+ };
+
+ let mut primary = footer_group("Enter", enter_label, true, theme, modal_active);
+ if let Some(d) = d_label {
+ primary.extend(footer_group("d", d, false, theme, modal_active));
+ }
+
+ let mut secondary = footer_group("f", fav_label, false, theme, modal_active);
+ if show_provider {
+ secondary.extend(footer_group(
+ crate::tui::text::CTRL_P_STR,
+ "Provider",
false,
theme,
modal_active,
));
- primary.extend(footer_group("f", fav_label, false, theme, modal_active));
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
- secondary.extend(footer_group("Tab", "Streams", false, theme, modal_active));
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
- } else {
- primary.extend(footer_group("Enter", "Select", true, theme, modal_active));
- primary.extend(footer_group("f", fav_label, false, theme, modal_active));
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
+ }
+ if !is_streams {
secondary.extend(footer_group("Tab", "Streams", false, theme, modal_active));
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
}
+ secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
if let Some(last) = secondary.last_mut() {
*last = Span::raw("");
}
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 59a6c6f..11bbb50 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -435,15 +435,6 @@ pub(crate) fn no_results_button_hitboxes(
};
(btn1, btn2)
}
-#[allow(dead_code)]
-pub(crate) fn render_favorites_landing(
- frame: &mut Frame,
- area: Rect,
- state: &AppState,
- theme: &Theme,
-) {
- render_landing_deck(frame, area, state, theme);
-}
pub(crate) fn render_landing_deck(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
if area.height < 3 || area.width < 20 {
@@ -3392,7 +3383,7 @@ mod tests {
terminal
.draw(|frame| {
let area = Rect::new(0, 0, 80, 24);
- render_favorites_landing(frame, area, &state, &theme);
+ render_landing_deck(frame, area, &state, &theme);
})
.unwrap();
@@ -3439,7 +3430,7 @@ mod tests {
terminal
.draw(|frame| {
let area = Rect::new(0, 0, 80, 24);
- render_favorites_landing(frame, area, &state, &theme);
+ render_landing_deck(frame, area, &state, &theme);
})
.unwrap();
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 0b5dcdd..b99d340 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -593,6 +593,24 @@ impl AppState {
.unwrap_or(self.active_provider)
}
+ pub fn is_selected_details_favorited(&self) -> bool {
+ let Some(details) = &self.selected_details else {
+ return false;
+ };
+ let details_subject_id = self.active_subject_id.as_deref().unwrap_or("");
+ let title = &details.title;
+ let type_val = if details.is_series() { 2 } else { 1 };
+ let year = details.year.as_deref().unwrap_or("N/A");
+ let provider = self.provider_for_subject(details_subject_id);
+ self.favorites.is_favorite(&crate::models::SubjectIdentity {
+ provider: provider.cache_key(),
+ subject_id: details_subject_id,
+ title,
+ stype: type_val,
+ release_year: year,
+ })
+ }
+
pub fn available_providers(&self) -> Vec<ProviderKind> {
crate::models::ProviderKind::ENABLED
.into_iter()
@@ -1094,10 +1112,6 @@ pub enum TvManagerRow {
Done,
}
-fn playlist_is_url(source: &str) -> bool {
- crate::tui::text::is_http_url(source)
-}
-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AddonManagerRow {
Header(&'static str),
@@ -1167,14 +1181,14 @@ 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 playlist_is_url(source) {
+ 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 !playlist_is_url(source) {
+ if !crate::tui::text::is_http_url(source) {
rows.push(TvManagerRow::Playlist(index));
}
}
diff --git a/src/tui/text.rs b/src/tui/text.rs
index 933bd8c..bfd8202 100644
--- a/src/tui/text.rs
+++ b/src/tui/text.rs
@@ -5,12 +5,6 @@ pub fn width(value: &str) -> usize {
UnicodeWidthStr::width(value)
}
-pub fn remove_last_grapheme(value: &mut String) {
- if let Some((index, _)) = value.grapheme_indices(true).next_back() {
- value.truncate(index);
- }
-}
-
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct TextInputBuffer {
content: String,
@@ -305,15 +299,6 @@ pub fn truncate_width(value: &str, max_width: usize) -> String {
output
}
-pub fn pad_to_width(value: &str, target: usize) -> String {
- let current = width(value);
- if current >= target {
- value.to_string()
- } else {
- format!("{value}{}", " ".repeat(target - current))
- }
-}
-
pub fn truncate_middle_width(value: &str, max_width: usize) -> String {
if width(value) <= max_width {
return value.to_string();
@@ -406,6 +391,14 @@ pub fn sanitize_language_label(name: &str) -> String {
}
}
+pub fn format_subtitle_label(name: &str) -> String {
+ if name == "None" {
+ "No subtitles".to_string()
+ } else {
+ sanitize_language_label(name)
+ }
+}
+
pub fn strip_emojis(input: &str) -> String {
input
.chars()
@@ -439,15 +432,6 @@ pub fn clean_stream_text(input: &str) -> String {
cleaned.trim().to_string()
}
-#[cfg(target_os = "macos")]
-pub const CTRL_PREFIX: &str = "^";
-
-#[cfg(not(target_os = "macos"))]
-pub const CTRL_PREFIX: &str = "Ctrl+";
-
-pub fn ctrl_key(key: &str) -> String {
- format!("{CTRL_PREFIX}{key}")
-}
pub const CTRL_S_STR: &str = if cfg!(target_os = "macos") {
"^S"
} else {
@@ -463,31 +447,11 @@ pub const CTRL_A_STR: &str = if cfg!(target_os = "macos") {
} else {
"Ctrl+A"
};
-pub const CTRL_D_STR: &str = if cfg!(target_os = "macos") {
- "^D"
-} else {
- "Ctrl+D"
-};
-pub const CTRL_F_STR: &str = if cfg!(target_os = "macos") {
- "^F"
-} else {
- "Ctrl+F"
-};
-pub const CTRL_H_STR: &str = if cfg!(target_os = "macos") {
- "^H"
-} else {
- "Ctrl+H"
-};
pub const CTRL_P_STR: &str = if cfg!(target_os = "macos") {
"^P"
} else {
"Ctrl+P"
};
-pub const CTRL_R_STR: &str = if cfg!(target_os = "macos") {
- "^R"
-} else {
- "Ctrl+R"
-};
pub fn wrap_text(text: &str, max_width: usize) -> Vec<String> {
if max_width == 0 {
@@ -534,10 +498,7 @@ pub fn wrap_text(text: &str, max_width: usize) -> Vec<String> {
lines
}
-pub fn is_http_url(source: &str) -> bool {
- let trimmed = source.trim();
- trimmed.starts_with("http://") || trimmed.starts_with("https://")
-}
+pub use crate::net::is_http_url;
pub fn extract_4digit_year(raw: &str) -> String {
raw.as_bytes()
.windows(4)
@@ -848,4 +809,10 @@ mod tests {
assert_eq!(cjk_buf.cursor_column_offset(), 2);
assert_eq!(cjk_buf.cursor_split_parts(), ("电", "影", ""));
}
+ #[test]
+ fn test_format_subtitle_label() {
+ assert_eq!(format_subtitle_label("None"), "No subtitles");
+ assert_eq!(format_subtitle_label("eng"), "English");
+ assert_eq!(format_subtitle_label("Spanish"), "Spanish");
+ }
}
diff --git a/src/tui/theme.rs b/src/tui/theme.rs
index 10e4229..5fe6691 100644
--- a/src/tui/theme.rs
+++ b/src/tui/theme.rs
@@ -176,6 +176,9 @@ pub(crate) fn classify_terminal(colorterm: &str, term: &str, term_program: &str)
ColorSupport::Basic
}
}
+pub fn theme_color(style: Style, fallback: Color) -> Color {
+ style.fg.unwrap_or(fallback)
+}
impl Theme {
pub fn mocha() -> Self {
@@ -1089,4 +1092,11 @@ mod tests {
assert_eq!(swatches[2].content, "■");
}
}
+ #[test]
+ fn test_theme_color() {
+ let with_fg = Style::default().fg(Color::Red);
+ assert_eq!(theme_color(with_fg, Color::Blue), Color::Red);
+ let without_fg = Style::default();
+ assert_eq!(theme_color(without_fg, Color::Blue), Color::Blue);
+ }
}
diff --git a/src/tui/widgets/badge.rs b/src/tui/widgets/badge.rs
index c45c516..2e543e3 100644
--- a/src/tui/widgets/badge.rs
+++ b/src/tui/widgets/badge.rs
@@ -4,11 +4,7 @@ use ratatui::{
};
use crate::providers::models::ProviderKind;
-use crate::tui::theme::Theme;
-
-fn theme_color(style: Style, fallback: Color) -> Color {
- style.fg.unwrap_or(fallback)
-}
+use crate::tui::theme::{Theme, theme_color};
pub fn resolution_label(resolution: i64) -> &'static str {
match resolution {
diff --git a/src/updater/apply.rs b/src/updater/apply.rs
index 158cf94..29bfe98 100644
--- a/src/updater/apply.rs
+++ b/src/updater/apply.rs
@@ -232,7 +232,7 @@ fn spawn_windows_helper(staged_path: &Path, current_exe: &Path) -> Result<(), St
#[cfg(windows)]
{
use std::os::windows::process::CommandExt;
- cmd.creation_flags(0x08000000);
+ cmd.creation_flags(crate::player::CREATE_NO_WINDOW);
}
cmd.spawn()
.map_err(|e| format!("failed to spawn Windows update helper: {e}"))?;