Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(tui): clean resize state, reset search inputs, and balance footer layout
Samir Hossains07b2215f733a
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rsindex cc53fa4..03a0a6a 100644--- a/src/tui/app/keyboard.rs+++ b/src/tui/app/keyboard.rs@@ -45,11 +45,6 @@ impl App {return None;}- if key.code == KeyCode::F(1) {- self.action_sender.send(Action::ToggleHelp).ok();- return None;- }-if self.state.show_browse_popup {match key.code {KeyCode::Esc => {@@ -137,6 +132,8 @@ impl App {InputMode::Editing => match key.code {KeyCode::Esc => {self.state.input_mode = InputMode::Normal;+ self.state.suggest_index = None;+ self.state.search_suggestions.clear();self.state.set_status(String::new(), 150);}KeyCode::Enter => {@@ -159,6 +156,12 @@ impl App {self.action_sender.send(action).ok();}}+ KeyCode::Char('u') if key.modifiers.contains(KeyModifiers::CONTROL) => {+ self.state.search_query.clear();+ self.state.suggest_index = None;+ self.state.search_suggestions.clear();+ self.state.last_search_edit = std::time::Instant::now();+ }KeyCode::Backspace => {crate::tui::text::remove_last_grapheme(&mut self.state.search_query);self.state.suggest_index = None;diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rsindex 297c254..f0f390d 100644--- a/src/tui/app/navigation.rs+++ b/src/tui/app/navigation.rs@@ -41,6 +41,7 @@ impl App {self.state.is_loading = false;self.state.is_fetching_streams = false;self.state.stream_error = None;+ self.state.search_error = None;self.state.search_results.clear();self.state.search_suggestions.clear();self.state.search_preview = None;diff --git a/src/tui/app/run.rs b/src/tui/app/run.rsindex db45d75..0563cab 100644--- a/src/tui/app/run.rs+++ b/src/tui/app/run.rs@@ -67,6 +67,8 @@ impl App {if self.state.clear_terminal_before_draw {terminal.backend_mut().clear()?;terminal.current_buffer_mut().reset();+ self.state.poster_protocol = None;+ self.state.search_poster_protocols.clear();self.state.clear_terminal_before_draw = false;self.state.dirty = true;}@@ -101,7 +103,9 @@ impl App {}async fn handle_action(&mut self, action: Action) -> Option<()> {- if !matches!(action, Action::Tick | Action::UpdateDownload(..)) {+ if self.state.last_resize_time.is_some()+ || !matches!(action, Action::Tick | Action::UpdateDownload(..))+ {self.state.dirty = true;}match action {@@ -213,17 +217,42 @@ impl App {fn draw(&mut self, frame: &mut Frame) {let area = frame.area();- if area.width < 85 || area.height < 24 {+ if let Some((_, w, h)) = self.state.last_resize_time {+ let label = format!("{} × {}", w, h);+ let label_len = label.chars().count() as u16 + 4;+ let badge_w = label_len.min(area.width);+ let badge_h = 1_u16;+ let badge_x = area.x + (area.width.saturating_sub(badge_w)) / 2;+ let badge_y = area.y + (area.height.saturating_sub(badge_h)) / 2;+ let badge_area = ratatui::layout::Rect {+ x: badge_x,+ y: badge_y,+ width: badge_w,+ height: badge_h,+ };+ let line = ratatui::text::Line::from(vec![ratatui::text::Span::styled(+ label,+ self.theme.title,+ )]);+ frame.render_widget(+ ratatui::widgets::Paragraph::new(line)+ .alignment(ratatui::layout::Alignment::Center),+ badge_area,+ );+ return;+ }++ if area.width < 50 || area.height < 14 {use ratatui::layout::Alignment;use ratatui::text::Line;use ratatui::widgets::{Block, Borders, Paragraph};let msg_lines = vec![Line::from(format!(- "Terminal too small ({}x{}).",+ "Terminal too small ({}×{}).",area.width, area.height)),- Line::from("Minimum required size: 85x24"),+ Line::from("Minimum required size: 50×14"),Line::from("Please enlarge your terminal window."),];diff --git a/src/tui/app/system.rs b/src/tui/app/system.rsindex b734a68..8257ed3 100644--- a/src/tui/app/system.rs+++ b/src/tui/app/system.rs@@ -19,6 +19,15 @@ impl App {self.state.status_message.clear();}}+ if let Some((time, _, _)) = self.state.last_resize_time {+ needs_redraw = true;+ if time.elapsed() >= std::time::Duration::from_millis(300) {+ self.state.last_resize_time = None;+ self.state.clear_terminal_before_draw = true;+ self.state.poster_protocol = None;+ self.state.search_poster_protocols.clear();+ }+ }if needs_redraw {self.state.dirty = true;}@@ -96,8 +105,8 @@ impl App {self.prepare_image_soft_refresh();}- Action::Resize(_w, _h) => {- self.state.last_resize_time = None;+ Action::Resize(w, h) => {+ self.state.last_resize_time = Some((std::time::Instant::now(), w, h));self.state.poster_protocol = None;self.state.search_poster_protocols.clear();self.state.clear_terminal_before_draw = true;diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rsindex b37d2fb..1f7ad1d 100644--- a/src/tui/screens/help.rs+++ b/src/tui/screens/help.rs@@ -42,7 +42,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {]),Line::from(vec![Span::styled(" [←] / [→] ", theme.header),- Span::styled("Page Through Results", theme.text),+ Span::styled("Jump Page of Results", theme.text),]),Line::from(vec![Span::styled(" [Enter] ", theme.header),@@ -68,12 +68,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {Span::styled("Reload Playlists", theme.text),]),Line::from(vec![- Span::styled(" /list ", theme.header),- Span::styled("Show Available Channels", theme.text),- ]),- Line::from(vec![- Span::styled(" /config ", theme.header),- Span::styled("Add / Remove Playlists", theme.text),+ Span::styled(" Type /config", theme.header),+ Span::styled("Manage Playlists (in search)", theme.text),]),]);} else {diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex bf6ff5f..3c0cf28 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -299,11 +299,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)Constraint::Length(1),Constraint::Length(3),Constraint::Length(1),- Constraint::Length(1),- Constraint::Length(1),Constraint::Min(0),Constraint::Length(1),- Constraint::Length(1),]).split(area);@@ -399,25 +396,30 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)}let mut footer_spans = vec![];- let provider_name = if state.is_tv_mode {- "Live TV"- } else {- state.active_provider.label()- };+ if !state.is_tv_mode {+ footer_spans.push(Span::styled("[", theme.text_dim));+ footer_spans.push(Span::styled("Ctrl+P", theme.shortcut));+ footer_spans.push(Span::styled("] ", theme.text_dim));+ footer_spans.push(Span::styled(+ state.active_provider.label(),+ theme.text.add_modifier(Modifier::BOLD),+ ));+ footer_spans.push(Span::raw(" "));+ }footer_spans.push(Span::styled("[", theme.text_dim));- footer_spans.push(Span::styled("Ctrl+P", theme.shortcut));+ footer_spans.push(Span::styled("Ctrl+T", theme.shortcut));footer_spans.push(Span::styled("] ", theme.text_dim));footer_spans.push(Span::styled(- provider_name,- theme.text.add_modifier(Modifier::BOLD),+ if state.is_tv_mode { "Streaming" } else { "TV" },+ theme.text_dim,));- footer_spans.push(Span::raw(" "));+ footer_spans.push(Span::raw(" "));footer_spans.push(Span::styled("[", theme.text_dim));footer_spans.push(Span::styled("?", theme.shortcut));footer_spans.push(Span::styled("] ", theme.text_dim));footer_spans.push(Span::styled("Help", theme.text_dim));- footer_spans.push(Span::raw(" "));+ footer_spans.push(Span::raw(" "));footer_spans.push(Span::styled("[", theme.text_dim));footer_spans.push(Span::styled("q", theme.shortcut));footer_spans.push(Span::styled("] ", theme.text_dim));@@ -425,7 +427,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)frame.render_widget(Paragraph::new(Line::from(footer_spans)).alignment(Alignment::Center),- vertical_chunks[8],+ vertical_chunks[6],);}} else {