Skip to content

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

fix(tui): resolve search auto-close, event stream drop, and provider switching delay

Samir Hossains4cd6b05bf7b7
diff --git a/src/main.rs b/src/main.rs
index 973c43e..5c27946 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -86,5 +86,8 @@ async fn main() -> std::io::Result<()> {
purge_stale_subtitles();
let mut app = App::new();
- app.run(&mut terminal).await
+ if let Err(err) = app.run(&mut terminal).await {
+ log::error!("application error: {err}");
+ }
+ Ok(())
}
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index f623948..e275433 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -168,9 +168,6 @@ impl App {
self.state.suggest_index = None;
self.state.last_search_edit = std::time::Instant::now();
}
- KeyCode::Char('q') if self.state.search_query.is_empty() => {
- self.action_sender.send(Action::Quit).ok();
- }
KeyCode::Char(c) => {
self.state.search_query.push(c);
self.state.suggest_index = None;
diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rs
index b6bfa7f..297c254 100644
--- a/src/tui/app/navigation.rs
+++ b/src/tui/app/navigation.rs
@@ -25,7 +25,7 @@ impl App {
return;
}
self.reset_transient_overlays();
- self.prepare_image_refresh();
+ self.prepare_image_soft_refresh();
self.state
.fetch_cancel
.store(true, std::sync::atomic::Ordering::SeqCst);
@@ -77,6 +77,7 @@ impl App {
self.state.poster_protocol = None;
self.state.search_list_state.select(None);
self.state.resource_list_state.select(None);
+ self.state.dirty = true;
self.state.set_status(
format!(
"{} selected. Search uses only this provider.",
@@ -91,6 +92,10 @@ impl App {
let _ = client.init().await;
});
}
+ if !self.state.search_query.trim().is_empty() {
+ let query = self.state.search_query.clone();
+ self.prepare_search_request(&query);
+ }
}
pub(super) fn cycle_provider(&mut self) {
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 3f18529..0cf4e6e 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -13,18 +13,13 @@ impl App {
std::io::Error: From<<B as ratatui::backend::Backend>::Error>,
{
if self.state.image_picker.is_none() && self.state.image_supported {
- match ratatui_image::picker::Picker::from_query_stdio() {
- Ok(picker) => {
- let cell_h = picker.font_size().height;
- if cell_h > 0 {
- self.state.poster_rows = (96_u16.div_ceil(cell_h)).max(3);
- }
- self.state.image_picker = Some(picker);
- }
- Err(_) => {
- self.state.image_supported = false;
- }
+ let picker = ratatui_image::picker::Picker::from_query_stdio()
+ .unwrap_or_else(|_| ratatui_image::picker::Picker::halfblocks());
+ let cell_h = picker.font_size().height;
+ if cell_h > 0 {
+ self.state.poster_rows = (96_u16.div_ceil(cell_h)).max(3);
}
+ self.state.image_picker = Some(picker);
}
let mut events = EventHandler::new(Duration::from_millis(100));
diff --git a/src/tui/event.rs b/src/tui/event.rs
index a4544b4..4f24c1b 100644
--- a/src/tui/event.rs
+++ b/src/tui/event.rs
@@ -48,10 +48,11 @@ impl EventHandler {
let _ = event_sender.send(Action::Resize(w, h)).await;
}
Err(error) => {
- let _ = event_sender.send(Action::SetStatus(format!(
- "Error: terminal input failed: {error}"
- ))).await;
- break;
+ if error.kind() == std::io::ErrorKind::Interrupted {
+ continue;
+ }
+ log::warn!("terminal input error: {error}");
+ tokio::time::sleep(Duration::from_millis(50)).await;
}
_ => {}
}
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 28a2284..a774204 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -459,51 +459,41 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
);
}
- let context = if state.is_tv_mode {
- Line::from(vec![
- Span::styled("Live TV", theme.accent),
- Span::styled(" • ", theme.muted),
- Span::styled("Local playlists", theme.text_dim),
- ])
- } else {
- Line::from(vec![
- Span::styled(state.active_provider.label().to_string(), theme.accent),
- Span::styled(" • ", theme.muted),
- Span::styled("Streaming", theme.text_dim),
- ])
- };
- let context_area = if suggestions_open {
- Rect::default()
- } else if view == SearchViewState::Empty {
- vertical_chunks[5]
- } else {
+ if !suggestions_open && view != SearchViewState::Empty {
frame.render_widget(
Paragraph::new(search_hint(view, search_bar_area.width, theme))
.alignment(Alignment::Center),
vertical_chunks[5],
);
- vertical_chunks[6]
- };
- 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),
- ]);
+ let mut footer_spans = vec![];
+ let provider_name = if state.is_tv_mode {
+ "Live TV"
+ } else {
+ state.active_provider.label()
+ };
+
+ 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(
+ provider_name,
+ theme.text.add_modifier(Modifier::BOLD),
+ ));
+ 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::styled("[", theme.text_dim));
+ footer_spans.push(Span::styled("q", theme.shortcut));
+ footer_spans.push(Span::styled("] ", theme.text_dim));
+ footer_spans.push(Span::styled("Quit", theme.text_dim));
+
frame.render_widget(
- Paragraph::new(footer).alignment(Alignment::Center),
+ Paragraph::new(Line::from(footer_spans)).alignment(Alignment::Center),
vertical_chunks[8],
);
}