Skip to content

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

feat(ui): Add stream table headers, framed search status cards, and grid gutter scaling

Samir Hossains1829f560b2f1
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index 2f2e4c1..6217800 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -224,7 +224,7 @@ impl App {
self.action_sender.send(Action::SelectTheme(orig)).ok();
}
}
- KeyCode::Up => {
+ KeyCode::Up | KeyCode::Char('k') => {
crate::tui::state::cycle_list_selection(
&mut self.state.theme_list_state,
crate::tui::theme::AVAILABLE_THEMES.len(),
@@ -237,7 +237,7 @@ impl App {
.ok();
}
}
- KeyCode::Down => {
+ KeyCode::Down | KeyCode::Char('j') => {
crate::tui::state::cycle_list_selection(
&mut self.state.theme_list_state,
crate::tui::theme::AVAILABLE_THEMES.len(),
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index 8cc44b7..7820a4e 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -642,7 +642,9 @@ impl App {
let row_height = metrics.row_height;
let clicked_relative_row = row.saturating_sub(results_y);
let visual_row = (clicked_relative_row / row_height) as usize;
- let clicked_column = ((col.saturating_sub(area.x)) / metrics.col_width.max(1)) as usize;
+ let col_step = (metrics.col_width + 1).max(1);
+ let clicked_column = (((col.saturating_sub(area.x)) / col_step) as usize)
+ .min(metrics.columns.saturating_sub(1) as usize);
let page_start = self.state.result_scroll;
@@ -850,14 +852,9 @@ impl App {
if !visible_selector_panes.is_empty()
&& selector_area.contains(ratatui::layout::Position::new(col, row))
{
- let selector_chunks = Layout::horizontal(vec![
- Constraint::Ratio(
- 1,
- visible_selector_panes.len() as u32
- );
- visible_selector_panes.len()
- ])
- .split(selector_area);
+ let selector_constraints =
+ crate::tui::screens::details::selector_pane_constraints(&visible_selector_panes);
+ let selector_chunks = Layout::horizontal(selector_constraints).split(selector_area);
for (pane, pane_rect) in visible_selector_panes
.into_iter()
@@ -946,6 +943,9 @@ impl App {
line_offset += 1;
}
line_offset += 1;
+ if i == 0 {
+ line_offset += 1;
+ }
prev_resolution = Some(resolution);
}
if clicked_stream_row == line_offset {
@@ -985,8 +985,40 @@ impl App {
fn handle_details_footer_click(&mut self, col: u16, line_idx: u16, width: u16) {
let is_streams = self.state.details_pane == DetailsPane::Streams;
let is_seasons = self.state.details_pane == DetailsPane::Seasons;
+ let is_episodes = self.state.details_pane == DetailsPane::Episodes;
let is_languages = self.state.details_pane == DetailsPane::Languages;
- let compact = width < 80;
+ 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.get("title").and_then(|t| t.as_str()).unwrap_or("");
+ let type_val = crate::tui::state::stype(details);
+ let year = details
+ .get("releaseDate")
+ .or_else(|| details.get("year"))
+ .or_else(|| details.get("releaseInfo"))
+ .and_then(|y| y.as_str())
+ .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 fav_label_len = if is_favorited { 10 } else { 8 };
enum FooterAction {
PlaySelect,
@@ -1008,35 +1040,50 @@ impl App {
let d_label_len = if compact { 4 } else { 8 };
primary.push((FooterAction::Download, 3 + 1 + d_label_len));
- secondary.push((FooterAction::Favorite, 3 + 1 + 8));
- let s_label_len = if compact { 4 } else { 9 };
- secondary.push((FooterAction::Subtitles, 3 + 1 + s_label_len));
+ secondary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
+ if !self.state.subtitle_list.is_empty() {
+ let s_label_len = if compact { 4 } else { 9 };
+ secondary.push((FooterAction::Subtitles, 3 + 1 + s_label_len));
+ }
secondary.push((FooterAction::Back, 5 + 1 + 4));
} else if is_languages {
primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
- primary.push((FooterAction::Favorite, 3 + 1 + 8));
+ primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
secondary.push((FooterAction::Back, 5 + 1 + 4));
- } else {
+ } else if is_seasons {
primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
let d_label_len = if compact { 8 } else { 15 };
primary.push((FooterAction::Download, 3 + 1 + d_label_len));
- primary.push((FooterAction::Favorite, 3 + 1 + 8));
+ primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
+ secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
+ secondary.push((FooterAction::Back, 5 + 1 + 4));
+ } else if is_episodes {
+ primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
+ let d_label_len = if compact { 8 } else { 16 };
+ primary.push((FooterAction::Download, 3 + 1 + d_label_len));
+ primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
secondary.push((FooterAction::Back, 5 + 1 + 4));
- }
- let active_buttons = if width >= 86 {
- if line_idx > 0 {
- return;
- }
- let mut combined = primary;
- combined.extend(secondary);
- combined
- } else if line_idx == 0 {
- primary
} else {
- secondary
- };
+ primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
+ primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
+ secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
+ secondary.push((FooterAction::Back, 5 + 1 + 4));
+ }
+ let active_buttons =
+ if width >= crate::tui::screens::details::DETAILS_FOOTER_SPLIT_THRESHOLD {
+ if line_idx > 0 {
+ return;
+ }
+ let mut combined = primary;
+ combined.extend(secondary);
+ combined
+ } else if line_idx == 0 {
+ primary
+ } else {
+ secondary
+ };
let sep = 3_u16;
let total_w: u16 = active_buttons.iter().map(|(_, w)| *w).sum::<u16>()
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index 8894242..e7e9d01 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -239,26 +239,37 @@ pub fn confirmation(
Paragraph::new(summary.to_vec()).alignment(Alignment::Center),
sections[0],
);
+ use ratatui::style::Color;
+ let confirm_btn_style = if confirm_selected {
+ if basic_terminal {
+ theme.text.add_modifier(Modifier::REVERSED | Modifier::BOLD)
+ } else {
+ Style::default()
+ .bg(theme.accent.fg.unwrap_or(Color::Cyan))
+ .fg(theme.crust.fg.unwrap_or(Color::Black))
+ .add_modifier(Modifier::BOLD)
+ }
+ } else {
+ theme.subtext1
+ };
+
+ let cancel_btn_style = if !confirm_selected {
+ if basic_terminal {
+ theme.text.add_modifier(Modifier::REVERSED | Modifier::BOLD)
+ } else {
+ Style::default()
+ .bg(theme.surface1.fg.unwrap_or(Color::DarkGray))
+ .fg(theme.text.fg.unwrap_or(Color::White))
+ .add_modifier(Modifier::BOLD)
+ }
+ } else {
+ theme.subtext1
+ };
- let selected_style = selection_style(theme, basic_terminal);
let actions = vec![
- Span::styled(
- " Download ",
- if confirm_selected {
- selected_style
- } else {
- theme.text_dim
- },
- ),
+ Span::styled(" [ Download ] ", confirm_btn_style),
Span::raw(" "),
- Span::styled(
- " Cancel ",
- if confirm_selected {
- theme.text_dim
- } else {
- selected_style
- },
- ),
+ Span::styled(" [ Cancel ] ", cancel_btn_style),
];
crate::tui::widgets::render_modal_footer(frame, sections[1], actions, theme);
}
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 99e5574..6e24a8f 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -73,9 +73,42 @@ impl DetailsLayoutTier {
let content_rows = metadata_rows + title_rows.saturating_sub(1) + synopsis_rows;
(content_rows as u16 + 2).clamp(minimum, maximum)
}
-
pub(crate) fn footer_height(self, width: u16) -> u16 {
- if width >= 86 { 1 } else { 2 }
+ if width >= DETAILS_FOOTER_SPLIT_THRESHOLD {
+ 1
+ } else {
+ 2
+ }
+ }
+}
+
+pub const DETAILS_FOOTER_SPLIT_THRESHOLD: u16 = 80;
+
+pub(crate) fn selector_pane_constraints(
+ visible_panes: &[crate::tui::state::DetailsPane],
+) -> Vec<Constraint> {
+ use crate::tui::state::DetailsPane;
+ match visible_panes.len() {
+ 0 => Vec::new(),
+ 1 => vec![Constraint::Min(20)],
+ 2 => {
+ if visible_panes.contains(&DetailsPane::Languages) {
+ vec![Constraint::Length(18), Constraint::Min(26)]
+ } else if visible_panes.contains(&DetailsPane::Seasons)
+ && visible_panes.contains(&DetailsPane::Episodes)
+ {
+ vec![Constraint::Length(16), Constraint::Min(30)]
+ } else {
+ vec![Constraint::Length(18), Constraint::Min(24)]
+ }
+ }
+ _ => {
+ vec![
+ Constraint::Length(18),
+ Constraint::Length(14),
+ Constraint::Min(26),
+ ]
+ }
}
}
@@ -486,16 +519,6 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
}
}
- if state.favorites_available() {
- metadata.push(
- if is_favorited {
- "[f] Unfavorite"
- } else {
- "[f] Favorite"
- }
- .to_string(),
- );
- }
metadata.retain(|s| !s.trim().is_empty());
let meta_line = Line::from(vec![Span::styled(
metadata.join(" • "),
@@ -638,15 +661,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let selector_chunks = if visible_selector_panes.is_empty() {
Vec::new()
} else {
- Layout::horizontal(vec![
- Constraint::Ratio(
- 1,
- visible_selector_panes.len() as u32
- );
- visible_selector_panes.len()
- ])
- .split(selector_area)
- .to_vec()
+ Layout::horizontal(selector_pane_constraints(&visible_selector_panes))
+ .split(selector_area)
+ .to_vec()
};
let mut lang_area = None;
@@ -1035,6 +1052,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.get("sourceCount")
.and_then(|value| value.as_u64())
.unwrap_or(0);
+ let is_compact = streams_area.width < 76;
+ let is_wide = streams_area.width > 110;
let stream_width = streams_area.width.saturating_sub(6) as usize;
// 1. Pointer (2 chars)
@@ -1047,13 +1066,12 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
state.basic_terminal,
));
- // 3. File Size (format!("{:>8} ") = 10 chars)
+ // 3. File Size (format!("{:>7} ") = 9 chars)
stream_spans.push(Span::styled(
- format!("{size_formatted:>8} "),
+ format!("{size_formatted:>7} "),
primary_style,
));
- // 4. Codecs / Media Tags (format!("{:<14} ") = 15 chars)
let codec_str = codec.to_uppercase();
let tags = extract_media_tags(raw_release_title, &codec_str);
let mut tag_parts = Vec::new();
@@ -1073,13 +1091,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
let sep = if state.basic_terminal { " - " } else { " · " };
let tags_or_codec = tag_parts.join(sep);
- let tags_display = crate::tui::text::truncate_width(&tags_or_codec, 14);
- stream_spans.push(Span::styled(
- format!("{tags_display:<14} "),
- secondary_style,
- ));
- // 5. Duration / Info column (format!("{:<8} ") = 9 chars)
let duration_col = if is_fourk && duration == 0 && source_count > 0 {
format!(
"{source_count} mirr{}",
@@ -1088,81 +1100,163 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
} else {
duration_str.clone()
};
- let duration_display = crate::tui::text::truncate_width(&duration_col, 8);
- stream_spans.push(Span::styled(
- format!("{duration_display:<8} "),
- secondary_style,
- ));
- // 6. Uploader / Release Title (cleanly truncated to remaining width)
- let used_prefix_width = stream_spans
- .iter()
- .map(|s| crate::tui::text::width(s.content.as_ref()))
- .sum::<usize>();
- let remaining = stream_width.saturating_sub(used_prefix_width);
-
- if remaining > 0 {
- if is_addon {
- let has_lang = language != "Unknown" && !language.is_empty();
- if has_lang && remaining >= 24 {
- let lang_str = format!(
- "{} ",
- crate::tui::text::pad_to_width(&language, 10)
- );
- let lang_len = crate::tui::text::width(&lang_str);
- let title_avail = remaining.saturating_sub(lang_len);
- let title_trunc = crate::tui::text::truncate_width(
- &release_title,
- title_avail,
- );
- stream_spans.push(Span::styled(lang_str, secondary_style));
- stream_spans.push(Span::styled(title_trunc, primary_style));
+ if is_compact {
+ // 4. Codec (format!("{:<5} ") = 6 chars)
+ let codec_display = crate::tui::text::truncate_width(&codec_str, 5);
+ stream_spans.push(Span::styled(
+ format!("{codec_display:<5} "),
+ secondary_style,
+ ));
+
+ // 5. Title (Flex Min 20)
+ let used_prefix = stream_spans
+ .iter()
+ .map(|s| crate::tui::text::width(s.content.as_ref()))
+ .sum::<usize>();
+ let remaining = stream_width.saturating_sub(used_prefix);
+ if remaining > 0 {
+ let title_trunc =
+ crate::tui::text::truncate_width(&release_title, remaining);
+ stream_spans.push(Span::styled(title_trunc, primary_style));
+ }
+ } else if is_wide {
+ // 4. Extended Tags (format!("{:<22} ") = 23 chars)
+ let tags_display = crate::tui::text::truncate_width(&tags_or_codec, 22);
+ stream_spans.push(Span::styled(
+ format!("{tags_display:<22} "),
+ secondary_style,
+ ));
+
+ // 5. Duration (format!("{:<8} ") = 9 chars)
+ let duration_display =
+ crate::tui::text::truncate_width(&duration_col, 8);
+ stream_spans.push(Span::styled(
+ format!("{duration_display:<8} "),
+ secondary_style,
+ ));
+
+ // 6. Uploader (format!("{:<14} ") = 16 chars)
+ let uploader_display =
+ if upload_by != "Unknown" && !upload_by.is_empty() {
+ format!(
+ "{:<14} ",
+ crate::tui::text::truncate_width(&upload_by, 14)
+ )
} else {
- let title_trunc =
- crate::tui::text::truncate_width(&release_title, remaining);
- stream_spans.push(Span::styled(title_trunc, primary_style));
- }
- } else if is_fourk {
- let has_lang = language != "Unknown" && !language.is_empty();
- if has_lang {
- let lang_trunc =
- crate::tui::text::truncate_width(&language, remaining);
- stream_spans.push(Span::styled(lang_trunc, secondary_style));
- }
- } else {
- let has_uploader = upload_by != "Unknown" && !upload_by.is_empty();
- let has_title =
- !release_title.is_empty() && release_title != upload_by;
-
- if has_uploader && has_title && remaining >= 24 {
- let uploader_width = crate::tui::text::width(&upload_by);
- let title_avail = remaining.saturating_sub(uploader_width + 2);
- if title_avail >= 8 {
+ format!("{:<16}", "")
+ };
+ stream_spans.push(Span::styled(uploader_display, secondary_style));
+
+ // 7. Title (Flex)
+ let used_prefix = stream_spans
+ .iter()
+ .map(|s| crate::tui::text::width(s.content.as_ref()))
+ .sum::<usize>();
+ let remaining = stream_width.saturating_sub(used_prefix);
+ if remaining > 0 {
+ let title_trunc =
+ crate::tui::text::truncate_width(&release_title, remaining);
+ stream_spans.push(Span::styled(title_trunc, primary_style));
+ }
+ } else {
+ // Standard (76..=110 cols)
+ // 4. Media Tags (format!("{:<14} ") = 15 chars)
+ let tags_display = crate::tui::text::truncate_width(&tags_or_codec, 14);
+ stream_spans.push(Span::styled(
+ format!("{tags_display:<14} "),
+ secondary_style,
+ ));
+
+ // 5. Duration (format!("{:<8} ") = 9 chars)
+ let duration_display =
+ crate::tui::text::truncate_width(&duration_col, 8);
+ stream_spans.push(Span::styled(
+ format!("{duration_display:<8} "),
+ secondary_style,
+ ));
+
+ // 6. Uploader / Release Title (cleanly truncated to remaining width)
+ let used_prefix_width = stream_spans
+ .iter()
+ .map(|s| crate::tui::text::width(s.content.as_ref()))
+ .sum::<usize>();
+ let remaining = stream_width.saturating_sub(used_prefix_width);
+
+ if remaining > 0 {
+ if is_addon {
+ let has_lang = language != "Unknown" && !language.is_empty();
+ if has_lang && remaining >= 24 {
+ let lang_str = format!(
+ "{} ",
+ crate::tui::text::pad_to_width(&language, 10)
+ );
+ let lang_len = crate::tui::text::width(&lang_str);
+ let title_avail = remaining.saturating_sub(lang_len);
let title_trunc = crate::tui::text::truncate_width(
&release_title,
title_avail,
);
- stream_spans.push(Span::styled(
- format!("{upload_by} "),
- secondary_style,
- ));
- stream_spans
- .push(Span::styled(title_trunc, secondary_style));
+ stream_spans.push(Span::styled(lang_str, secondary_style));
+ stream_spans.push(Span::styled(title_trunc, primary_style));
} else {
+ let title_trunc = crate::tui::text::truncate_width(
+ &release_title,
+ remaining,
+ );
+ stream_spans.push(Span::styled(title_trunc, primary_style));
+ }
+ } else if is_fourk {
+ let has_lang = language != "Unknown" && !language.is_empty();
+ if has_lang {
+ let lang_trunc =
+ crate::tui::text::truncate_width(&language, remaining);
+ stream_spans
+ .push(Span::styled(lang_trunc, secondary_style));
+ }
+ } else {
+ let has_uploader =
+ upload_by != "Unknown" && !upload_by.is_empty();
+ let has_title =
+ !release_title.is_empty() && release_title != upload_by;
+
+ if has_uploader && has_title && remaining >= 24 {
+ let uploader_width = crate::tui::text::width(&upload_by);
+ let title_avail =
+ remaining.saturating_sub(uploader_width + 2);
+ if title_avail >= 8 {
+ let title_trunc = crate::tui::text::truncate_width(
+ &release_title,
+ title_avail,
+ );
+ stream_spans.push(Span::styled(
+ format!("{upload_by} "),
+ secondary_style,
+ ));
+ stream_spans
+ .push(Span::styled(title_trunc, secondary_style));
+ } else {
+ let uploader_trunc = crate::tui::text::truncate_width(
+ &upload_by, remaining,
+ );
+ stream_spans.push(Span::styled(
+ uploader_trunc,
+ secondary_style,
+ ));
+ }
+ } else if has_uploader {
let uploader_trunc =
crate::tui::text::truncate_width(&upload_by, remaining);
stream_spans
.push(Span::styled(uploader_trunc, secondary_style));
+ } else if has_title {
+ let title_trunc = crate::tui::text::truncate_width(
+ &release_title,
+ remaining,
+ );
+ stream_spans
+ .push(Span::styled(title_trunc, secondary_style));
}
- } else if has_uploader {
- let uploader_trunc =
- crate::tui::text::truncate_width(&upload_by, remaining);
- stream_spans
- .push(Span::styled(uploader_trunc, secondary_style));
- } else if has_title {
- let title_trunc =
- crate::tui::text::truncate_width(&release_title, remaining);
- stream_spans.push(Span::styled(title_trunc, secondary_style));
}
}
}
@@ -1203,6 +1297,12 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
),
];
lines.push(Line::from(header_spans));
+ if i == 0 {
+ lines.push(Line::from(stream_table_header_spans(
+ streams_area.width,
+ theme,
+ )));
+ }
}
lines.push(stream_line);
ListItem::new(lines)
@@ -1216,7 +1316,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let rendered_position = selected_idx.map_or(0, |selected| {
let mut headings = 0;
let mut previous: Option<&'static str> = None;
- for file in list.iter().take(selected.saturating_add(1)) {
+ for (i, file) in list.iter().take(selected.saturating_add(1)).enumerate() {
let resolution = file
.get("resolution")
.and_then(|value| value.as_i64())
@@ -1224,6 +1324,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let label = resolution_label(resolution);
if previous != Some(label) {
headings += 1;
+ if i == 0 {
+ headings += 1;
+ }
previous = Some(label);
}
}
@@ -1322,7 +1425,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
let (mut primary_footer, secondary_footer) = details_footer(state, theme, area.width);
- let footer_p = if area.width >= 70 {
+ let footer_p = if area.width >= DETAILS_FOOTER_SPLIT_THRESHOLD {
primary_footer.extend(secondary_footer);
Paragraph::new(Line::from(primary_footer))
} else {
@@ -1427,19 +1530,50 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
pub(crate) fn season_confirm_summary(state: &AppState) -> Vec<String> {
+ let title = state
+ .selected_details
+ .as_ref()
+ .and_then(|d| d.get("title"))
+ .and_then(|t| t.as_str())
+ .unwrap_or("Series");
let season_idx = state.selected_season;
let eps_count = if season_idx > 0 && season_idx <= state.available_episode_numbers.len() {
state.available_episode_numbers[season_idx - 1].len()
} else {
0
};
- vec![
- format!("Season {season_idx}"),
- format!("{eps_count} episodes"),
- ]
+ let mut summary = vec![format!(
+ "{title} • Season {season_idx} ({eps_count} Episodes)"
+ )];
+ if let Some(stream) = selected_stream_summary(state) {
+ summary.push(format!("Quality: {stream}"));
+ }
+ let dest = state
+ .download_dir
+ .as_ref()
+ .map(|p| p.to_string_lossy().to_string())
+ .unwrap_or_else(|| {
+ crate::service::resolve_download_dir(None)
+ .to_string_lossy()
+ .to_string()
+ });
+ summary.push(format!("Save to: {dest}"));
+ summary
}
pub(crate) fn episode_confirm_summary(state: &AppState) -> Vec<String> {
+ let title = state
+ .selected_details
+ .as_ref()
+ .and_then(|d| d.get("title"))
+ .and_then(|t| t.as_str())
+ .unwrap_or("Media");
+ let year = state
+ .selected_details
+ .as_ref()
+ .and_then(|d| d.get("releaseDate").or_else(|| d.get("year")))
+ .and_then(|y| y.as_str())
+ .unwrap_or("");
let season_idx = state.selected_season;
let ep_idx = state.selected_episode;
let type_val = state
@@ -1448,13 +1582,25 @@ pub(crate) fn episode_confirm_summary(state: &AppState) -> Vec<String> {
.map(crate::tui::state::stype)
.unwrap_or(1);
let mut summary = if type_val == 2 {
- vec![format!("Season {season_idx} · Episode {ep_idx}")]
+ vec![format!("{title} • Season {season_idx} Episode {ep_idx}")]
+ } else if !year.is_empty() && year != "N/A" {
+ vec![format!("{title} ({year}) • Movie")]
} else {
- vec!["Download this movie".to_string()]
+ vec![format!("{title} • Movie")]
};
if let Some(stream) = selected_stream_summary(state) {
- summary.push(stream);
+ summary.push(format!("Quality: {stream}"));
}
+ let dest = state
+ .download_dir
+ .as_ref()
+ .map(|p| p.to_string_lossy().to_string())
+ .unwrap_or_else(|| {
+ crate::service::resolve_download_dir(None)
+ .to_string_lossy()
+ .to_string()
+ });
+ summary.push(format!("Save to: {dest}"));
summary
}
@@ -1740,9 +1886,29 @@ fn render_workflow(
);
}
+fn stream_table_header_spans(width: u16, theme: &Theme) -> Vec<Span<'static>> {
+ let header_style = theme.overlay0.add_modifier(Modifier::BOLD);
+ if width < 76 {
+ vec![Span::styled(
+ " RES SIZE CODEC RELEASE",
+ header_style,
+ )]
+ } else if width > 110 {
+ vec![Span::styled(
+ " RES SIZE MEDIA TAGS DURATION UPLOADER RELEASE",
+ header_style,
+ )]
+ } else {
+ vec![Span::styled(
+ " RES SIZE MEDIA TAGS DURATION UPLOADER / RELEASE",
+ header_style,
+ )]
+ }
+}
+
fn footer_group(
key: &'static str,
- action: &'static str,
+ action: &str,
prominent: bool,
theme: &Theme,
) -> Vec<Span<'static>> {
@@ -1751,7 +1917,7 @@ fn footer_group(
Span::styled(key, theme.shortcut),
Span::styled("] ", theme.overlay0),
Span::styled(
- action,
+ action.to_string(),
if prominent {
theme.text
} else {
@@ -1767,9 +1933,39 @@ fn details_footer(
theme: &Theme,
width: u16,
) -> (Vec<Span<'static>>, Vec<Span<'static>>) {
- let compact = width < 80;
+ 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.get("title").and_then(|t| t.as_str()).unwrap_or("");
+ let type_val = crate::tui::state::stype(details);
+ let year = details
+ .get("releaseDate")
+ .or_else(|| details.get("year"))
+ .or_else(|| details.get("releaseInfo"))
+ .and_then(|y| y.as_str())
+ .unwrap_or("N/A");
+ state
+ .favorites
+ .is_favorite(&crate::models::SubjectIdentity {
+ provider: subject_provider(state, details_subject_id).cache_key(),
+ subject_id: details_subject_id,
+ title,
+ stype: type_val,
+ release_year: year,
+ })
+ } else {
+ false
+ };
+ let fav_label = if is_favorited {
+ "Unfavorite"
+ } else {
+ "Favorite"
+ };
let mut primary = Vec::new();
let mut secondary = Vec::new();
@@ -1788,20 +1984,22 @@ fn details_footer(
false,
theme,
));
- secondary.extend(footer_group("f", "Favorite", false, theme));
- secondary.extend(footer_group(
- "s",
- if compact { "Subs" } else { "Subtitles" },
- false,
- theme,
- ));
+ secondary.extend(footer_group("f", fav_label, false, theme));
+ if !state.subtitle_list.is_empty() {
+ secondary.extend(footer_group(
+ "s",
+ if compact { "Subs" } else { "Subtitles" },
+ false,
+ theme,
+ ));
+ }
secondary.extend(footer_group("Esc", "Back", false, theme));
} else if is_languages {
primary.extend(footer_group("Enter", "Select", true, theme));
- primary.extend(footer_group("f", "Favorite", false, theme));
+ primary.extend(footer_group("f", fav_label, false, theme));
secondary.extend(footer_group("Tab", "Streams", false, theme));
secondary.extend(footer_group("Esc", "Back", false, theme));
- } else {
+ } else if is_seasons {
primary.extend(footer_group("Enter", "Select", true, theme));
primary.extend(footer_group(
"d",
@@ -1813,11 +2011,30 @@ fn details_footer(
false,
theme,
));
- primary.extend(footer_group("f", "Favorite", false, theme));
+ primary.extend(footer_group("f", fav_label, false, theme));
+ secondary.extend(footer_group("Tab", "Streams", false, theme));
+ secondary.extend(footer_group("Esc", "Back", false, theme));
+ } else if is_episodes {
+ primary.extend(footer_group("Enter", "Select", true, theme));
+ primary.extend(footer_group(
+ "d",
+ if compact {
+ "Download"
+ } else {
+ "Download Episode"
+ },
+ false,
+ theme,
+ ));
+ primary.extend(footer_group("f", fav_label, false, theme));
+ secondary.extend(footer_group("Tab", "Streams", false, theme));
+ secondary.extend(footer_group("Esc", "Back", false, theme));
+ } else {
+ primary.extend(footer_group("Enter", "Select", true, theme));
+ primary.extend(footer_group("f", fav_label, false, theme));
secondary.extend(footer_group("Tab", "Streams", false, theme));
secondary.extend(footer_group("Esc", "Back", false, theme));
}
-
if let Some(last) = secondary.last_mut() {
*last = Span::raw("");
}
@@ -2032,8 +2249,9 @@ mod tests {
let theme = Theme::mocha();
let mut state = AppState::default();
- // Streams pane
+ // Streams pane with subtitles
state.details_pane = crate::tui::state::DetailsPane::Streams;
+ state.subtitle_list = vec![("English".to_string(), "http://sub".to_string())];
let (primary, secondary) = details_footer(&state, &theme, 100);
let mut all_spans = primary;
all_spans.extend(secondary);
@@ -2056,6 +2274,18 @@ mod tests {
assert!(footer_text.contains("[f] Favorite"));
assert!(footer_text.contains("[Tab] Streams"));
assert!(footer_text.contains("[Esc] Back"));
+
+ // Episodes pane
+ state.details_pane = crate::tui::state::DetailsPane::Episodes;
+ let (primary, secondary) = details_footer(&state, &theme, 100);
+ let mut all_spans = primary;
+ all_spans.extend(secondary);
+ let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();
+ assert!(footer_text.contains("[Enter] Select"));
+ assert!(footer_text.contains("[d] Download Episode"));
+ assert!(footer_text.contains("[f] Favorite"));
+ assert!(footer_text.contains("[Tab] Streams"));
+ assert!(footer_text.contains("[Esc] Back"));
}
#[test]
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 339ebd7..97e0fc0 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -189,7 +189,6 @@ fn render_search_state(
);
let ctrl_p = crate::tui::text::ctrl_key("P");
- let ctrl_u = crate::tui::text::ctrl_key("U");
let bullet = if state.basic_terminal {
" - "
} else {
@@ -244,6 +243,10 @@ fn render_search_state(
format!("No items found for {}", catalog.label)
} else if state.search_query.trim().eq_ignore_ascii_case("/history") {
"No watch history found".to_string()
+ } else if state.search_query.trim().eq_ignore_ascii_case("/favorites")
+ || state.search_query.trim().eq_ignore_ascii_case("/fav")
+ {
+ "No favorites saved yet".to_string()
} else if !state.search_query.trim().is_empty() {
format!("No matches for “{query}”")
} else {
@@ -251,46 +254,64 @@ fn render_search_state(
};
lines.push(Line::from(vec![
Span::styled(format!("{symbol} "), theme.text_dim),
- Span::styled(msg, theme.text),
+ Span::styled(msg, theme.text.add_modifier(Modifier::BOLD)),
]));
lines.push(Line::from(""));
- if area.width < 76 {
- lines.push(Line::from(vec![
+
+ let pills = if state.is_tv_mode {
+ vec![
+ Span::styled("[", theme.text_dim),
+ Span::styled("/tv", theme.shortcut),
+ Span::styled("] ", theme.text_dim),
+ Span::styled("Playlists", theme.subtext1),
+ Span::styled(bullet, theme.text_dim),
+ Span::styled("[", theme.text_dim),
+ Span::styled("r", theme.shortcut),
+ Span::styled("] ", theme.text_dim),
+ Span::styled("Reload Playlist", theme.subtext1),
+ Span::styled(bullet, theme.text_dim),
+ Span::styled("[", theme.text_dim),
+ Span::styled("c", theme.shortcut),
+ Span::styled("] ", theme.text_dim),
+ Span::styled("Clear", theme.subtext1),
+ ]
+ } else if state.is_addon_mode {
+ vec![
Span::styled("[", theme.text_dim),
Span::styled(&ctrl_p, theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Switch provider", theme.text_dim),
- ]));
- lines.push(Line::from(vec![
+ Span::styled("Change Catalog", theme.subtext1),
+ Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
- Span::styled("/browse", theme.shortcut),
+ Span::styled("/addons", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Browse categories", theme.text_dim),
- ]));
- lines.push(Line::from(vec![
+ Span::styled("Manage Addons", theme.subtext1),
+ Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
- Span::styled(&ctrl_u, theme.shortcut),
+ Span::styled("c", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Clear", theme.text_dim),
- ]));
+ Span::styled("Clear", theme.subtext1),
+ ]
} else {
- lines.push(Line::from(vec![
+ vec![
Span::styled("[", theme.text_dim),
Span::styled(&ctrl_p, theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Switch provider", theme.text_dim),
+ Span::styled("Switch Provider", theme.subtext1),
Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
Span::styled("/browse", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Browse categories", theme.text_dim),
+ Span::styled("Categories", theme.subtext1),
Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
- Span::styled(&ctrl_u, theme.shortcut),
+ Span::styled("c", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Clear", theme.text_dim),
- ]));
- }
+ Span::styled("Clear", theme.subtext1),
+ ]
+ };
+
+ lines.push(Line::from(pills));
}
SearchViewState::Error => {
let symbol = if state.basic_terminal { "!" } else { "×" };
@@ -301,44 +322,42 @@ fn render_search_state(
"Search request failed"
}
});
- let wrap_width = card_width.saturating_sub(6).max(10) as usize;
+ let wrap_width = card_width.saturating_sub(8).max(10) as usize;
let wrapped_err_lines = crate::tui::text::wrap_text(err_text, wrap_width);
- if wrapped_err_lines.is_empty() {
- lines.push(Line::from(vec![
- Span::styled(format!("{symbol} "), theme.error),
- Span::styled("Search request failed", theme.error),
- ]));
- } else {
- for (idx, eline) in wrapped_err_lines.into_iter().enumerate() {
- if idx == 0 {
- lines.push(Line::from(vec![
- Span::styled(format!("{symbol} "), theme.error),
- Span::styled(eline, theme.error),
- ]));
- } else {
- lines.push(Line::from(vec![
- Span::styled(" ", theme.error),
- Span::styled(eline, theme.error),
- ]));
- }
+
+ lines.push(Line::from(vec![
+ Span::styled(format!("{symbol} "), theme.error),
+ Span::styled(
+ "Search Request Error",
+ theme.error.add_modifier(Modifier::BOLD),
+ ),
+ ]));
+ if !wrapped_err_lines.is_empty() {
+ for eline in wrapped_err_lines {
+ lines.push(Line::from(vec![Span::styled(eline, theme.subtext1)]));
}
+ } else {
+ lines.push(Line::from(vec![Span::styled(
+ "Unable to complete search request with the current provider.",
+ theme.subtext1,
+ )]));
}
lines.push(Line::from(""));
lines.push(Line::from(vec![
Span::styled("[", theme.text_dim),
Span::styled("r", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Retry request", theme.text_dim),
+ Span::styled("Retry", theme.subtext1),
Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
Span::styled(&ctrl_p, theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Switch provider", theme.text_dim),
+ Span::styled("Switch Provider", theme.subtext1),
Span::styled(bullet, theme.text_dim),
Span::styled("[", theme.text_dim),
Span::styled("Esc", theme.shortcut),
Span::styled("] ", theme.text_dim),
- Span::styled("Back", theme.text_dim),
+ Span::styled("Back", theme.subtext1),
]));
}
_ => return,
@@ -346,10 +365,17 @@ fn render_search_state(
let max_line_width = lines.iter().map(|l| l.width()).max().unwrap_or(0) as u16;
if matches!(view, SearchViewState::Error | SearchViewState::NoResults) {
- card_width = max_line_width.clamp(20, area.width.min(64));
+ card_width = (max_line_width + 4)
+ .clamp(32, area.width.saturating_sub(2))
+ .min(72);
}
- let card_height = (lines.len() as u16).min(area.height);
+ let is_boxed = matches!(view, SearchViewState::Error | SearchViewState::NoResults);
+ let card_height = if is_boxed {
+ (lines.len() as u16 + 2).min(area.height)
+ } else {
+ (lines.len() as u16).min(area.height)
+ };
let card = Rect {
x: area.x + area.width.saturating_sub(card_width) / 2,
y: area.y + area.height.saturating_sub(card_height) / 2,
@@ -357,13 +383,40 @@ fn render_search_state(
height: card_height,
};
- let alignment = if matches!(view, SearchViewState::Error | SearchViewState::NoResults) {
- Alignment::Left
+ if is_boxed && card.height >= 3 {
+ let (border_style, title_text, title_style) = if view == SearchViewState::Error {
+ (
+ theme.error,
+ " Error ",
+ theme.error.add_modifier(Modifier::BOLD),
+ )
+ } else {
+ (
+ theme.muted,
+ " No Results ",
+ theme.subtext1.add_modifier(Modifier::BOLD),
+ )
+ };
+ let block = Block::default()
+ .borders(Borders::ALL)
+ .border_type(crate::tui::overlay::border_type(state.basic_terminal))
+ .border_style(border_style)
+ .title(Line::from(vec![Span::styled(title_text, title_style)]))
+ .padding(ratatui::widgets::Padding::horizontal(1));
+ frame.render_widget(
+ Paragraph::new(lines)
+ .block(block)
+ .alignment(Alignment::Left),
+ card,
+ );
} else {
- Alignment::Center
- };
-
- frame.render_widget(Paragraph::new(lines).alignment(alignment), card);
+ let alignment = if matches!(view, SearchViewState::Error | SearchViewState::NoResults) {
+ Alignment::Left
+ } else {
+ Alignment::Center
+ };
+ frame.render_widget(Paragraph::new(lines).alignment(alignment), card);
+ }
}
pub(crate) fn render_favorites_landing(
frame: &mut Frame,
@@ -1231,14 +1284,19 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let current_y =
inner_area.y + (visible_index as u16 * row_height).min(inner_area.height);
+ let gutter = 1_u16;
+ let col_x = inner_area.x + column * (metrics.col_width + gutter);
+ let col_w = if column + 1 == metrics.columns {
+ inner_area
+ .width
+ .saturating_sub(column * (metrics.col_width + gutter))
+ } else {
+ metrics.col_width
+ };
let item_area = Rect {
- x: inner_area.x + column * metrics.col_width,
+ x: col_x,
y: current_y,
- width: if column + 1 == metrics.columns {
- inner_area.width.saturating_sub(column * metrics.col_width)
- } else {
- metrics.col_width
- },
+ width: col_w,
height: metrics.poster_rows_eff,
};
@@ -1352,16 +1410,37 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
frame.render_widget(placeholder, p_area);
}
- let text_top_padding = text_area.height.saturating_sub(2) / 2;
- let text_layout = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Length(text_top_padding),
- Constraint::Length(1),
- Constraint::Length(1),
- Constraint::Min(0),
- ])
- .split(text_area);
+ let text_height = text_area.height;
+ let (text_top_padding, use_three_rows) = if text_height >= 4 {
+ ((text_height.saturating_sub(3)) / 2, true)
+ } else if text_height == 3 {
+ (0, true)
+ } else {
+ ((text_height.saturating_sub(2)) / 2, false)
+ };
+
+ let text_layout = if use_three_rows {
+ Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Length(text_top_padding),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ Constraint::Min(0),
+ ])
+ .split(text_area)
+ } else {
+ Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Length(text_top_padding),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ Constraint::Min(0),
+ ])
+ .split(text_area)
+ };
let title_style = if is_selected {
if is_editing {
@@ -1382,9 +1461,6 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
stype: res.stype,
release_year: &res.release_year,
});
- let title_reserved = if is_favorited { 6 } else { 4 };
- let max_title_width = text_area.width.saturating_sub(title_reserved) as usize;
- let display_title = crate::tui::text::truncate_width(&res.title, max_title_width);
let mut type_tag = if state.is_tv_mode || res.stype == 3 {
"TV Channel".to_string()
@@ -1401,32 +1477,80 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
type_tag = "Unknown".to_string();
}
- let mut title_spans = vec![ratatui::text::Span::raw(" ")];
+ // Row 1: Title + Right-pinned Resolution Badge
+ let res_badge = if !is_history {
+ crate::tui::widgets::badge::extract_resolution(&res.title, None)
+ } else {
+ None
+ };
+ let badge_spans = res_badge.map(|r| {
+ crate::tui::widgets::badge::resolution_badge_spans(
+ r,
+ theme,
+ state.basic_terminal,
+ )
+ });
+ let badge_width = badge_spans.as_ref().map_or(0, |spans| {
+ spans
+ .iter()
+ .map(|s| crate::tui::text::width(s.content.as_ref()))
+ .sum::<usize>()
+ });
+
+ let title_reserved = if is_favorited { 3 } else { 1 }
+ + badge_width
+ + if badge_width > 0 { 1 } else { 0 };
+ let max_title_width = (text_area.width as usize)
+ .saturating_sub(title_reserved)
+ .max(4);
+ let display_title = crate::tui::text::truncate_width(&res.title, max_title_width);
+
+ let mut row1_spans = vec![ratatui::text::Span::raw(" ")];
if is_favorited {
- title_spans.push(ratatui::text::Span::styled(
+ row1_spans.push(ratatui::text::Span::styled(
if state.basic_terminal { "* " } else { "★ " },
theme.rating,
));
}
- title_spans.push(ratatui::text::Span::styled(display_title, title_style));
- let title_line = ratatui::text::Line::from(title_spans);
+ row1_spans.push(ratatui::text::Span::styled(
+ display_title.clone(),
+ title_style,
+ ));
+
+ if let Some(b_spans) = badge_spans {
+ let title_actual_w = 1
+ + if is_favorited { 2 } else { 0 }
+ + crate::tui::text::width(&display_title);
+ let gap =
+ (text_area.width as usize).saturating_sub(title_actual_w + badge_width);
+ if gap > 0 {
+ row1_spans.push(ratatui::text::Span::raw(" ".repeat(gap)));
+ }
+ row1_spans.extend(b_spans);
+ }
+
if text_layout[1].height > 0 {
- frame.render_widget(Paragraph::new(title_line), text_layout[1]);
+ frame.render_widget(
+ Paragraph::new(ratatui::text::Line::from(row1_spans)),
+ text_layout[1],
+ );
}
- let mut info_spans = vec![];
+ // Row 2 & Row 3 Metadata
+ let mut row2_spans = vec![ratatui::text::Span::raw(" ")];
+ let mut row3_spans = vec![ratatui::text::Span::raw(" ")];
if is_history {
if !type_tag.is_empty() {
- info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ row2_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
if res.season > 0 {
- info_spans.push(ratatui::text::Span::styled(
+ row2_spans.push(ratatui::text::Span::styled(
format!("S{:02}E{:02}", res.season, res.episode),
theme.text,
));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
if let Some(hist) = state.history.get_item(
@@ -1438,87 +1562,78 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
) {
if hist.is_in_progress() {
let (filled, empty) = hist.progress_bar_parts(8);
- info_spans.push(ratatui::text::Span::styled(
- filled,
- theme.accent.add_modifier(ratatui::style::Modifier::BOLD),
- ));
- info_spans.push(ratatui::text::Span::styled(empty, theme.text_dim));
-
+ let mut progress_spans = vec![
+ ratatui::text::Span::styled(
+ filled,
+ theme.accent.add_modifier(ratatui::style::Modifier::BOLD),
+ ),
+ ratatui::text::Span::styled(empty, theme.text_dim),
+ ];
let pct = hist
.progress_percentage()
.map(|p| format!(" {:.0}%", p))
.unwrap_or_default();
- info_spans.push(ratatui::text::Span::styled(pct, theme.text));
+ progress_spans.push(ratatui::text::Span::styled(pct, theme.text));
if let Some(r) = hist.formatted_remaining() {
- info_spans.push(ratatui::text::Span::styled(
+ progress_spans.push(ratatui::text::Span::styled(
format!(" ({r})"),
theme.text_dim,
));
}
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- info_spans.push(ratatui::text::Span::styled(
- format!("Watched {}", hist.formatted_relative_time()),
- theme.text_dim,
- ));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+
+ if use_three_rows {
+ row3_spans.extend(progress_spans);
+ row3_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ row3_spans.push(ratatui::text::Span::styled(
+ format!("Watched {}", hist.formatted_relative_time()),
+ theme.text_dim,
+ ));
+ } else {
+ row2_spans.extend(progress_spans);
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ }
} else if hist.completed {
- info_spans.push(ratatui::text::Span::styled(
+ let comp_span = ratatui::text::Span::styled(
if state.basic_terminal {
"[Completed]"
} else {
"[✓ Completed]"
},
theme.text_dim,
- ));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- info_spans.push(ratatui::text::Span::styled(
- format!("Watched {}", hist.formatted_relative_time()),
- theme.text_dim,
- ));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ );
+ if use_three_rows {
+ row3_spans.push(comp_span);
+ row3_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ row3_spans.push(ratatui::text::Span::styled(
+ format!("Watched {}", hist.formatted_relative_time()),
+ theme.text_dim,
+ ));
+ } else {
+ row2_spans.push(comp_span);
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ }
}
}
- info_spans.push(crate::tui::widgets::badge::provider_badge_span(
+ row2_spans.push(crate::tui::widgets::badge::provider_badge_span(
res.provider,
theme,
state.basic_terminal,
));
} else {
- if let Some(resolution) =
- crate::tui::widgets::badge::extract_resolution(&res.title, None)
- {
- info_spans.extend(crate::tui::widgets::badge::resolution_badge_spans(
- resolution,
- theme,
- state.basic_terminal,
- ));
- }
-
- macro_rules! push_year {
- () => {
- if res.release_year != "Unknown" && !res.release_year.is_empty() {
- info_spans
- .push(ratatui::text::Span::styled(&res.release_year, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- }
- };
- }
-
- if is_selected {
- if let Some(meta) = &state.search_preview {
+ if let Some(meta) = &state.search_preview {
+ if is_selected {
let rating = meta
.get("imdbRating")
.or_else(|| meta.get("imdbRatingValue"))
.and_then(|v| v.as_str());
if let Some(r) = rating {
let star = if state.basic_terminal { "* " } else { "★ " };
- info_spans.push(ratatui::text::Span::styled(star, theme.rating));
- info_spans.push(ratatui::text::Span::styled(r, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ row2_spans.push(ratatui::text::Span::styled(star, theme.rating));
+ row2_spans.push(ratatui::text::Span::styled(r, theme.text));
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
- push_year!();
let mut g_names = vec![];
if let Some(genres) = meta.get("genres").and_then(|g| g.as_array()) {
@@ -1532,54 +1647,60 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.collect();
}
if !g_names.is_empty() {
- info_spans.push(ratatui::text::Span::styled(
- g_names.join(" • "),
- theme.text,
- ));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ let g_str = g_names.join(", ");
+ let g_trunc = crate::tui::text::truncate_width(
+ &g_str,
+ text_area.width.saturating_sub(2) as usize,
+ );
+ row3_spans
+ .push(ratatui::text::Span::styled(g_trunc, theme.subtext1));
}
- info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
- } else if state.preview_loading {
- push_year!();
- info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
- let dots = match (state.tick_count / 4) % 4 {
- 0 => "",
- 1 => ".",
- 2 => "..",
- _ => "...",
- };
- info_spans.push(ratatui::text::Span::styled(
- format!("Loading{dots}"),
- theme.text_dim,
- ));
- } else {
- push_year!();
- info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
}
- } else {
- push_year!();
- info_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
+ } else if is_selected && state.preview_loading {
+ let dots = match (state.tick_count / 4) % 4 {
+ 0 => "",
+ 1 => ".",
+ 2 => "..",
+ _ => "...",
+ };
+ row3_spans.push(ratatui::text::Span::styled(
+ format!("Loading{dots}"),
+ theme.text_dim,
+ ));
}
- if !info_spans.is_empty() {
- info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+ if res.release_year != "Unknown" && !res.release_year.is_empty() {
+ row2_spans.push(ratatui::text::Span::styled(&res.release_year, theme.text));
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
- info_spans.push(crate::tui::widgets::badge::provider_badge_span(
+
+ row2_spans.push(ratatui::text::Span::styled(&type_tag, theme.text));
+ row2_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
+
+ row2_spans.push(crate::tui::widgets::badge::provider_badge_span(
res.provider,
theme,
state.basic_terminal,
));
}
- if text_layout[2].height > 0 && !info_spans.is_empty() {
- let mut padded = vec![ratatui::text::Span::raw(" ")];
- padded.extend(info_spans);
+ if text_layout[2].height > 0 && row2_spans.len() > 1 {
frame.render_widget(
- Paragraph::new(ratatui::text::Line::from(padded)),
+ Paragraph::new(ratatui::text::Line::from(row2_spans)),
text_layout[2],
);
}
+
+ if use_three_rows
+ && text_layout.len() > 3
+ && text_layout[3].height > 0
+ && row3_spans.len() > 1
+ {
+ frame.render_widget(
+ Paragraph::new(ratatui::text::Line::from(row3_spans)),
+ text_layout[3],
+ );
+ }
}
crate::tui::widgets::render_scrollbar(
@@ -2053,10 +2174,25 @@ fn render_search_suggestions(
}
crate::tui::clear_area(frame, container_area, theme);
- let container_block = Block::default()
+ let remaining_below = state
+ .search_suggestions
+ .len()
+ .saturating_sub(suggestion_offset + visible_count);
+ let mut container_block = Block::default()
.borders(Borders::ALL)
.border_type(crate::tui::overlay::border_type(state.basic_terminal))
.border_style(theme.border_focus);
+
+ if remaining_below > 0 {
+ let hint_text = if state.basic_terminal {
+ format!(" v (+{} more) ", remaining_below)
+ } else {
+ format!(" ▼ (+{} more) ", remaining_below)
+ };
+ container_block = container_block.title_bottom(
+ Line::from(vec![Span::styled(hint_text, theme.overlay1)]).alignment(Alignment::Right),
+ );
+ }
frame.render_widget(container_block, container_area);
for (row_idx, &(orig_idx, suggestion)) in visible_slice.iter().enumerate() {
@@ -2227,6 +2363,44 @@ mod tests {
assert!(!rendered.contains('├'));
assert!(!rendered.contains('└'));
}
+ #[test]
+ fn test_render_search_suggestions_overflow_cue() {
+ let backend = TestBackend::new(80, 24);
+ let mut terminal = Terminal::new(backend).unwrap();
+ let state = AppState {
+ input_mode: InputMode::Editing,
+ search_suggestions: (1..=10).map(|i| format!("Movie Title {i}")).collect(),
+ suggest_index: Some(0),
+ basic_terminal: false,
+ ..Default::default()
+ };
+ let theme = Theme::mocha();
+
+ terminal
+ .draw(|frame| {
+ let area = Rect::new(0, 0, 80, 24);
+ let search_bar = Rect::new(10, 2, 60, 3);
+ render_search_suggestions(
+ frame,
+ area,
+ search_bar,
+ &state,
+ &theme,
+ SearchViewState::Empty,
+ );
+ })
+ .unwrap();
+
+ let buffer = terminal.backend().buffer();
+ let mut rendered = String::new();
+ for y in 0..24 {
+ for x in 0..80 {
+ rendered.push_str(buffer[(x, y)].symbol());
+ }
+ rendered.push('\n');
+ }
+ assert!(rendered.contains("▼ (+4 more)"));
+ }
#[test]
fn test_landing_draw_hides_favorites_when_suggestions_open() {
diff --git a/src/tui/state.rs b/src/tui/state.rs
index c111a98..c235f05 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -47,17 +47,17 @@ pub struct ResultMetrics {
}
pub fn result_columns_for(width: u16) -> u16 {
- if width < 75 {
- return 1;
- }
- let by_width = if width >= 160 {
- 3
- } else if width >= 110 {
+ if width < 110 {
+ 1
+ } else if width < 160 {
2
+ } else if width < 220 {
+ 3
+ } else if width < 280 {
+ 4
} else {
- 1
- };
- by_width.clamp(1, width / 40).max(1)
+ 5
+ }
}
pub struct AppState {
@@ -459,7 +459,9 @@ impl AppState {
let poster_rows_eff = self.poster_rows.max(3).min(max_rows);
let row_height = poster_rows_eff.saturating_add(1).max(4);
let columns = crate::tui::state::result_columns_for(results_width);
- let col_width = results_width / columns;
+ let total_gutters = columns.saturating_sub(1);
+ let usable_width = results_width.saturating_sub(total_gutters);
+ let col_width = (usable_width / columns.max(1)).max(1);
let visible_rows = (results_height as usize / row_height as usize).max(1);
let visible_items = visible_rows * columns as usize;
ResultMetrics {
@@ -711,10 +713,16 @@ mod tests {
#[test]
fn columns_follow_width_tiers() {
+ assert_eq!(result_columns_for(60), 1);
assert_eq!(result_columns_for(80), 1);
assert_eq!(result_columns_for(110), 2);
+ assert_eq!(result_columns_for(159), 2);
assert_eq!(result_columns_for(160), 3);
- assert_eq!(result_columns_for(60), 1);
+ assert_eq!(result_columns_for(219), 3);
+ assert_eq!(result_columns_for(220), 4);
+ assert_eq!(result_columns_for(279), 4);
+ assert_eq!(result_columns_for(280), 5);
+ assert_eq!(result_columns_for(320), 5);
}
#[test]
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
index ae0467b..fd09126 100644
--- a/tests/tui_acceptance.rs
+++ b/tests/tui_acceptance.rs
@@ -756,16 +756,18 @@ async fn test_no_results_and_error_state_rendering_hints() {
// No results view
app.state_mut().active_screen = Screen::Home;
app.state_mut().input_mode = InputMode::Normal;
+ app.state_mut()
+ .set_mode(moviebox_tui::tui::state::AppMode::Streaming);
+ app.state_mut().active_provider = moviebox_tui::providers::models::ProviderKind::MovieBox;
app.state_mut()
.search_query
.set_content("nonexistent_movie_xyz");
app.state_mut().search_results.clear();
-
terminal.draw(|frame| app.draw(frame)).unwrap();
let content = terminal.backend().buffer().content();
let text: String = content.iter().map(|c| c.symbol()).collect();
- assert!(text.contains("Switch provider"));
- assert!(text.contains("Browse categories"));
+ assert!(text.contains("Switch Provider"));
+ assert!(text.contains("Categories"));
assert!(text.contains("Clear"));
// Error view
@@ -774,7 +776,7 @@ async fn test_no_results_and_error_state_rendering_hints() {
terminal.draw(|frame| app.draw(frame)).unwrap();
let content_err = terminal.backend().buffer().content();
let text_err: String = content_err.iter().map(|c| c.symbol()).collect();
- assert!(text_err.contains("Retry request"));
- assert!(text_err.contains("Switch provider"));
+ assert!(text_err.contains("Retry"));
+ assert!(text_err.contains("Switch Provider"));
assert!(text_err.contains("Back"));
}