Skip to content

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

feat(tui): add floating pill HUD and event coalescing for smooth window resizing

Samir Hossains44bae1edbdf0
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 5cd01ca..3f18529 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -70,9 +70,7 @@ impl App {
loop {
if self.state.clear_terminal_before_draw {
- terminal.current_buffer_mut().reset();
- terminal.backend_mut().clear()?;
- terminal.swap_buffers();
+ terminal.clear()?;
self.state.clear_terminal_before_draw = false;
self.state.dirty = true;
}
@@ -86,18 +84,30 @@ impl App {
if let Some(quit) = self.handle_action(action).await {
return Ok(quit);
}
+ while let Ok(action) = events.try_recv() {
+ if let Some(quit) = self.handle_action(action).await {
+ return Ok(quit);
+ }
+ }
}
Some(action) = self.action_receiver.recv() => {
if let Some(quit) = self.handle_action(action).await {
return Ok(quit);
}
+ while let Ok(action) = self.action_receiver.try_recv() {
+ if let Some(quit) = self.handle_action(action).await {
+ return Ok(quit);
+ }
+ }
}
}
}
}
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 {
@@ -242,6 +252,43 @@ impl App {
return;
}
+ if let Some((time, w, h)) = self.state.last_resize_time {
+ if time.elapsed() < std::time::Duration::from_millis(150) {
+ let pill_w = 42_u16.min(area.width.saturating_sub(4));
+ let pill_h = 3_u16;
+ let pill_x = area.x + (area.width.saturating_sub(pill_w)) / 2;
+ let pill_y = area.y + (area.height.saturating_sub(pill_h)) / 2;
+ let pill_area = ratatui::layout::Rect {
+ x: pill_x,
+ y: pill_y,
+ width: pill_w,
+ height: pill_h,
+ };
+
+ let line = ratatui::text::Line::from(vec![
+ ratatui::text::Span::styled("● ", self.theme.accent),
+ ratatui::text::Span::styled("Resizing Window", self.theme.title),
+ ratatui::text::Span::styled(" · ", self.theme.text_dim),
+ ratatui::text::Span::styled(format!("{} × {} cols", w, h), self.theme.text),
+ ]);
+
+ let block = ratatui::widgets::Block::default()
+ .borders(ratatui::widgets::Borders::ALL)
+ .border_type(ratatui::widgets::BorderType::Rounded)
+ .border_style(self.theme.accent);
+
+ let p = ratatui::widgets::Paragraph::new(line)
+ .block(block)
+ .alignment(ratatui::layout::Alignment::Center);
+
+ frame.render_widget(p, pill_area);
+ return;
+ } else {
+ self.state.last_resize_time = None;
+ self.state.clear_terminal_before_draw = true;
+ }
+ }
+
let mut main_area = frame.area();
let mut download_area = None;
diff --git a/src/tui/app/system.rs b/src/tui/app/system.rs
index 359e491..11c6e9d 100644
--- a/src/tui/app/system.rs
+++ b/src/tui/app/system.rs
@@ -96,10 +96,10 @@ impl App {
self.prepare_image_soft_refresh();
}
- Action::Resize(_w, _h) => {
- self.prepare_image_refresh();
+ 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.dirty = true;
}
Action::SwitchProvider(provider) => self.switch_provider(provider),
diff --git a/src/tui/event.rs b/src/tui/event.rs
index c7b953c..a4544b4 100644
--- a/src/tui/event.rs
+++ b/src/tui/event.rs
@@ -66,4 +66,8 @@ impl EventHandler {
pub async fn next(&mut self) -> Option<Action> {
self.receiver.recv().await
}
+
+ pub fn try_recv(&mut self) -> Result<Action, mpsc::error::TryRecvError> {
+ self.receiver.try_recv()
+ }
}
diff --git a/src/tui/state.rs b/src/tui/state.rs
index da17224..efdd70e 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -243,6 +243,7 @@ pub struct AppState {
pub active_suggest_request: u64,
pub pending_episode_fetch: Option<(String, usize, usize)>,
pub last_episode_nav: std::time::Instant,
+ pub last_resize_time: Option<(std::time::Instant, u16, u16)>,
pub player_picker_popup: bool,
pub player_picker_state: ListState,
pub player_picker_link: Option<String>,
@@ -363,6 +364,7 @@ impl Default for AppState {
active_suggest_request: 0,
pending_episode_fetch: None,
last_episode_nav: std::time::Instant::now(),
+ last_resize_time: None,
player_picker_popup: false,
player_picker_state: ListState::default(),
player_picker_link: None,