Skip to content

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

feat(tui): centralize search input buffer, gate modal graphics, and polish terminal ergonomics

Samir Hossains3f4ff11d8527
diff --git a/src/tui/app/favorites.rs b/src/tui/app/favorites.rs
index 0fa8f10..3e9257b 100644
--- a/src/tui/app/favorites.rs
+++ b/src/tui/app/favorites.rs
@@ -214,7 +214,7 @@ impl App {
self.state.suggest_index = None;
self.state.favorites_focus = false;
- self.state.search_query = "/favorites".to_string();
+ self.state.search_query.set_content("/favorites");
let mut items = self.state.favorites.items.clone();
if items.is_empty() {
self.state.notify(
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index 3ceb03f..37b2642 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -311,15 +311,9 @@ impl App {
return None;
}
if let KeyCode::Char('w') = key.code {
- let trimmed = self.state.search_query.trim_end();
- if let Some(last_space) = trimmed
- .rfind(|c: char| c.is_whitespace() || c == '/' || c == '-' || c == '_')
- {
- self.state.search_query.truncate(last_space);
- } else {
- self.state.search_query.clear();
- }
+ self.state.search_query.delete_word_backwards();
self.state.suggest_index = None;
+ self.state.search_suggestions.clear();
self.state.last_search_edit = std::time::Instant::now();
return None;
}
@@ -358,11 +352,11 @@ impl App {
if !query.is_empty() {
if query.trim().eq_ignore_ascii_case("/history") {
- self.state.search_query = "/history".to_string();
+ self.state.search_query.set_content("/history");
} else if query.starts_with('/') {
self.state.search_query.clear();
} else {
- self.state.search_query = query.clone();
+ self.state.search_query.set_content(&query);
}
self.state.input_mode = InputMode::Normal;
self.state.search_suggestions.clear();
@@ -397,17 +391,42 @@ impl App {
.or_else(|| self.state.search_suggestions.first().cloned())
};
if let Some(sug) = selected_or_first {
- self.state.search_query = sug;
+ self.state.search_query.set_content(&sug);
self.state.last_search_edit = std::time::Instant::now();
}
}
+ KeyCode::Left => {
+ self.state.search_query.move_left();
+ self.state.suggest_index = None;
+ self.state.last_search_edit = std::time::Instant::now();
+ }
+ KeyCode::Right => {
+ self.state.search_query.move_right();
+ self.state.suggest_index = None;
+ self.state.last_search_edit = std::time::Instant::now();
+ }
+ KeyCode::Home => {
+ self.state.search_query.move_home();
+ self.state.suggest_index = None;
+ self.state.last_search_edit = std::time::Instant::now();
+ }
+ KeyCode::End => {
+ self.state.search_query.move_end();
+ self.state.suggest_index = None;
+ self.state.last_search_edit = std::time::Instant::now();
+ }
KeyCode::Backspace => {
- crate::tui::text::remove_last_grapheme(&mut self.state.search_query);
+ self.state.search_query.delete_backwards();
+ self.state.suggest_index = None;
+ self.state.last_search_edit = std::time::Instant::now();
+ }
+ KeyCode::Delete => {
+ self.state.search_query.delete_forwards();
self.state.suggest_index = None;
self.state.last_search_edit = std::time::Instant::now();
}
KeyCode::Char(c) => {
- self.state.search_query.push(c);
+ self.state.search_query.insert(c);
self.state.suggest_index = None;
self.state.last_search_edit = std::time::Instant::now();
}
@@ -884,7 +903,7 @@ impl App {
if c == '/' {
self.state.search_query.clear();
}
- self.state.search_query.push(c);
+ self.state.search_query.insert(c);
self.state.search_suggestions.clear();
self.state.suggest_index = None;
diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rs
index 0dc9711..3dbea5a 100644
--- a/src/tui/app/navigation.rs
+++ b/src/tui/app/navigation.rs
@@ -152,7 +152,7 @@ impl App {
})
.ok();
} else {
- let query = self.state.search_query.clone();
+ let query = self.state.search_query.to_string();
let service = self.service.clone();
let sender = self.action_sender.clone();
let context = self.request_context();
@@ -744,9 +744,6 @@ impl App {
if self.state.is_loading {
return None;
}
- if self.state.last_search_edit.elapsed().as_millis() < 500 {
- return None;
- }
if self.state.player_picker_popup {
let idx = self.state.player_picker_state.selected().unwrap_or(0);
if let Some(player) = self.state.available_players.get(idx).copied() {
@@ -816,6 +813,9 @@ impl App {
return None;
}
if self.state.active_screen == Screen::Home {
+ if self.state.last_search_edit.elapsed().as_millis() < 500 {
+ return None;
+ }
let idx_opt = self.state.search_list_state.selected();
let item_opt =
idx_opt.and_then(|idx| self.state.search_results.get(idx).cloned());
diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rs
index a0cd65b..3193cdd 100644
--- a/src/tui/app/requests.rs
+++ b/src/tui/app/requests.rs
@@ -123,7 +123,7 @@ impl App {
}
Action::SelectSuggestion { query } => {
- self.state.search_query = query.clone();
+ self.state.search_query.set_content(&query);
self.state.suggest_index = None;
self.state.search_suggestions.clear();
self.state.input_mode = InputMode::Normal;
@@ -166,7 +166,7 @@ impl App {
self.state.search_suggestions.clear();
self.state.suggest_index = None;
- self.state.search_query = "/history".to_string();
+ self.state.search_query.set_content("/history");
let mut recent = self.state.history.recent.clone();
if recent.is_empty() {
self.state.notify(
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 365998d..0a2e584 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -65,6 +65,7 @@ impl App {
let kind = self.state.available_players.remove(index);
self.state.available_players.insert(0, kind);
}
+ let mut last_window_title = String::new();
loop {
let want_beam =
@@ -79,6 +80,11 @@ impl App {
let _ = crossterm::execute!(std::io::stdout(), style);
self.state.cursor_beam = want_beam;
}
+ let title = self.contextual_title();
+ if title != last_window_title {
+ let _ = crate::tui::terminal::set_window_title(&title);
+ last_window_title = title;
+ }
self.state.normalize_result_view();
if self.state.clear_terminal_before_draw {
if let Err(err) = terminal.clear() {
@@ -276,6 +282,25 @@ impl App {
}
Some(ratatui_image::FontSize { width, height })
}
+ pub fn contextual_title(&self) -> String {
+ match self.state.active_screen {
+ Screen::Home => match self.state.mode() {
+ crate::tui::state::AppMode::Streaming => "MovieBox-Tui — Streaming".to_string(),
+ crate::tui::state::AppMode::Tv => "MovieBox-Tui — Live TV".to_string(),
+ crate::tui::state::AppMode::Addon => "MovieBox-Tui — Addons".to_string(),
+ },
+ Screen::Details => {
+ if let Some(details) = &self.state.selected_details {
+ if let Some(title) = details.get("title").and_then(|t| t.as_str()) {
+ if !title.is_empty() {
+ return format!("MovieBox-Tui — {title}");
+ }
+ }
+ }
+ "MovieBox-Tui — Details".to_string()
+ }
+ }
+ }
pub async fn handle_action(&mut self, action: Action) -> Option<()> {
if self.state.last_resize_time.is_some()
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index f4abade..0ac7d82 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -99,7 +99,7 @@ pub fn download_confirm_layout(
}
pub fn download_confirm_action_row(popup: Rect, summary_lines: usize) -> u16 {
- popup.y + summary_lines as u16 + 2
+ popup.y + summary_lines as u16 + 1
}
pub fn picker(
@@ -680,4 +680,28 @@ mod tests {
assert_eq!(large.display_count, 10);
assert!(large.has_more);
}
+
+ #[test]
+ fn test_download_confirm_action_row_matches_rendered_button_section() {
+ let popup = Rect::new(10, 10, 40, 10);
+ let summary_lines = 3;
+ let action_row = download_confirm_action_row(popup, summary_lines);
+
+ // Borders = 1 (top border at popup.y), Summary = 3 lines (popup.y + 1 .. popup.y + 4)
+ // Action row = popup.y + 1 + 3 = popup.y + 4
+ assert_eq!(action_row, popup.y + 4);
+ assert!(popup.contains(ratatui::layout::Position::new(popup.x + 2, action_row)));
+ }
+
+ #[test]
+ fn test_download_confirm_zones_do_not_overlap() {
+ let area = Rect::new(0, 0, 80, 24);
+ let summary_lines = 4;
+ let longest = 30;
+ let popup = download_confirm_layout(area, summary_lines, longest);
+ let action_row = download_confirm_action_row(popup, summary_lines);
+
+ assert!(popup.contains(ratatui::layout::Position::new(popup.x + 1, action_row)));
+ assert!(action_row < popup.bottom() - 1); // Action row is inside inner area before footer/border
+ }
}
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 5336f45..6b3bcea 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -300,7 +300,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
}
if let Some((_, proto)) = &state.poster_protocol {
- if !state.show_help {
+ if !state.has_active_modal() {
frame.render_widget(ratatui_image::Image::new(proto), poster_area);
}
}
@@ -1176,9 +1176,6 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
}
}
- if !state.selected_resources.is_some() {
- frame.render_widget(streams_block, streams_area);
- }
let (mut primary_footer, secondary_footer) = details_footer(state, theme, area.width);
let footer_p = if area.width >= 70 {
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 9d4e23b..54c2f75 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -431,8 +431,9 @@ fn search_content(
.saturating_sub(crate::tui::text::width(prefix) as u16)
.saturating_sub(cursor_width as u16) as usize;
let has_status = state.status_timer > 0 && !state.status_message.is_empty();
- let content = if state.search_query.is_empty() {
- if has_status && !editing {
+
+ if state.search_query.is_empty() {
+ let content = if has_status && !editing {
crate::tui::text::truncate_width(&state.status_message, available)
} else if state.is_tv_mode {
"Search live channels…".to_string()
@@ -440,16 +441,36 @@ fn search_content(
"Search movies and series via addons…".to_string()
} else {
"Search movies and series…".to_string()
- }
- } else {
- crate::tui::text::truncate_width(&state.search_query, available)
- };
- let cursor = if editing && !real_cursor {
- if show_cursor { "█" } else { " " }
+ };
+ let cursor = if editing && !real_cursor {
+ if show_cursor { "█" } else { " " }
+ } else {
+ ""
+ };
+ format!("{prefix}{content}{cursor}")
+ } else if editing && !real_cursor {
+ let segments = state.search_query.graphemes();
+ let cursor = state.search_query.cursor();
+ let cursor_char = if show_cursor {
+ "█"
+ } else if cursor < segments.len() {
+ segments[cursor]
+ } else {
+ " "
+ };
+ let before: String = segments.iter().take(cursor).copied().collect();
+ let after: String = if cursor < segments.len() {
+ segments.iter().skip(cursor + 1).copied().collect()
+ } else {
+ String::new()
+ };
+ let full = format!("{before}{cursor_char}{after}");
+ let truncated = crate::tui::text::truncate_width(&full, available);
+ format!("{prefix}{truncated}")
} else {
- ""
- };
- format!("{prefix}{content}{cursor}")
+ let content = crate::tui::text::truncate_width(state.search_query.as_str(), available);
+ format!("{prefix}{content}")
+ }
}
fn render_search_bar(
@@ -507,15 +528,21 @@ fn render_search_bar(
}
frame.render_widget(paragraph, content_row[0]);
if real_cursor {
- let prefix_width = 2u16;
- let text_width = crate::tui::text::width(&state.search_query) as u16;
- let shown = text_width.min(content_row[0].width.saturating_sub(6));
+ let prefix_width =
+ crate::tui::text::width(if state.basic_terminal { "> " } else { "❯ " }) as u16;
+ let segments = state.search_query.graphemes();
+ let cursor = state.search_query.cursor();
+ let before_cursor: String = segments.into_iter().take(cursor).collect();
+ let before_cursor_width = crate::tui::text::width(&before_cursor) as u16;
+ let total_text_width = crate::tui::text::width(state.search_query.as_str()) as u16;
+ let shown = total_text_width.min(content_row[0].width.saturating_sub(6));
let line_offset = if centered {
(content_row[0].width.saturating_sub(prefix_width + shown)) / 2
} else {
0
};
- let cursor_x = content_row[0].x + line_offset + prefix_width + shown;
+ let cursor_x = (content_row[0].x + line_offset + prefix_width + before_cursor_width)
+ .min(content_row[0].right().saturating_sub(1));
frame.set_cursor_position((cursor_x, content_row[0].y));
}
if let Some(status) = result_status {
@@ -906,16 +933,17 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
}
if let Some((_, proto)) = state.search_poster_protocols.peek(&res.id) {
- let img_height = poster_area.height.min(state.poster_rows);
- let img_y_offset = item_area.height.saturating_sub(img_height) / 2;
- let p_area = Rect {
- y: poster_area.y + img_y_offset,
- height: img_height,
- ..poster_area
- };
- frame.render_widget(ratatui_image::Image::new(proto), p_area);
+ if !state.has_active_modal() {
+ let img_height = poster_area.height.min(state.poster_rows);
+ let img_y_offset = item_area.height.saturating_sub(img_height) / 2;
+ let p_area = Rect {
+ y: poster_area.y + img_y_offset,
+ height: img_height,
+ ..poster_area
+ };
+ frame.render_widget(ratatui_image::Image::new(proto), p_area);
+ }
}
- } else {
let is_in_flight = state.in_flight_posters.contains(&res.id);
let placeholder = Paragraph::new(poster_placeholder_lines(
state.basic_terminal,
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 3e7ab07..a0e2970 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -63,7 +63,7 @@ pub struct AppState {
pub active_screen: Screen,
pub dirty: bool,
pub input_mode: InputMode,
- pub search_query: String,
+ pub search_query: crate::tui::text::TextInputBuffer,
pub last_suggest_query: String,
pub last_search_edit: std::time::Instant,
pub search_suggestions: Vec<String>,
@@ -221,7 +221,7 @@ impl Default for AppState {
provider_generation: 0,
active_screen: Screen::Home,
input_mode: InputMode::Normal,
- search_query: String::new(),
+ search_query: crate::tui::text::TextInputBuffer::new(),
last_suggest_query: String::new(),
last_search_edit: std::time::Instant::now(),
search_suggestions: Vec::new(),
@@ -525,6 +525,19 @@ impl AppState {
None => false,
}
}
+ pub fn has_active_modal(&self) -> bool {
+ self.show_help
+ || self.show_theme_popup
+ || self.show_browse_popup
+ || self.addon_manager_popup
+ || self.tv_config_popup
+ || self.player_picker_popup
+ || self.subtitle_popup
+ || self.is_download_subtitle_popup
+ || self.show_season_download_confirm
+ || self.show_episode_download_confirm
+ || self.update_available.is_some()
+ }
pub fn clear_search_state(&mut self) {
self.search_query.clear();
@@ -737,4 +750,56 @@ mod tests {
assert_eq!(state.result_scroll, 6);
assert!(state.search_list_state.selected().unwrap() < state.result_scroll + 6);
}
+
+ #[test]
+ fn test_has_active_modal_detection() {
+ let mut state = AppState::default();
+ assert!(!state.has_active_modal());
+
+ state.show_help = true;
+ assert!(state.has_active_modal());
+ state.show_help = false;
+
+ state.show_theme_popup = true;
+ assert!(state.has_active_modal());
+ state.show_theme_popup = false;
+
+ state.show_browse_popup = true;
+ assert!(state.has_active_modal());
+ state.show_browse_popup = false;
+
+ state.addon_manager_popup = true;
+ assert!(state.has_active_modal());
+ state.addon_manager_popup = false;
+
+ state.tv_config_popup = true;
+ assert!(state.has_active_modal());
+ state.tv_config_popup = false;
+
+ state.player_picker_popup = true;
+ assert!(state.has_active_modal());
+ state.player_picker_popup = false;
+
+ state.subtitle_popup = true;
+ assert!(state.has_active_modal());
+ state.subtitle_popup = false;
+
+ state.is_download_subtitle_popup = true;
+ assert!(state.has_active_modal());
+ state.is_download_subtitle_popup = false;
+
+ state.show_season_download_confirm = true;
+ assert!(state.has_active_modal());
+ state.show_season_download_confirm = false;
+
+ state.show_episode_download_confirm = true;
+ assert!(state.has_active_modal());
+ state.show_episode_download_confirm = false;
+
+ state.update_available = Some(("v2.0.0".to_string(), "Notes".to_string()));
+ assert!(state.has_active_modal());
+ state.update_available = None;
+
+ assert!(!state.has_active_modal());
+ }
}
diff --git a/src/tui/terminal.rs b/src/tui/terminal.rs
index a69c636..4dd3c5e 100644
--- a/src/tui/terminal.rs
+++ b/src/tui/terminal.rs
@@ -30,3 +30,7 @@ pub fn background_is_light() -> bool {
std::env::var("TERM_BACKGROUND").is_ok_and(|value| value.eq_ignore_ascii_case("light"))
}
+
+pub fn set_window_title(title: &str) -> std::io::Result<()> {
+ crossterm::execute!(std::io::stdout(), crossterm::terminal::SetTitle(title))
+}
diff --git a/src/tui/text.rs b/src/tui/text.rs
index 6c946aa..a8769d5 100644
--- a/src/tui/text.rs
+++ b/src/tui/text.rs
@@ -54,7 +54,7 @@ impl TextInputBuffer {
pub fn set_content(&mut self, content: impl Into<String>) {
self.content = content.into();
- self.cursor = self.cursor.min(self.len_graphemes());
+ self.cursor = self.len_graphemes();
}
pub fn graphemes(&self) -> Vec<&str> {
@@ -137,7 +137,6 @@ impl TextInputBuffer {
while new_cursor > 0 && !is_delim(graphemes[new_cursor - 1]) {
new_cursor -= 1;
}
-
if new_cursor == old_cursor {
return false;
}
@@ -222,6 +221,44 @@ impl std::str::FromStr for TextInputBuffer {
}
}
+impl std::ops::Deref for TextInputBuffer {
+ type Target = str;
+
+ fn deref(&self) -> &Self::Target {
+ &self.content
+ }
+}
+
+impl PartialEq<str> for TextInputBuffer {
+ fn eq(&self, other: &str) -> bool {
+ self.content == other
+ }
+}
+
+impl PartialEq<&str> for TextInputBuffer {
+ fn eq(&self, other: &&str) -> bool {
+ self.content == *other
+ }
+}
+
+impl PartialEq<String> for TextInputBuffer {
+ fn eq(&self, other: &String) -> bool {
+ self.content == *other
+ }
+}
+
+impl PartialEq<TextInputBuffer> for &str {
+ fn eq(&self, other: &TextInputBuffer) -> bool {
+ *self == other.content
+ }
+}
+
+impl PartialEq<TextInputBuffer> for String {
+ fn eq(&self, other: &TextInputBuffer) -> bool {
+ *self == other.content
+ }
+}
+
pub fn truncate_width(value: &str, max_width: usize) -> String {
if width(value) <= max_width {
return value.to_string();
diff --git a/src/tui/theme.rs b/src/tui/theme.rs
index 3c667f5..41511c3 100644
--- a/src/tui/theme.rs
+++ b/src/tui/theme.rs
@@ -117,6 +117,17 @@ pub enum ColorSupport {
Color256,
Basic,
}
+impl ColorSupport {
+ pub fn current() -> Self {
+ if std::env::var("NO_COLOR").is_ok() {
+ return ColorSupport::NoColor;
+ }
+ let colorterm = std::env::var("COLORTERM").unwrap_or_default();
+ let term = std::env::var("TERM").unwrap_or_default();
+ let term_program = std::env::var("TERM_PROGRAM").unwrap_or_default();
+ classify_terminal(&colorterm, &term, &term_program)
+ }
+}
pub(crate) fn classify_terminal(colorterm: &str, term: &str, term_program: &str) -> ColorSupport {
let colorterm = colorterm.to_lowercase();
@@ -241,7 +252,7 @@ impl Theme {
}
pub fn from_kind(kind: ThemeKind) -> Self {
- match kind {
+ let base = match kind {
ThemeKind::Latte => Self::latte(),
ThemeKind::Macchiato => Self::macchiato(),
ThemeKind::Frappe => Self::frappe(),
@@ -251,6 +262,10 @@ impl Theme {
ThemeKind::Gruvbox => Self::gruvbox(),
ThemeKind::RosePine => Self::rose_pine(),
ThemeKind::Mocha => Self::mocha(),
+ };
+ match ColorSupport::current() {
+ ColorSupport::Color256 => base.quantized_to_256(),
+ _ => base,
}
}
}
@@ -265,13 +280,7 @@ impl Theme {
if std::env::var("NO_COLOR").is_ok() {
return Self::monochrome(resolved_light);
}
- let colorterm = std::env::var("COLORTERM").unwrap_or_default();
- let term = std::env::var("TERM").unwrap_or_default();
- let term_program = std::env::var("TERM_PROGRAM").unwrap_or_default();
- Self::detect_from(
- classify_terminal(&colorterm, &term, &term_program),
- resolved_light,
- )
+ Self::detect_from(ColorSupport::current(), resolved_light)
}
pub(crate) fn detect_from(support: ColorSupport, is_light: bool) -> Self {
@@ -375,7 +384,50 @@ impl Theme {
pub fn fallback(is_light: bool) -> Self {
if is_light {
- return Self::latte();
+ return Self {
+ border: Style::default().fg(Color::DarkGray),
+ border_focus: Style::default()
+ .fg(Color::Blue)
+ .add_modifier(Modifier::BOLD),
+ text: Style::default().fg(Color::Black),
+ text_dim: Style::default().fg(Color::DarkGray),
+ title: Style::default()
+ .fg(Color::Magenta)
+ .add_modifier(Modifier::BOLD),
+ highlight: Style::default()
+ .fg(Color::Blue)
+ .add_modifier(Modifier::BOLD),
+ header: Style::default()
+ .fg(Color::Magenta)
+ .add_modifier(Modifier::BOLD),
+ error: Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
+ success: Style::default().fg(Color::Green),
+ shortcut: Style::default().fg(Color::Red),
+ overlay: Style::default().fg(Color::DarkGray),
+ rating: Style::default().fg(Color::Yellow),
+ accent: Style::default()
+ .fg(Color::Blue)
+ .add_modifier(Modifier::BOLD),
+ muted: Style::default().fg(Color::DarkGray),
+ teal: Style::default().fg(Color::Cyan),
+ lavender: Style::default().fg(Color::Blue),
+ sapphire: Style::default().fg(Color::Blue),
+ subtext1: Style::default().fg(Color::Black),
+ base: Color::White,
+ bg: Style::default(),
+ rosewater: Style::default().fg(Color::Black),
+ flamingo: Style::default().fg(Color::Magenta),
+ maroon: Style::default().fg(Color::Red),
+ surface0: Style::default().fg(Color::DarkGray),
+ surface1: Style::default().fg(Color::DarkGray),
+ surface2: Style::default().fg(Color::Black),
+ overlay0: Style::default().fg(Color::DarkGray),
+ overlay1: Style::default().fg(Color::DarkGray),
+ overlay2: Style::default().fg(Color::Black),
+ mantle: Style::default().fg(Color::White),
+ crust: Style::default().fg(Color::White),
+ is_light: true,
+ };
}
Self {
border: Style::default().fg(Color::DarkGray),
@@ -419,7 +471,7 @@ impl Theme {
overlay2: Style::default().fg(Color::Gray),
mantle: Style::default().fg(Color::Black),
crust: Style::default().fg(Color::Black),
- is_light,
+ is_light: false,
}
}
@@ -914,4 +966,33 @@ mod tests {
assert!(Theme::detect_from(ColorSupport::Truecolor, true).is_light);
assert!(!Theme::detect_from(ColorSupport::NoColor, false).is_light);
}
+
+ #[test]
+ fn fallback_light_uses_high_contrast_ansi_palette_with_no_rgb() {
+ let fallback_light = Theme::fallback(true);
+ assert!(fallback_light.is_light);
+ assert_eq!(fallback_light.text.fg, Some(Color::Black));
+ assert_eq!(fallback_light.base, Color::White);
+
+ for style in [
+ fallback_light.border,
+ fallback_light.border_focus,
+ fallback_light.text,
+ fallback_light.text_dim,
+ fallback_light.title,
+ fallback_light.highlight,
+ fallback_light.header,
+ fallback_light.error,
+ fallback_light.success,
+ fallback_light.shortcut,
+ fallback_light.accent,
+ ] {
+ assert!(
+ style
+ .fg
+ .map(|c| !matches!(c, Color::Rgb(..)))
+ .unwrap_or(true)
+ );
+ }
+ }
}
diff --git a/tests/content_pipeline.rs b/tests/content_pipeline.rs
index df166c2..0fdad05 100644
--- a/tests/content_pipeline.rs
+++ b/tests/content_pipeline.rs
@@ -323,7 +323,7 @@ async fn test_search_failure_vs_empty_result_distinction() {
app.state_mut().update_available = None;
app.state_mut().active_provider = ProviderKind::MovieBox;
app.state_mut().input_mode = InputMode::Normal;
- app.state_mut().search_query = "xyznonexistent".to_string();
+ app.state_mut().search_query.set_content("xyznonexistent");
let context = RequestContext {
provider: ProviderKind::MovieBox,
@@ -375,7 +375,7 @@ async fn test_mode_switch_stale_response_protection() {
generation: streaming_generation,
};
app.state_mut().active_search_request = 1;
- app.state_mut().search_query = "avatar".to_string();
+ app.state_mut().search_query.set_content("avatar");
app.handle_action(Action::ToggleAddonMode).await;
assert_eq!(app.state().mode(), AppMode::Addon);
diff --git a/tests/error_handling.rs b/tests/error_handling.rs
index f16911f..80ab2df 100644
--- a/tests/error_handling.rs
+++ b/tests/error_handling.rs
@@ -11,7 +11,7 @@ async fn test_search_failure_clears_loading_and_sets_error_state() {
let mut app = App::new();
app.state_mut().is_loading = true;
app.state_mut().active_search_request = 42;
- app.state_mut().search_query = "Inception".to_string();
+ app.state_mut().search_query.set_content("Inception");
let context = RequestContext {
provider: app.state().active_provider,
diff --git a/tests/grand_user_journey.rs b/tests/grand_user_journey.rs
index 7dcfeed..2782109 100644
--- a/tests/grand_user_journey.rs
+++ b/tests/grand_user_journey.rs
@@ -19,7 +19,7 @@ async fn test_grand_user_journey_complete_lifecycle() {
app.state_mut().set_mode(AppMode::Streaming);
app.state_mut().active_provider = ProviderKind::MovieBox;
- app.state_mut().search_query = "Inception".to_string();
+ app.state_mut().search_query.set_content("Inception");
let streaming_ctx = RequestContext {
provider: ProviderKind::MovieBox,
@@ -220,7 +220,7 @@ async fn test_grand_user_journey_complete_lifecycle() {
assert!(app.state().download_progress.is_none());
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "/download-dir".to_string();
+ app.state_mut().search_query.set_content("/download-dir");
assert_eq!(app.state().search_query, "/download-dir");
let esc_key = crossterm::event::KeyEvent::new(
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
index d766ad1..673f862 100644
--- a/tests/tui_acceptance.rs
+++ b/tests/tui_acceptance.rs
@@ -13,7 +13,7 @@ async fn test_backspace_from_home_focuses_search_input() {
let mut app = App::new();
app.state_mut().active_screen = Screen::Home;
app.state_mut().input_mode = InputMode::Normal;
- app.state_mut().search_query = "Inception".to_string();
+ app.state_mut().search_query.set_content("Inception");
app.state_mut().favorites_focus = true;
let key = KeyEvent::new(KeyCode::Backspace, KeyModifiers::empty());
@@ -309,7 +309,7 @@ async fn test_esc_key_cancels_slash_command_and_clears_search_bar() {
app.state_mut().show_theme_popup = false;
app.state_mut().show_browse_popup = false;
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "/download-dir".to_string();
+ app.state_mut().search_query.set_content("/download-dir");
let esc_key = crossterm::event::KeyEvent::new(
crossterm::event::KeyCode::Esc,
@@ -328,7 +328,7 @@ async fn test_esc_key_cancels_unsubmitted_search_query() {
app.state_mut().show_theme_popup = false;
app.state_mut().show_browse_popup = false;
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "batman".to_string();
+ app.state_mut().search_query.set_content("batman");
assert!(app.state().search_results.is_empty());
let esc_key = crossterm::event::KeyEvent::new(
@@ -345,7 +345,7 @@ async fn test_esc_key_cancels_unsubmitted_search_query() {
async fn test_tab_key_completes_regular_search_suggestions() {
let mut app = App::new();
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "inter".to_string();
+ app.state_mut().search_query.set_content("inter");
app.state_mut().search_suggestions =
vec!["Interstellar".to_string(), "Interstellar 2".to_string()];
@@ -362,7 +362,7 @@ async fn test_tab_key_completes_regular_search_suggestions() {
async fn test_ctrl_u_clears_search_input() {
let mut app = App::new();
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "hello world".to_string();
+ app.state_mut().search_query.set_content("hello world");
let ctrl_u = crossterm::event::KeyEvent::new(
crossterm::event::KeyCode::Char('u'),
@@ -377,23 +377,27 @@ async fn test_ctrl_u_clears_search_input() {
async fn test_ctrl_w_deletes_backward_word() {
let mut app = App::new();
app.state_mut().input_mode = InputMode::Editing;
- app.state_mut().search_query = "the dark knight".to_string();
+ app.state_mut().search_query.set_content("the dark knight");
let ctrl_w = crossterm::event::KeyEvent::new(
crossterm::event::KeyCode::Char('w'),
crossterm::event::KeyModifiers::CONTROL,
);
app.handle_action(Action::Key(ctrl_w)).await;
- assert_eq!(app.state().search_query, "the dark");
+ assert_eq!(app.state().search_query, "the dark ");
app.handle_action(Action::Key(ctrl_w)).await;
- assert_eq!(app.state().search_query, "the");
+ assert_eq!(app.state().search_query, "the ");
+
+ app.handle_action(Action::Key(ctrl_w)).await;
+ assert_eq!(app.state().search_query, "");
}
#[tokio::test]
async fn test_f_key_toggles_favorite_on_home_results() {
let mut app = App::new();
app.state_mut().active_screen = Screen::Home;
+ app.state_mut().favorites.items.clear();
let res = SearchResult {
id: "100".to_string(),
title: "Test Movie".to_string(),
@@ -438,3 +442,63 @@ async fn test_up_from_favorites_landing_unfocuses() {
assert!(!app.state().favorites_focus);
assert_eq!(app.state().favorites_landing_state.selected(), None);
}
+
+#[tokio::test]
+async fn test_search_cursor_navigation_and_mid_string_editing() {
+ let mut app = App::new();
+ app.state_mut().input_mode = InputMode::Editing;
+ app.state_mut().search_query.set_content("avtar");
+
+ // Move left twice to position cursor between 'v' and 't' (pos 2)
+ let left = KeyEvent::new(KeyCode::Left, KeyModifiers::empty());
+ app.handle_action(Action::Key(left)).await;
+ app.handle_action(Action::Key(left)).await;
+ assert_eq!(app.state().search_query.cursor(), 3);
+ app.handle_action(Action::Key(left)).await;
+ assert_eq!(app.state().search_query.cursor(), 2);
+
+ // Insert 'a' -> "avatar"
+ let char_a = KeyEvent::new(KeyCode::Char('a'), KeyModifiers::empty());
+ app.handle_action(Action::Key(char_a)).await;
+ assert_eq!(app.state().search_query, "avatar");
+ assert_eq!(app.state().search_query.cursor(), 3);
+
+ // Home -> cursor at 0
+ let home = KeyEvent::new(KeyCode::Home, KeyModifiers::empty());
+ app.handle_action(Action::Key(home)).await;
+ assert_eq!(app.state().search_query.cursor(), 0);
+
+ // Forward delete 'a' -> "vatar"
+ let delete = KeyEvent::new(KeyCode::Delete, KeyModifiers::empty());
+ app.handle_action(Action::Key(delete)).await;
+ assert_eq!(app.state().search_query, "vatar");
+ assert_eq!(app.state().search_query.cursor(), 0);
+
+ // End -> cursor at end
+ let end = KeyEvent::new(KeyCode::End, KeyModifiers::empty());
+ app.handle_action(Action::Key(end)).await;
+ assert_eq!(app.state().search_query.cursor(), 5);
+}
+
+#[tokio::test]
+async fn test_contextual_window_title() {
+ let mut app = App::new();
+ app.state_mut().active_screen = Screen::Home;
+ app.state_mut()
+ .set_mode(moviebox_tui::tui::state::AppMode::Streaming);
+ assert_eq!(app.contextual_title(), "MovieBox-Tui — Streaming");
+
+ app.state_mut()
+ .set_mode(moviebox_tui::tui::state::AppMode::Tv);
+ assert_eq!(app.contextual_title(), "MovieBox-Tui — Live TV");
+
+ app.state_mut()
+ .set_mode(moviebox_tui::tui::state::AppMode::Addon);
+ assert_eq!(app.contextual_title(), "MovieBox-Tui — Addons");
+
+ app.state_mut().active_screen = Screen::Details;
+ app.state_mut().selected_details = Some(serde_json::json!({
+ "title": "Inception"
+ }));
+ assert_eq!(app.contextual_title(), "MovieBox-Tui — Inception");
+}