Skip to content

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

refactor: remove TUI search prompt animation and update input submission logic

Samir Hossains9b3b5c08888b
diff --git a/src/tui/app.rs b/src/tui/app.rs
index e66cdf5..4e75975 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -573,6 +573,7 @@ impl App {
if self.state.auto_update && now.saturating_sub(self.state.last_update_check) > 3600 {
self.state.last_update_check = now;
+ self.state.manual_update_check = false;
self.persist_config();
self.action_sender.send(Action::CheckForUpdates).ok();
} else {
@@ -636,97 +637,6 @@ impl App {
self.state.dirty = true;
}
- if self.state.search_query.is_empty()
- && matches!(self.state.active_screen, crate::tui::state::Screen::Home)
- {
- let greeting = format!("Welcome back, {}", self.state.username);
-
- let prompts = if self.state.is_tv_mode {
- vec![
- "What live channel are you looking for?",
- "Try 'BBC', 'CNN', or 'ESPN'...",
- "Discover news, sports, or entertainment...",
- "Search your selected broadcast areas...",
- "Feeling bored? Find a live stream...",
- "Search live broadcast channels...",
- ]
- } else {
- vec![
- "What are you in the mood to watch?",
- "Try 'Oppenheimer', 'Titanic', or 'Interstellar'...",
- "Discover your next binge-worthy masterpiece...",
- "Search for blockbuster movies, hit shows, or anime...",
- "Feeling nostalgic? Search timeless classics...",
- "Explore trending titles for your movie night...",
- ]
- };
- let type_speed = 3;
- let del_speed = 1;
- let pause1 = 90;
- let pause2 = 15;
-
- let greeting_graphemes = crate::tui::text::grapheme_count(&greeting);
- let greeting_cycle = greeting_graphemes * type_speed
- + pause1
- + greeting_graphemes * del_speed
- + pause2;
- let mut total_ticks = 0;
- for p in prompts.iter() {
- let count = crate::tui::text::grapheme_count(p);
- total_ticks += count * type_speed + pause1 + count * del_speed + pause2;
- }
-
- let tick_u = self.state.tick_count as usize;
- let mut animated_text = String::new();
-
- if tick_u < greeting_cycle {
- let t = tick_u;
- let greeting_len = greeting_graphemes;
- let t_type = greeting_len * type_speed;
- let t_del = greeting_len * del_speed;
- let display_len = if t < t_type {
- t / type_speed
- } else if t < t_type + pause1 {
- greeting_len
- } else if t < t_type + pause1 + t_del {
- greeting_len.saturating_sub((t - (t_type + pause1)) / del_speed)
- } else {
- 0
- };
- animated_text = crate::tui::text::take_graphemes(
- &greeting,
- display_len.min(greeting_len),
- );
- } else {
- let mut t = (tick_u - greeting_cycle) % total_ticks;
- for p in prompts.iter() {
- let p_len = crate::tui::text::grapheme_count(p);
- let t_type = p_len * type_speed;
- let t_del = p_len * del_speed;
- let cycle = t_type + pause1 + t_del + pause2;
- if t < cycle {
- let display_len = if t < t_type {
- t / type_speed
- } else if t < t_type + pause1 {
- p_len
- } else if t < t_type + pause1 + t_del {
- p_len.saturating_sub((t - (t_type + pause1)) / del_speed)
- } else {
- 0
- };
- animated_text =
- crate::tui::text::take_graphemes(p, display_len.min(p_len));
- break;
- } else {
- t -= cycle;
- }
- }
- }
- if self.state.cached_animated_text != animated_text {
- self.state.cached_animated_text = animated_text;
- self.state.dirty = true;
- }
- }
let current_query = self.state.search_query.trim().to_string();
if current_query != self.state.last_suggest_query
&& self.state.last_search_edit.elapsed()
@@ -1076,7 +986,28 @@ impl App {
self.action_sender.send(Action::MoveRight).ok();
}
KeyCode::Enter => {
- self.action_sender.send(Action::Submit).ok();
+ if self.state.search_results.is_empty()
+ && !self.state.search_query.trim().is_empty()
+ && (self
+ .state
+ .status_message
+ .to_ascii_lowercase()
+ .starts_with("no matches")
+ || self
+ .state
+ .status_message
+ .to_ascii_lowercase()
+ .contains("search failed"))
+ {
+ self.action_sender
+ .send(Action::Search {
+ query: self.state.search_query.trim().to_string(),
+ force_refresh: true,
+ })
+ .ok();
+ } else {
+ self.action_sender.send(Action::Submit).ok();
+ }
}
KeyCode::Char('?') => {
self.action_sender.send(Action::ToggleHelp).ok();
@@ -1360,7 +1291,9 @@ impl App {
match self.state.active_screen {
Screen::Startup => {}
Screen::Home => {
- if !self.state.search_results.is_empty() {
+ if !self.state.search_results.is_empty()
+ || !self.state.search_query.is_empty()
+ {
self.state.search_poster_protocols.clear();
self.state.search_results.clear();
self.state.search_query.clear();
@@ -1611,6 +1544,7 @@ impl App {
self.state.updater_progress = None;
self.state.updater_status = None;
self.state.updater_done = false;
+ self.state.manual_update_check = true;
self.action_sender.send(Action::CheckForUpdates).ok();
return None;
}
@@ -4130,13 +4064,17 @@ impl App {
if version == "none" {
if self.state.active_screen == Screen::Startup {
self.state.active_screen = Screen::Home;
+ }
+ if self.state.manual_update_check {
self.state.notify(
NotificationKind::Success,
"Up to date",
"You are using the latest version.",
);
}
+ self.state.manual_update_check = false;
} else {
+ self.state.manual_update_check = false;
self.state.update_available = Some(version);
if self.state.active_screen == Screen::Startup {
match crate::tui::updater::replacement_access() {
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index ec58614..81f07bd 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -108,7 +108,7 @@ pub fn picker(
} else {
BorderType::Rounded
})
- .border_style(theme.border_focus);
+ .border_style(theme.lavender);
let inner = block.inner(popup);
frame.render_widget(block, popup);
@@ -118,11 +118,7 @@ pub fn picker(
.map(|item| ListItem::new(item.clone()).style(theme.text))
.collect::<Vec<_>>();
let list = List::new(list_items)
- .highlight_style(
- theme
- .highlight
- .add_modifier(Modifier::BOLD | Modifier::REVERSED),
- )
+ .highlight_style(selection_style(theme, basic_terminal))
.highlight_symbol(if basic_terminal { "> " } else { "▌ " });
frame.render_stateful_widget(list, sections[0], state);
@@ -131,8 +127,8 @@ pub fn picker(
.viewport_content_length(visible_rows)
.position(selected);
let scrollbar = Scrollbar::new(ScrollbarOrientation::VerticalRight)
- .thumb_style(theme.accent)
- .track_style(theme.muted)
+ .thumb_style(theme.lavender)
+ .track_style(theme.surface1)
.begin_symbol(Some("▲"))
.end_symbol(Some("▼"));
frame.render_stateful_widget(scrollbar, sections[0], &mut scrollbar_state);
@@ -188,7 +184,7 @@ pub fn confirmation(
} else {
BorderType::Rounded
})
- .border_style(theme.border_focus);
+ .border_style(theme.lavender);
let inner = block.inner(popup);
frame.render_widget(block, popup);
let sections = Layout::vertical([
@@ -202,9 +198,7 @@ pub fn confirmation(
sections[0],
);
- let selected_style = theme
- .highlight
- .add_modifier(Modifier::BOLD | Modifier::REVERSED);
+ let selected_style = selection_style(theme, basic_terminal);
let actions = Line::from(vec![
Span::styled(
" Download ",
@@ -353,6 +347,15 @@ fn key_hint(key: &str, action: &str, theme: &Theme) -> Span<'static> {
Span::styled(format!("[{key}] {action}"), theme.text_dim)
}
+fn selection_style(theme: &Theme, basic_terminal: bool) -> Style {
+ let style = theme.text.add_modifier(Modifier::BOLD);
+ if basic_terminal {
+ style.add_modifier(Modifier::UNDERLINED)
+ } else {
+ style.bg(theme.surface0.fg.unwrap_or(theme.base))
+ }
+}
+
fn notification_style(
kind: NotificationKind,
theme: &Theme,
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index a0d4c20..e38c548 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -2,7 +2,7 @@ use crate::tui::{state::AppState, theme::Theme};
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Layout, Rect},
- style::Modifier,
+ style::{Modifier, Style},
text::{Line, Span},
widgets::{
Block, Borders, List, ListItem, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,
@@ -167,7 +167,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
} else {
ratatui::widgets::BorderType::Rounded
})
- .border_style(theme.border)
+ .border_style(theme.surface1)
.padding(ratatui::widgets::Padding::new(
if matches!(tier, DetailsLayoutTier::Wide) {
2
@@ -304,9 +304,15 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
if !duration_str.is_empty() {
metadata.push(duration.to_string());
}
- let meta_line = Line::from(vec![Span::styled(metadata.join(" • "), theme.text)]);
+ let meta_line = Line::from(vec![Span::styled(
+ metadata.join(" • "),
+ metadata_style(theme),
+ )]);
- let genre_line = Line::from(vec![Span::styled(genres.to_string(), theme.text_dim)]);
+ let genre_line = Line::from(vec![Span::styled(
+ genres.to_string(),
+ metadata_style(theme),
+ )]);
let mut top_meta = vec![
title_line,
@@ -315,10 +321,10 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
Line::from(vec![Span::styled(
tagline.unwrap_or_default(),
theme
- .text_dim
+ .overlay1
.add_modifier(ratatui::style::Modifier::ITALIC),
)]),
- Line::from(vec![Span::styled("Synopsis", theme.text)]),
+ Line::from(vec![Span::styled("Synopsis", theme.title)]),
];
if matches!(tier, DetailsLayoutTier::Tiny) {
top_meta.truncate(3);
@@ -340,10 +346,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let synopsis_capacity =
(meta_chunks[1].width as usize).saturating_mul(meta_chunks[1].height as usize);
let synopsis = truncate_with_ellipsis(intro, synopsis_capacity);
- let syn_lines = vec![Line::from(vec![Span::styled(
- synopsis,
- theme.text_dim.add_modifier(ratatui::style::Modifier::DIM),
- )])];
+ let syn_lines = vec![Line::from(vec![Span::styled(synopsis, theme.overlay1)])];
let intro_p = Paragraph::new(syn_lines).wrap(Wrap { trim: true });
frame.render_widget(intro_p, meta_chunks[1]);
@@ -470,9 +473,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let language_focused = state.details_pane == crate::tui::state::DetailsPane::Languages;
let lang_border = if language_focused {
- theme.border_focus
+ focused_border_style(theme)
} else {
- theme.border
+ unfocused_border_style(theme)
};
let lang_list = List::new(lang_items)
.block(
@@ -491,14 +494,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
state,
))
.title_style(if language_focused {
- theme.accent
+ focused_title_style(theme)
} else {
- theme.text_dim
+ unfocused_title_style(theme)
})
.border_style(lang_border)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
- .highlight_style(selection_style(language_focused, theme))
+ .highlight_style(selection_style(
+ language_focused,
+ state.basic_terminal,
+ theme,
+ ))
.highlight_symbol(selection_symbol(language_focused, state.basic_terminal));
if let Some(area) = lang_area {
@@ -526,9 +533,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let seasons_focused = state.details_pane == crate::tui::state::DetailsPane::Seasons;
let seasons_border = if seasons_focused {
- theme.border_focus
+ focused_border_style(theme)
} else {
- theme.border
+ unfocused_border_style(theme)
};
let seasons_list = List::new(seasons_items)
.block(
@@ -547,14 +554,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
state,
))
.title_style(if seasons_focused {
- theme.accent
+ focused_title_style(theme)
} else {
- theme.text_dim
+ unfocused_title_style(theme)
})
.border_style(seasons_border)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
- .highlight_style(selection_style(seasons_focused, theme))
+ .highlight_style(selection_style(
+ seasons_focused,
+ state.basic_terminal,
+ theme,
+ ))
.highlight_symbol(selection_symbol(seasons_focused, state.basic_terminal));
if let Some(area) = seasons_area {
@@ -583,9 +594,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let episodes_focused = state.details_pane == crate::tui::state::DetailsPane::Episodes;
let eps_border = if episodes_focused {
- theme.border_focus
+ focused_border_style(theme)
} else {
- theme.border
+ unfocused_border_style(theme)
};
let eps_list = List::new(ep_items)
.block(
@@ -604,14 +615,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
state,
))
.title_style(if episodes_focused {
- theme.accent
+ focused_title_style(theme)
} else {
- theme.text_dim
+ unfocused_title_style(theme)
})
.border_style(eps_border)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
- .highlight_style(selection_style(episodes_focused, theme))
+ .highlight_style(selection_style(
+ episodes_focused,
+ state.basic_terminal,
+ theme,
+ ))
.highlight_symbol(selection_symbol(episodes_focused, state.basic_terminal));
if let Some(area) = eps_area {
@@ -630,10 +645,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
}
- let streams_border = if state.details_pane == crate::tui::state::DetailsPane::Streams {
- theme.border_focus
+ let streams_focused = state.details_pane == crate::tui::state::DetailsPane::Streams;
+ let streams_border = if streams_focused {
+ focused_border_style(theme)
} else {
- theme.border
+ unfocused_border_style(theme)
};
let streams_title = if streams_count > 0 {
@@ -643,11 +659,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.unwrap_or(0)
.min(streams_count.saturating_sub(1));
format!(
- " Streams · {} available · {}/{} ",
+ " {}Streams · {} available · {}/{} ",
+ if streams_focused {
+ focus_title_marker(state.basic_terminal)
+ } else {
+ ""
+ },
streams_count,
selected + 1,
streams_count
)
+ } else if streams_focused {
+ format!(" {}Streams ", focus_title_marker(state.basic_terminal))
} else {
" Streams ".to_string()
};
@@ -660,13 +683,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
ratatui::widgets::BorderType::Rounded
})
.title(ratatui::text::Line::from(streams_title).alignment(Alignment::Left))
- .title_style(
- if state.details_pane == crate::tui::state::DetailsPane::Streams {
- theme.accent
- } else {
- theme.text_dim
- },
- )
+ .title_style(if streams_focused {
+ focused_title_style(theme)
+ } else {
+ unfocused_title_style(theme)
+ })
.border_style(streams_border)
.padding(ratatui::widgets::Padding::horizontal(1));
@@ -732,19 +753,38 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let is_selected = Some(i) == selected_idx;
let pointer = if is_selected {
- if state.basic_terminal { "> " } else { "▌ " }
+ selection_symbol(streams_focused, state.basic_terminal)
} else {
" "
};
- let stream_style = if is_selected {
- selection_style(
- state.details_pane
- == crate::tui::state::DetailsPane::Streams,
+ let row_style = if is_selected {
+ selection_style(streams_focused, state.basic_terminal, theme)
+ } else {
+ metadata_style(theme)
+ };
+ let marker_style = if is_selected && streams_focused {
+ with_selection_surface(theme.lavender, state.basic_terminal, theme)
+ .add_modifier(Modifier::BOLD)
+ } else if is_selected {
+ theme.title
+ } else {
+ metadata_style(theme)
+ };
+ let primary_style = if is_selected {
+ with_selection_surface(theme.text, state.basic_terminal, theme)
+ .add_modifier(Modifier::BOLD)
+ } else {
+ theme.text
+ };
+ let secondary_style = if is_selected {
+ with_selection_surface(
+ metadata_style(theme),
+ state.basic_terminal,
theme,
)
} else {
- theme.text_dim
+ metadata_style(theme)
};
let is_fourk = file.get("_fourk_release").is_some();
@@ -758,36 +798,46 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.unwrap_or(0);
let stream_width = streams_area.width.saturating_sub(6) as usize;
let codec = codec.to_uppercase();
- let metadata = if is_fourk && stream_width >= 58 {
- format!(
- "{size_formatted:<9}{codec:<8}{language:<16}{source_count} mirror{}",
- if source_count == 1 { "" } else { "s" }
- )
+ let mut stream_spans = vec![
+ Span::styled(pointer, marker_style),
+ Span::styled(format!("{size_formatted:<9}"), primary_style),
+ Span::styled(format!("{codec:<8}"), secondary_style),
+ ];
+ if is_fourk && stream_width >= 58 {
+ stream_spans
+ .push(Span::styled(format!("{language:<16}"), secondary_style));
+ stream_spans.push(Span::styled(
+ format!(
+ "{source_count} mirror{}",
+ if source_count == 1 { "" } else { "s" }
+ ),
+ secondary_style,
+ ));
} else if is_fourk && stream_width >= 38 {
- format!("{size_formatted:<9}{codec:<8}{language}")
- } else if is_fourk {
- format!("{size_formatted:<9}{codec}")
- } else if stream_width >= 64 {
+ stream_spans.push(Span::styled(language.to_string(), secondary_style));
+ } else if !is_fourk && stream_width >= 64 {
let fixed_width = 9 + 8 + 12;
let uploader = crate::tui::text::truncate_width(
upload_by,
stream_width.saturating_sub(fixed_width).max(4),
);
- format!("{size_formatted:<9}{codec:<8}{duration_str:<12}{uploader}")
- } else if stream_width >= 38 {
- format!("{size_formatted:<9}{codec:<8}{duration_str}")
- } else {
- format!("{size_formatted:<9}{codec}")
- };
- let metadata = if is_selected {
- format!("{metadata:<width$}", width = stream_width.saturating_sub(2))
- } else {
- metadata
- };
- let stream_line = ratatui::text::Line::from(vec![
- ratatui::text::Span::styled(pointer, stream_style),
- ratatui::text::Span::styled(metadata, stream_style),
- ]);
+ stream_spans
+ .push(Span::styled(format!("{duration_str:<12}"), secondary_style));
+ stream_spans.push(Span::styled(uploader, secondary_style));
+ } else if !is_fourk && stream_width >= 38 {
+ stream_spans.push(Span::styled(duration_str, secondary_style));
+ }
+ if is_selected {
+ let used_width = stream_spans
+ .iter()
+ .map(|span| crate::tui::text::width(span.content.as_ref()))
+ .sum::<usize>();
+ stream_spans.push(Span::styled(
+ " ".repeat(stream_width.saturating_sub(used_width)),
+ row_style,
+ ));
+ }
+ let stream_line = Line::from(stream_spans);
let mut lines = vec![];
if is_first_of_quality {
@@ -796,17 +846,18 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
let option_count =
quality_counts.get(&resolution).copied().unwrap_or(1);
- lines.push(ratatui::text::Line::from(
- ratatui::text::Span::styled(
+ lines.push(Line::from(vec![
+ Span::styled(quality_str, group_heading_style(theme)),
+ Span::styled(" · ", theme.overlay0),
+ Span::styled(
format!(
- "{} · {} option{}",
- quality_str,
+ "{} option{}",
option_count,
if option_count == 1 { "" } else { "s" }
),
- theme.accent,
+ metadata_style(theme),
),
- ));
+ ]));
}
lines.push(stream_line);
@@ -1111,7 +1162,7 @@ fn pane_title(
state: &AppState,
) -> Line<'static> {
let marker = if focused {
- if state.basic_terminal { "> " } else { "◆ " }
+ focus_title_marker(state.basic_terminal)
} else {
""
};
@@ -1140,16 +1191,60 @@ fn pane_title(
Line::from(title)
}
-fn selection_style(focused: bool, theme: &Theme) -> ratatui::style::Style {
+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
+}
+
+fn unfocused_border_style(theme: &Theme) -> Style {
+ theme.surface1
+}
+
+fn focused_title_style(theme: &Theme) -> Style {
+ theme.title
+}
+
+fn unfocused_title_style(theme: &Theme) -> Style {
+ theme.subtext1
+}
+
+fn metadata_style(theme: &Theme) -> Style {
+ theme.subtext1
+}
+
+fn group_heading_style(theme: &Theme) -> Style {
+ theme.lavender.add_modifier(Modifier::BOLD)
+}
+
+fn with_selection_surface(style: Style, basic_terminal: bool, theme: &Theme) -> Style {
+ if basic_terminal {
+ style
+ } else {
+ style.bg(theme_color(theme.surface0, theme.base))
+ }
+}
+
+fn selection_style(focused: bool, basic_terminal: bool, theme: &Theme) -> Style {
if focused {
- theme
- .highlight
- .add_modifier(Modifier::BOLD | Modifier::REVERSED)
+ let style =
+ with_selection_surface(theme.text, basic_terminal, theme).add_modifier(Modifier::BOLD);
+ if basic_terminal {
+ style.add_modifier(Modifier::UNDERLINED)
+ } else {
+ style
+ }
} else {
theme.text.add_modifier(Modifier::BOLD)
}
}
+fn focus_title_marker(basic_terminal: bool) -> &'static str {
+ if basic_terminal { "> " } else { "● " }
+}
+
fn selection_symbol(focused: bool, basic_terminal: bool) -> &'static str {
if focused {
if basic_terminal { "> " } else { "▌ " }
@@ -1223,7 +1318,7 @@ fn render_workflow(
let text = format!("{label} · {}/{}", position + 1, steps.len());
frame.render_widget(
Paragraph::new(text)
- .style(theme.accent)
+ .style(focused_title_style(theme))
.alignment(Alignment::Center),
area,
);
@@ -1231,6 +1326,10 @@ fn render_workflow(
}
let mut spans = Vec::new();
+ let active_index = steps
+ .iter()
+ .position(|(pane, _)| *pane == state.details_pane)
+ .unwrap_or(0);
for (index, (pane, label)) in steps.iter().enumerate() {
if index > 0 {
spans.push(Span::styled(
@@ -1239,17 +1338,25 @@ fn render_workflow(
} else {
" › "
},
- theme.muted,
+ theme.overlay0,
+ ));
+ }
+ if *pane == state.details_pane {
+ spans.push(Span::styled(
+ focus_title_marker(state.basic_terminal),
+ theme.lavender.add_modifier(Modifier::BOLD),
+ ));
+ spans.push(Span::styled(label.clone(), focused_title_style(theme)));
+ } else {
+ spans.push(Span::styled(
+ label.clone(),
+ if index < active_index {
+ theme.text
+ } else {
+ theme.overlay0
+ },
));
}
- spans.push(Span::styled(
- label.clone(),
- if *pane == state.details_pane {
- theme.accent
- } else {
- theme.text_dim
- },
- ));
}
frame.render_widget(
Paragraph::new(Line::from(spans)).alignment(Alignment::Center),
@@ -1257,12 +1364,24 @@ fn render_workflow(
);
}
-fn footer_group(key: &'static str, action: &'static str, theme: &Theme) -> Vec<Span<'static>> {
+fn footer_group(
+ key: &'static str,
+ action: &'static str,
+ prominent: bool,
+ theme: &Theme,
+) -> Vec<Span<'static>> {
vec![
- Span::styled("[", theme.text_dim),
+ Span::styled("[", theme.overlay0),
Span::styled(key, theme.shortcut),
- Span::styled("] ", theme.text_dim),
- Span::styled(action, theme.text),
+ Span::styled("] ", theme.overlay0),
+ Span::styled(
+ action,
+ if prominent {
+ theme.text
+ } else {
+ theme.subtext1
+ },
+ ),
Span::raw(" "),
]
}
@@ -1274,8 +1393,13 @@ fn details_footer(
) -> (Vec<Span<'static>>, Vec<Span<'static>>) {
let compact = width < 80;
let very_compact = width < 45;
- let mut primary = footer_group("Tab", if compact { "Pane" } else { "Next pane" }, theme);
- primary.extend(footer_group("↑↓", "Move", theme));
+ let mut primary = footer_group(
+ "Tab",
+ if compact { "Pane" } else { "Next pane" },
+ false,
+ theme,
+ );
+ primary.extend(footer_group("↑↓", "Move", false, theme));
if !very_compact {
primary.extend(footer_group(
"Enter",
@@ -1284,6 +1408,7 @@ fn details_footer(
} else {
"Select"
},
+ true,
theme,
));
}
@@ -1297,6 +1422,7 @@ fn details_footer(
} else {
"Select"
},
+ true,
theme,
));
} else {
@@ -1304,6 +1430,7 @@ fn details_footer(
secondary.extend(footer_group(
"o",
if compact { "Open" } else { "Open with" },
+ false,
theme,
));
}
@@ -1314,6 +1441,7 @@ fn details_footer(
secondary.extend(footer_group(
"d",
if compact { "Save" } else { "Download" },
+ false,
theme,
));
}
@@ -1321,11 +1449,12 @@ fn details_footer(
secondary.extend(footer_group(
"r",
if compact { "Retry" } else { "Refresh" },
+ false,
theme,
));
}
}
- secondary.extend(footer_group("Esc", "Back", theme));
+ secondary.extend(footer_group("Esc", "Back", false, theme));
if let Some(last) = secondary.last_mut() {
*last = Span::raw("");
@@ -1351,8 +1480,8 @@ fn render_scroll_indicator(
.position(position);
let scrollbar = Scrollbar::default()
.orientation(ScrollbarOrientation::VerticalRight)
- .thumb_style(theme.accent)
- .track_style(theme.muted)
+ .thumb_style(theme.lavender)
+ .track_style(theme.surface1)
.begin_symbol(Some("▲"))
.end_symbol(Some("▼"));
frame.render_stateful_widget(
diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rs
index 5e53161..ef75968 100644
--- a/src/tui/screens/help.rs
+++ b/src/tui/screens/help.rs
@@ -34,6 +34,10 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {
theme.text,
),
]),
+ Line::from(vec![
+ Span::styled(" [Ctrl+T] ", theme.header),
+ Span::styled("Switch Streaming / TV Mode", theme.text),
+ ]),
Line::from(vec![]),
Line::from(vec![Span::styled(
" Navigation",
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index f51e284..3734f36 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -5,56 +5,207 @@ use crate::tui::{
use ratatui::{
Frame,
layout::{Alignment, Constraint, Direction, Layout, Rect},
- widgets::{Block, Borders, Cell, Paragraph, Row, Table},
+ style::{Modifier, Style},
+ text::{Line, Span},
+ widgets::{Block, Cell, Paragraph, Row, Table},
};
-pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme) {
- let show_cursor = (state.tick_count % 16) < 8;
- let search_prefix = if state.basic_terminal { "> " } else { "❯ " };
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum SearchViewState {
+ Empty,
+ Editing,
+ Loading,
+ Results,
+ NoResults,
+ Error,
+}
- let search_content =
- if !state.status_message.is_empty() && state.input_mode == InputMode::Normal {
- format!("{}{}", search_prefix, state.status_message)
- } else if state.search_query.is_empty() {
- let animated_text = &state.cached_animated_text;
+fn search_view_state(state: &AppState) -> SearchViewState {
+ if state.input_mode == InputMode::Editing {
+ SearchViewState::Editing
+ } else if state.is_loading {
+ SearchViewState::Loading
+ } else if state
+ .status_message
+ .to_ascii_lowercase()
+ .contains("search failed")
+ {
+ SearchViewState::Error
+ } else if !state.search_results.is_empty() {
+ SearchViewState::Results
+ } else if !state.search_query.trim().is_empty()
+ && state
+ .status_message
+ .to_ascii_lowercase()
+ .starts_with("no matches")
+ {
+ SearchViewState::NoResults
+ } else {
+ SearchViewState::Empty
+ }
+}
- if state.input_mode == InputMode::Editing {
- if show_cursor {
- format!("{}{}{}█", search_prefix, animated_text, "")
- } else {
- format!("{}{}{} ", search_prefix, animated_text, "")
- }
- } else {
- if show_cursor {
- format!("{}{}|", search_prefix, animated_text)
- } else {
- format!("{}{}", search_prefix, animated_text)
- }
- }
- } else {
- if state.input_mode == InputMode::Editing {
- if show_cursor {
- format!("{} {}█", search_prefix, state.search_query)
- } else {
- format!("{} {} ", search_prefix, state.search_query)
- }
- } else {
- format!("{} {}", search_prefix, state.search_query)
- }
+fn search_spinner(state: &AppState) -> char {
+ if state.basic_terminal {
+ let frames = ['-', '\\', '|', '/'];
+ frames[(state.tick_count as usize) % frames.len()]
+ } else {
+ let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
+ frames[(state.tick_count as usize) % frames.len()]
+ }
+}
+
+fn search_hint(view: SearchViewState, width: u16, theme: &Theme) -> Line<'static> {
+ let text = match view {
+ SearchViewState::Editing if width >= 82 => "[↑↓] Suggestions [Enter] Search [Esc] Cancel",
+ SearchViewState::Editing if width >= 54 => "[↑↓] Suggest [Enter] Search [Esc] Cancel",
+ SearchViewState::Editing => "[Enter] Search [Esc] Cancel",
+ SearchViewState::Error if width >= 62 => "[Enter] Retry [Type] Edit [Esc] Clear",
+ SearchViewState::Error => "[Enter] Retry [Esc] Clear",
+ SearchViewState::Results if width >= 62 => "[Type] Edit [↑↓] Browse [Enter] Open",
+ SearchViewState::Results => "[↑↓] Browse [Enter] Open",
+ SearchViewState::NoResults if width >= 62 => "[Type] Edit [Enter] Retry [Esc] Clear",
+ SearchViewState::NoResults => "[Type] Edit [Esc] Clear",
+ SearchViewState::Loading => "",
+ SearchViewState::Empty => "",
+ };
+
+ let mut spans = Vec::new();
+ let mut remaining = text;
+ while let Some(open) = remaining.find('[') {
+ if open > 0 {
+ spans.push(Span::styled(remaining[..open].to_string(), theme.text_dim));
+ }
+ let Some(close) = remaining[open..].find(']') else {
+ spans.push(Span::styled(remaining[open..].to_string(), theme.text_dim));
+ remaining = "";
+ break;
};
+ let close = open + close;
+ spans.push(Span::styled("[", theme.text_dim));
+ spans.push(Span::styled(
+ remaining[open + 1..close].to_string(),
+ theme.shortcut,
+ ));
+ spans.push(Span::styled("]", theme.text_dim));
+ remaining = &remaining[close + 1..];
+ }
+ if !remaining.is_empty() {
+ spans.push(Span::styled(remaining.to_string(), theme.text_dim));
+ }
+ Line::from(spans).centered()
+}
+fn centered_width(area: Rect, maximum: u16) -> Rect {
+ let width = area.width.min(maximum).max(1);
+ Rect {
+ x: area.x + area.width.saturating_sub(width) / 2,
+ width,
+ ..area
+ }
+}
+
+fn search_content(
+ state: &AppState,
+ view: SearchViewState,
+ show_cursor: bool,
+ width: u16,
+) -> String {
+ let prefix = if state.basic_terminal { "> " } else { "❯ " };
+ let cursor_width = usize::from(view == SearchViewState::Editing);
+ let available = width
+ .saturating_sub(4)
+ .saturating_sub(crate::tui::text::width(prefix) as u16)
+ .saturating_sub(cursor_width as u16) as usize;
+ let content = if state.search_query.is_empty() {
+ "Search movies and series…".to_string()
+ } else {
+ crate::tui::text::truncate_width(&state.search_query, available)
+ };
+ let cursor = if view == SearchViewState::Editing {
+ if show_cursor { "█" } else { " " }
+ } else {
+ ""
+ };
+ format!("{prefix}{content}{cursor}")
+}
+
+fn render_search_bar(
+ frame: &mut Frame,
+ area: Rect,
+ state: &AppState,
+ theme: &Theme,
+ view: SearchViewState,
+ show_cursor: bool,
+ centered: bool,
+) {
+ let rule_style = if view == SearchViewState::Editing {
+ theme.border_focus
+ } else if view == SearchViewState::Error {
+ theme.error
+ } else {
+ theme.border
+ };
+ let rows = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([Constraint::Length(1), Constraint::Length(1)])
+ .split(area);
+ let mut paragraph = Paragraph::new(search_content(state, view, show_cursor, area.width)).style(
+ if view == SearchViewState::Editing {
+ theme.text
+ } else if state.search_query.is_empty() {
+ theme.text_dim
+ } else {
+ theme.text
+ },
+ );
+ if centered {
+ paragraph = paragraph.alignment(Alignment::Center);
+ }
+ frame.render_widget(paragraph, rows[0]);
+
+ let status = match view {
+ SearchViewState::Loading => format!(" {} Searching… ", search_spinner(state)),
+ SearchViewState::Results => format!(" {} results ", state.search_results.len()),
+ SearchViewState::NoResults => " No results ".to_string(),
+ SearchViewState::Error => " Search failed ".to_string(),
+ _ => String::new(),
+ };
+ let status_width = crate::tui::text::width(&status) as u16;
+ let rule_width = area.width.saturating_sub(status_width);
+ let rule = if state.basic_terminal { "-" } else { "─" };
+ let rule_text = rule.repeat(rule_width as usize);
+ let status_style = if view == SearchViewState::Error {
+ theme.error.add_modifier(Modifier::BOLD)
+ } else if view == SearchViewState::Results {
+ theme.accent
+ } else {
+ theme.text_dim
+ };
+ frame.render_widget(
+ Paragraph::new(Line::from(vec![
+ Span::styled(rule_text, rule_style),
+ Span::styled(status, status_style),
+ ])),
+ rows[1],
+ );
+}
+
+pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme) {
+ let show_cursor = (state.tick_count % 16) < 8;
+ let view = search_view_state(state);
let mut search_bar_area = Rect::default();
+ let mut suggestion_area = Rect::default();
- if state.search_results.is_empty()
- && !state.is_loading
- && !state.status_message.to_lowercase().contains("fail")
+ if view == SearchViewState::Empty
+ || (view == SearchViewState::Editing && state.search_results.is_empty())
{
if state.tick_count < 1 {
return;
}
- let is_narrow = area.width < 60 || state.basic_terminal;
- let is_wide = area.width >= 100 && !state.basic_terminal;
+ let is_narrow = area.width < 100 || area.height < 28 || state.basic_terminal;
+ let is_wide = area.width >= 120 && area.height >= 32 && !state.basic_terminal;
let logo_height = if is_narrow {
2
} else if is_wide {
@@ -110,20 +261,19 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
} else {
if state.is_tv_mode { 57 } else { 55 }
};
- let compact_footer = area.width < 120;
- let footer_height = if compact_footer { 2 } else { 1 };
-
+ let suggestions_open =
+ state.input_mode == InputMode::Editing && !state.search_suggestions.is_empty();
let vertical_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
- Constraint::Percentage(15),
+ Constraint::Percentage(18),
Constraint::Length(logo_height),
Constraint::Length(1),
Constraint::Length(2),
- Constraint::Length(3),
- Constraint::Length(3),
+ Constraint::Length(1),
+ Constraint::Length(1),
Constraint::Min(0),
- Constraint::Length(footer_height),
+ Constraint::Length(1),
Constraint::Length(1),
])
.split(area);
@@ -198,183 +348,171 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
frame.render_widget(version, version_chunks[1]);
if state.tick_count >= 3 {
- search_bar_area = vertical_chunks[5];
-
- let search_bar = Paragraph::new(search_content.clone())
- .alignment(Alignment::Center)
- .style(match state.input_mode {
- InputMode::Editing => theme.title,
- InputMode::Normal => theme.text_dim,
- });
+ let search_width = if is_wide {
+ 64
+ } else if is_narrow {
+ area.width.saturating_sub(4)
+ } else {
+ 56
+ };
+ search_bar_area = centered_width(vertical_chunks[3], search_width);
+ suggestion_area = Rect {
+ x: search_bar_area.x,
+ y: search_bar_area.bottom(),
+ width: search_bar_area.width,
+ height: area.bottom().saturating_sub(search_bar_area.bottom()),
+ };
if !state.tv_config_popup {
- frame.render_widget(search_bar, search_bar_area);
+ render_search_bar(
+ frame,
+ search_bar_area,
+ state,
+ theme,
+ view,
+ show_cursor,
+ true,
+ );
}
- let mut primary_legend = vec![
- ratatui::text::Span::styled(
- state.active_provider.label().to_string(),
- theme.accent,
- ),
- ratatui::text::Span::styled(" • ", theme.muted),
- ratatui::text::Span::styled(
+ let context = Line::from(vec![
+ Span::styled(state.active_provider.label().to_string(), theme.accent),
+ Span::styled(" • ", theme.muted),
+ Span::styled(
if state.is_tv_mode { "TV" } else { "Streaming" },
theme.text_dim,
),
- ratatui::text::Span::raw(" "),
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("Ctrl+P", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("Provider ", theme.text),
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("Ctrl+T", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("TV Mode", theme.text),
- ];
- let search_legend = vec![
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("Type", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("Search ", theme.text),
- ];
- let mut secondary_legend = search_legend;
- secondary_legend.extend([
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("↑↓", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("Browse ", theme.text),
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("?", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("Help ", theme.text),
- ratatui::text::Span::styled("[", theme.text_dim),
- ratatui::text::Span::styled("q", theme.shortcut),
- ratatui::text::Span::styled("] ", theme.text_dim),
- ratatui::text::Span::styled("Quit", theme.text),
]);
-
- let legend = if compact_footer {
- Paragraph::new(vec![
- ratatui::text::Line::from(primary_legend),
- ratatui::text::Line::from(secondary_legend),
- ])
+ let context_area = if suggestions_open {
+ Rect::default()
+ } else if view == SearchViewState::Empty {
+ vertical_chunks[4]
} else {
- primary_legend.push(ratatui::text::Span::raw(" "));
- primary_legend.extend(secondary_legend);
- Paragraph::new(ratatui::text::Line::from(primary_legend))
- }
- .alignment(Alignment::Center);
- frame.render_widget(legend, vertical_chunks[7]);
-
- if let Some(version_str) = &state.update_available {
- let update_text = Paragraph::new(format!(
- "Update v{} available! Auto-update failed, please reinstall manually.",
- version_str
- ))
- .alignment(Alignment::Center)
- .style(theme.highlight);
- frame.render_widget(update_text, vertical_chunks[8]);
+ frame.render_widget(
+ Paragraph::new(search_hint(view, search_bar_area.width, theme))
+ .alignment(Alignment::Center),
+ vertical_chunks[4],
+ );
+ vertical_chunks[5]
+ };
+ if context_area.width > 0 {
+ frame.render_widget(
+ Paragraph::new(context).alignment(Alignment::Center),
+ context_area,
+ );
}
+
+ let footer = Line::from(vec![
+ Span::styled("[", theme.text_dim),
+ Span::styled("?", theme.shortcut),
+ Span::styled("] ", theme.text_dim),
+ Span::styled("Help", theme.text_dim),
+ Span::raw(" "),
+ Span::styled("[", theme.text_dim),
+ Span::styled("q", theme.shortcut),
+ Span::styled("] ", theme.text_dim),
+ Span::styled("Quit", theme.text_dim),
+ ]);
+ frame.render_widget(
+ Paragraph::new(footer).alignment(Alignment::Center),
+ vertical_chunks[7],
+ );
}
} else {
+ let suggestion_height =
+ if state.input_mode == InputMode::Editing && !state.search_suggestions.is_empty() {
+ state.search_suggestions.len().min(6) as u16 + 2
+ } else {
+ 0
+ };
+ let feedback_height = u16::from(matches!(
+ view,
+ SearchViewState::NoResults | SearchViewState::Error
+ ));
let chunks = Layout::default()
.direction(Direction::Vertical)
- .constraints([Constraint::Length(3), Constraint::Min(0)])
+ .constraints([
+ Constraint::Length(2),
+ Constraint::Length(1),
+ Constraint::Length(suggestion_height),
+ Constraint::Length(feedback_height),
+ Constraint::Min(0),
+ ])
.split(area);
- search_bar_area = chunks[0];
- let border_style = if state.input_mode == InputMode::Editing {
- theme.border_focus
+ let search_width = if area.width >= 120 {
+ 88
} else {
- theme.border
+ area.width.saturating_sub(4)
};
-
- let loading_title = if state.is_loading && !state.search_results.is_empty() {
- let spinner = if state.basic_terminal {
- let frames = ['-', '\\', '|', '/'];
- frames[(state.tick_count as usize) % frames.len()]
- } else {
- let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
- frames[(state.tick_count as usize) % frames.len()]
- };
- Some(ratatui::text::Line::from(ratatui::text::Span::styled(
- format!(" {} ", spinner),
- theme.accent,
- )))
- } else {
- None
- };
-
- let mut search_block = Block::default()
- .borders(Borders::ALL)
- .border_style(border_style)
- .border_type(if state.basic_terminal {
- ratatui::widgets::BorderType::Plain
- } else {
- ratatui::widgets::BorderType::Rounded
- })
- .padding(ratatui::widgets::Padding::left(1));
- if let Some(title) = loading_title {
- search_block = search_block
- .title_top(title)
- .title_alignment(Alignment::Right);
+ search_bar_area = centered_width(chunks[0], search_width);
+ suggestion_area = chunks[2];
+ render_search_bar(
+ frame,
+ search_bar_area,
+ state,
+ theme,
+ view,
+ show_cursor,
+ false,
+ );
+ let suggestions_open =
+ state.input_mode == InputMode::Editing && !state.search_suggestions.is_empty();
+ if !suggestions_open {
+ frame.render_widget(
+ Paragraph::new(search_hint(view, search_bar_area.width, theme))
+ .alignment(Alignment::Center),
+ chunks[1],
+ );
}
- let search_bar = Paragraph::new(search_content.clone())
- .style(match state.input_mode {
- InputMode::Editing => theme.title,
- InputMode::Normal => theme.text,
- })
- .block(search_block);
- frame.render_widget(search_bar, search_bar_area);
let list_block = Block::default();
-
- if state.is_loading && state.search_results.is_empty() {
- let spinner = if state.basic_terminal {
- let frames = ['-', '\\', '|', '/'];
- frames[(state.tick_count as usize) % frames.len()]
- } else {
- let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
- frames[(state.tick_count as usize) % frames.len()]
- };
-
- let inner_area = list_block.inner(chunks[1]);
- frame.render_widget(list_block, chunks[1]);
-
- let v_chunks = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Percentage(45),
- Constraint::Length(1),
- Constraint::Percentage(50),
- ])
- .split(inner_area);
-
- let spinner_color = if state.basic_terminal {
- theme.accent
- } else {
- let is_sky = (state.tick_count % 16) < 8;
- if is_sky { theme.accent } else { theme.teal }
+ if feedback_height > 0 {
+ let feedback = match view {
+ SearchViewState::NoResults => format!(
+ "No matches for “{}” · Type to edit or press Esc to clear",
+ state.search_query
+ ),
+ SearchViewState::Error => {
+ "Search failed · Press Enter to retry or type to edit".to_string()
+ }
+ _ => String::new(),
};
+ frame.render_widget(
+ Paragraph::new(feedback).style(if view == SearchViewState::Error {
+ theme.error
+ } else if view == SearchViewState::NoResults {
+ theme.text_dim
+ } else {
+ theme.accent
+ }),
+ chunks[3],
+ );
+ }
- let loading_text = if state.is_homepage_mode {
- state.status_message.clone()
+ if state.is_loading && state.search_results.is_empty() {
+ frame.render_widget(list_block, chunks[4]);
+ } else if !state.search_results.is_empty() {
+ let poster_width = if state.image_supported {
+ (state.poster_rows.saturating_mul(2) / 3).max(5)
} else {
- format!("Searching for \"{}\"...", state.search_query)
+ 12
};
-
- let p = Paragraph::new(ratatui::text::Line::from(vec![
- ratatui::text::Span::styled(format!("{} ", spinner), spinner_color),
- ratatui::text::Span::styled(loading_text, theme.title),
- ]))
- .alignment(Alignment::Center);
- frame.render_widget(p, v_chunks[1]);
- } else if !state.search_results.is_empty() {
+ let content_width = state
+ .search_results
+ .iter()
+ .map(|result| crate::tui::text::width(&result.title) as u16)
+ .max()
+ .unwrap_or(0)
+ .saturating_add(poster_width)
+ .saturating_add(18)
+ .clamp(48, 104);
+ let results_area = centered_width(chunks[4], content_width);
let selected_idx = state.search_list_state.selected();
let offset = state.search_list_state.offset();
- let row_height = state.poster_rows;
- state.visible_items = (chunks[1].height as usize) / (row_height as usize);
+ let row_height = state.poster_rows.max(3);
+ state.visible_items = (results_area.height as usize) / (row_height as usize);
let rows = state
.search_results
.iter()
@@ -382,13 +520,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let table = Table::new(rows, [Constraint::Percentage(100)]).block(list_block);
- frame.render_stateful_widget(table, chunks[1], &mut state.search_list_state);
+ frame.render_stateful_widget(table, results_area, &mut state.search_list_state);
- let mut inner_area = chunks[1];
- inner_area.x += 1;
- inner_area.y += 1;
- inner_area.width = inner_area.width.saturating_sub(2);
- inner_area.height = inner_area.height.saturating_sub(2);
+ let inner_area = results_area;
let mut current_y = inner_area.y;
@@ -411,16 +545,19 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
let is_selected = Some(i) == selected_idx;
+ if is_selected {
+ let selected_bg = theme.surface0.fg.unwrap_or(theme.base);
+ frame.render_widget(
+ Block::default().style(Style::default().bg(selected_bg)),
+ item_area,
+ );
+ }
let layout = Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(2),
- Constraint::Length(if state.image_supported {
- state.poster_rows + 1
- } else {
- 12
- }),
+ Constraint::Length(poster_width),
Constraint::Length(1),
Constraint::Min(0),
])
@@ -603,29 +740,12 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.content_length(content_len.saturating_sub(state.visible_items))
.position(offset);
- let mut sb_area = chunks[1];
- sb_area.y += 1;
- sb_area.height = sb_area.height.saturating_sub(2);
+ let sb_area = results_area;
frame.render_stateful_widget(scrollbar, sb_area, &mut scrollbar_state);
}
} else {
- let inner_area = list_block.inner(chunks[1]);
- frame.render_widget(list_block, chunks[1]);
-
- let v_chunks = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Percentage(45),
- Constraint::Length(1),
- Constraint::Percentage(50),
- ])
- .split(inner_area);
-
- let p = Paragraph::new(state.status_message.clone())
- .alignment(Alignment::Center)
- .style(theme.error);
- frame.render_widget(p, v_chunks[1]);
+ frame.render_widget(list_block, chunks[4]);
}
}
@@ -634,58 +754,61 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
&& search_bar_area.width > 0
{
let search_area = search_bar_area;
-
- let dropdown_height = std::cmp::min(state.search_suggestions.len() as u16, 10);
-
- let is_home_screen = state.search_results.is_empty()
- && !state.is_loading
- && !state.status_message.to_lowercase().contains("fail");
-
- let dropdown_y = if !is_home_screen && search_area.y > area.height / 2 {
- search_area.y.saturating_sub(dropdown_height)
- } else {
- search_area.y + 1
- };
-
- let max_len = state
- .search_suggestions
- .iter()
- .map(|s| crate::tui::text::width(s))
- .max()
- .unwrap_or(0) as u16;
-
- let dropdown_width = std::cmp::min(std::cmp::max(max_len + 8, 30), search_area.width);
-
- let text_len = crate::tui::text::width(&search_content) as u16;
- let text_start_x = search_area.x + search_area.width.saturating_sub(text_len) / 2;
-
- let dropdown_x = if is_home_screen {
- text_start_x + 2
+ let visible_count = state.search_suggestions.len().min(6);
+ let dropdown_height = visible_count as u16 + 2;
+ let selected_index = state.suggest_index.unwrap_or(0);
+ let suggestion_offset = selected_index
+ .saturating_add(1)
+ .saturating_sub(visible_count)
+ .min(state.search_suggestions.len().saturating_sub(visible_count));
+ let dropdown_width = search_area.width;
+ let dropdown_x = search_area.x;
+ let dropdown_area = if suggestion_area.height >= dropdown_height {
+ Rect {
+ x: dropdown_x,
+ y: suggestion_area.y,
+ width: dropdown_width,
+ height: dropdown_height,
+ }
} else {
- search_area.x + 3
- };
-
- let dropdown_area = Rect {
- x: dropdown_x,
- y: dropdown_y,
- width: dropdown_width,
- height: dropdown_height,
+ Rect {
+ x: dropdown_x,
+ y: search_area.y + search_area.height,
+ width: dropdown_width,
+ height: dropdown_height,
+ }
};
- if dropdown_area.y + dropdown_area.height <= area.height || search_area.y > area.height / 2
- {
- crate::tui::clear_area(frame, dropdown_area, theme);
+ if dropdown_area.y + dropdown_area.height <= area.y + area.height {
+ let surface = theme.surface0.fg.unwrap_or(theme.base);
+ let selected_surface = theme.surface1.fg.unwrap_or(surface);
+ frame.render_widget(
+ Block::default().style(Style::default().bg(surface)),
+ dropdown_area,
+ );
+ let dropdown_rows = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Length(1),
+ Constraint::Length(visible_count as u16),
+ Constraint::Length(1),
+ ])
+ .split(dropdown_area);
let items: Vec<ratatui::widgets::ListItem> = state
.search_suggestions
.iter()
.enumerate()
+ .skip(suggestion_offset)
+ .take(visible_count)
.map(|(i, s)| {
- let text = if Some(i) == state.suggest_index {
- format!("▌ {}", s)
+ let selected = Some(i) == state.suggest_index;
+ let marker = if selected {
+ if state.basic_terminal { "> " } else { "▌ " }
} else {
- format!(" {}", s)
+ " "
};
- let style = if Some(i) == state.suggest_index {
+ let text = format!("{marker}{s}");
+ let style = if selected {
theme.highlight
} else {
theme.text
@@ -694,11 +817,68 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
ratatui::text::Line::from(ratatui::text::Span::styled(text, style))
.alignment(ratatui::layout::Alignment::Left),
)
+ .style(if selected {
+ theme.lavender.bg(selected_surface)
+ } else {
+ theme.text.bg(surface)
+ })
})
.collect();
+ let position = state
+ .suggest_index
+ .map(|index| format!("{}/{}", index + 1, state.search_suggestions.len()))
+ .unwrap_or_else(|| state.search_suggestions.len().to_string());
+ let heading = Line::from(vec![
+ Span::styled(" Suggestions", theme.title),
+ Span::styled(" · ", theme.overlay0),
+ Span::styled(position, theme.subtext1),
+ ]);
+ frame.render_widget(
+ Paragraph::new(heading).style(Style::default().bg(surface)),
+ dropdown_rows[0],
+ );
let list = ratatui::widgets::List::new(items)
- .block(ratatui::widgets::Block::default().borders(ratatui::widgets::Borders::NONE));
- frame.render_widget(list, dropdown_area);
+ .highlight_style(
+ theme
+ .lavender
+ .bg(selected_surface)
+ .add_modifier(Modifier::BOLD),
+ )
+ .style(Style::default().bg(surface));
+ frame.render_widget(list, dropdown_rows[1]);
+
+ let footer = Line::from(vec![
+ Span::styled(" [", theme.text_dim),
+ Span::styled("↑↓", theme.shortcut),
+ Span::styled("] Move [", theme.text_dim),
+ Span::styled("Enter", theme.shortcut),
+ Span::styled("] Use [", theme.text_dim),
+ Span::styled("Esc", theme.shortcut),
+ Span::styled("] Close", theme.text_dim),
+ ])
+ .centered();
+ frame.render_widget(
+ Paragraph::new(footer).style(Style::default().bg(surface)),
+ dropdown_rows[2],
+ );
+ if state.search_suggestions.len() > visible_count {
+ let mut scrollbar_state = ratatui::widgets::ScrollbarState::default()
+ .content_length(state.search_suggestions.len())
+ .position(selected_index);
+ let scrollbar = ratatui::widgets::Scrollbar::default()
+ .orientation(ratatui::widgets::ScrollbarOrientation::VerticalRight)
+ .begin_symbol(None)
+ .end_symbol(None)
+ .track_symbol(Some("│"))
+ .thumb_symbol(if state.basic_terminal { "|" } else { "█" });
+ let scrollbar_area = Rect {
+ x: dropdown_rows[1].x,
+ y: dropdown_rows[1].y,
+ width: dropdown_rows[1].width,
+ height: dropdown_rows[1].height,
+ };
+ frame.render_stateful_widget(scrollbar, scrollbar_area, &mut scrollbar_state);
+ }
}
}
if state.tv_config_popup {
diff --git a/src/tui/state.rs b/src/tui/state.rs
index dca2143..822065f 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -63,7 +63,6 @@ pub struct AppState {
pub is_homepage_mode: bool,
pub current_tab_id: String,
pub current_page: usize,
- pub cached_animated_text: String,
pub search_posters: lru::LruCache<String, std::sync::Arc<image::DynamicImage>>,
pub search_poster_protocols:
lru::LruCache<String, ((u16, u16), ratatui_image::protocol::Protocol)>,
@@ -127,6 +126,7 @@ pub struct AppState {
pub updater_done: bool,
pub auto_update: bool,
pub last_update_check: u64,
+ pub manual_update_check: bool,
pub download_progress: Option<f64>,
pub download_status: Option<String>,
@@ -163,7 +163,6 @@ impl Default for AppState {
provider_generation: 0,
active_screen: Screen::Startup,
input_mode: InputMode::Normal,
- cached_animated_text: String::new(),
search_query: String::new(),
last_suggest_query: String::new(),
last_search_edit: std::time::Instant::now(),
@@ -233,6 +232,7 @@ impl Default for AppState {
updater_done: false,
auto_update: true,
last_update_check: 0,
+ manual_update_check: false,
download_progress: None,
download_status: None,