Skip to content

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

fix(tui): compact home tier, reserved status row, truthful update-modal zones

Samir Hossains32534d9d1861
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index c100e03..7d52d59 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -15,9 +15,13 @@ impl App {
return None;
}
+ let screen_area = ratatui::layout::Rect {
+ height: area.height.saturating_sub(1),
+ ..area
+ };
match self.state.active_screen {
- Screen::Home => self.handle_home_mouse(col, row, area),
- Screen::Details => self.handle_details_mouse(col, row, area),
+ Screen::Home => self.handle_home_mouse(col, row, screen_area),
+ Screen::Details => self.handle_details_mouse(col, row, screen_area),
}
}
@@ -337,41 +341,40 @@ impl App {
let is_landing = self.state.search_results.is_empty()
&& (self.state.search_query.trim().is_empty()
|| self.state.input_mode == InputMode::Editing);
- let logo_height = if self.state.basic_terminal { 2 } else { 6 };
let search_width =
crate::tui::screens::home::search_deck_width(area, &self.state, is_landing);
let search_bar_area = if is_landing {
- let vertical_chunks = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Percentage(16),
- Constraint::Length(logo_height),
- Constraint::Length(1),
- Constraint::Length(3),
- Constraint::Length(1),
- Constraint::Length(1),
- Constraint::Min(0),
- Constraint::Length(1),
- Constraint::Length(1),
- ])
- .split(area);
+ let (tier, rows) = crate::tui::screens::home::landing_split(
+ area,
+ self.state.is_tv_mode,
+ self.state.basic_terminal,
+ );
+ let compact = tier.is_compact();
- if row == vertical_chunks[7].y {
- self.handle_home_mode_click(col, area.width);
+ if row == rows.rects[rows.mode_row].y {
+ if compact {
+ if col < area.width / 2 {
+ self.handle_home_mode_click(col, area.width, true);
+ } else {
+ self.handle_home_util_click(col, area.width, true);
+ }
+ } else {
+ self.handle_home_mode_click(col, area.width, false);
+ }
return None;
}
- if row == vertical_chunks[8].y {
- self.handle_home_util_click(col, area.width);
+ if rows.util_row.is_some() && row == rows.rects[rows.util_row.unwrap()].y {
+ self.handle_home_util_click(col, area.width, false);
return None;
}
if self.state.favorites_landing_visible()
- && self.handle_favorites_landing_click(col, row, vertical_chunks[6])
+ && self.handle_favorites_landing_click(col, row, rows.rects[rows.favorites])
{
return None;
}
- centered_width_rect(vertical_chunks[4], search_width)
+ centered_width_rect(rows.rects[rows.search], search_width)
} else {
let chunks = Layout::default()
.direction(Direction::Vertical)
@@ -503,7 +506,7 @@ impl App {
true
}
- fn handle_home_mode_click(&mut self, col: u16, width: u16) {
+ fn handle_home_mode_click(&mut self, col: u16, width: u16, left_aligned: bool) {
enum ModeBtn {
Streaming,
Tv,
@@ -549,7 +552,11 @@ impl App {
let total_w: u16 = buttons.iter().map(|(_, w)| *w).sum::<u16>()
+ (buttons.len().saturating_sub(1) as u16) * sep;
- let mut curr_x = width.saturating_sub(total_w) / 2;
+ let mut curr_x = if left_aligned {
+ 0
+ } else {
+ width.saturating_sub(total_w) / 2
+ };
for (btn, w) in buttons {
let start = curr_x;
@@ -580,7 +587,7 @@ impl App {
}
}
- fn handle_home_util_click(&mut self, col: u16, width: u16) {
+ fn handle_home_util_click(&mut self, col: u16, width: u16, right_aligned: bool) {
enum UtilBtn {
Help,
Quit,
@@ -591,7 +598,11 @@ impl App {
let total_w: u16 = buttons.iter().map(|(_, w)| *w).sum::<u16>()
+ (buttons.len().saturating_sub(1) as u16) * sep;
- let mut curr_x = width.saturating_sub(total_w) / 2;
+ let mut curr_x = if right_aligned {
+ width.saturating_sub(total_w)
+ } else {
+ width.saturating_sub(total_w) / 2
+ };
for (btn, w) in buttons {
let start = curr_x;
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 856d5aa..238cba4 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -535,12 +535,21 @@ impl App {
download_area = Some(chunks[1]);
}
+ let screen_area = ratatui::layout::Rect {
+ height: main_area.height.saturating_sub(1),
+ ..main_area
+ };
match self.state.active_screen {
Screen::Home => {
- crate::tui::screens::home::draw(frame, main_area, &mut self.state, &self.theme);
+ crate::tui::screens::home::draw(frame, screen_area, &mut self.state, &self.theme);
}
Screen::Details => {
- crate::tui::screens::details::draw(frame, main_area, &mut self.state, &self.theme);
+ crate::tui::screens::details::draw(
+ frame,
+ screen_area,
+ &mut self.state,
+ &self.theme,
+ );
}
}
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index eacbe0b..9ad6940 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -452,9 +452,11 @@ pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {
.filter(|l| !l.is_empty())
.count();
- let min_w: u16 = 46;
+ let min_w: u16 = 58;
let max_w: u16 = 72;
- let desired_w = max_w.min(area.width.saturating_sub(4)).max(min_w);
+ let desired_w = max_w
+ .min(area.width.saturating_sub(4))
+ .max(min_w.min(area.width));
let header_rows: u16 = 5;
let footer_rows: u16 = 3;
@@ -468,11 +470,18 @@ pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {
header_rows + (display_count as u16) + (if has_more { 1 } else { 0 }) + footer_rows;
let desired_h = total_rows.clamp(10, available_height.max(10));
- let popup_area = centered(area, desired_w, desired_h, min_w, max_w);
+ const UPDATE_SEGMENT: u16 = 18;
+ const OPEN_SEGMENT: u16 = 26;
+ const DISMISS_SEGMENT: u16 = 12;
+ let footer_width = UPDATE_SEGMENT + OPEN_SEGMENT + DISMISS_SEGMENT;
+
+ let popup_area = centered(area, desired_w, desired_h, min_w.min(area.width), max_w);
let button_row_y = popup_area.y + popup_area.height.saturating_sub(2);
- let update_btn_end_x = popup_area.x + popup_area.width / 3;
- let open_btn_end_x = popup_area.x + (popup_area.width * 2) / 3;
- let open_button_midpoint_x = popup_area.x + popup_area.width / 2;
+ let inner_width = popup_area.width.saturating_sub(2);
+ let footer_start = popup_area.x + 1 + inner_width.saturating_sub(footer_width) / 2;
+ let update_btn_end_x = footer_start + UPDATE_SEGMENT;
+ let open_btn_end_x = update_btn_end_x + OPEN_SEGMENT;
+ let open_button_midpoint_x = update_btn_end_x + OPEN_SEGMENT / 2;
UpdateModalLayout {
popup_area,
@@ -502,7 +511,31 @@ mod tests {
assert_eq!(layout.popup_area.x, (80 - 72) / 2);
assert_eq!(layout.popup_area.y, (24 - 12) / 2);
assert_eq!(layout.button_row_y, layout.popup_area.y + 10);
- assert_eq!(layout.open_button_midpoint_x, layout.popup_area.x + 36);
+ let footer_start = layout.popup_area.x + 1 + (70 - 56) / 2;
+ assert_eq!(layout.update_btn_end_x, footer_start + 18);
+ assert_eq!(layout.open_btn_end_x, layout.update_btn_end_x + 26);
+ assert_eq!(layout.open_button_midpoint_x, layout.update_btn_end_x + 13);
+ }
+
+ #[test]
+ fn test_update_modal_zones_cover_visible_labels_only() {
+ let area = Rect::new(0, 0, 80, 24);
+ let layout = update_modal_layout(area, "notes");
+ let row = layout.button_row_y;
+
+ assert!(layout.popup_area.contains(ratatui::layout::Position::new(
+ layout.update_btn_end_x - 2,
+ row
+ )));
+ assert!(layout.popup_area.contains(ratatui::layout::Position::new(
+ layout.open_btn_end_x - 2,
+ row
+ )));
+
+ let gap_before_open = layout.update_btn_end_x;
+ assert!(gap_before_open < layout.open_btn_end_x);
+ let dismiss_center = layout.open_btn_end_x + 6;
+ assert!(dismiss_center > layout.open_btn_end_x);
}
#[test]
@@ -529,7 +562,7 @@ mod tests {
let notes = "Feature A";
let layout = update_modal_layout(area, notes);
- let dismiss_x = layout.open_button_midpoint_x + 5;
+ let dismiss_x = layout.open_btn_end_x + 6;
let dismiss_y = layout.button_row_y;
assert!(
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index d226355..e9688e7 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -66,6 +66,114 @@ pub(crate) fn poster_placeholder_lines(basic: bool) -> &'static str {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum HomeLayoutTier {
+ Compact,
+ Normal,
+ Wide,
+}
+
+impl HomeLayoutTier {
+ pub(crate) fn for_width(width: u16) -> Self {
+ if width < 76 {
+ Self::Compact
+ } else if width < 110 {
+ Self::Normal
+ } else {
+ Self::Wide
+ }
+ }
+
+ pub(crate) fn is_compact(self) -> bool {
+ self == Self::Compact
+ }
+}
+
+pub(crate) struct LandingRows {
+ pub rects: std::rc::Rc<[Rect]>,
+ pub logo: usize,
+ pub version: usize,
+ pub search: usize,
+ pub favorites: usize,
+ pub mode_row: usize,
+ pub util_row: Option<usize>,
+ pub logo_width: u16,
+}
+
+pub(crate) fn landing_split(
+ area: Rect,
+ tv_mode: bool,
+ basic_terminal: bool,
+) -> (HomeLayoutTier, LandingRows) {
+ let tier = HomeLayoutTier::for_width(area.width);
+ let compact_logo = tier.is_compact();
+ let effective_basic = basic_terminal || compact_logo;
+ let logo_height = if effective_basic { 2 } else { 6 };
+ let logo_width = if effective_basic {
+ if tv_mode { 33 } else { 31 }
+ } else if tv_mode {
+ 75
+ } else {
+ 73
+ };
+ if compact_logo {
+ let rects = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Percentage(12),
+ Constraint::Length(logo_height),
+ Constraint::Length(1),
+ Constraint::Length(3),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ Constraint::Min(0),
+ Constraint::Length(1),
+ ])
+ .split(area);
+ (
+ tier,
+ LandingRows {
+ rects,
+ logo: 1,
+ version: 2,
+ search: 4,
+ favorites: 6,
+ mode_row: 7,
+ util_row: None,
+ logo_width,
+ },
+ )
+ } else {
+ let rects = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Percentage(16),
+ Constraint::Length(logo_height),
+ Constraint::Length(1),
+ Constraint::Length(3),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ Constraint::Min(0),
+ Constraint::Length(1),
+ Constraint::Length(1),
+ ])
+ .split(area);
+ (
+ tier,
+ LandingRows {
+ rects,
+ logo: 1,
+ version: 2,
+ search: 4,
+ favorites: 6,
+ mode_row: 7,
+ util_row: Some(8),
+ logo_width,
+ },
+ )
+ }
+}
+
pub(crate) fn search_deck_width(area: Rect, state: &AppState, landing: bool) -> u16 {
let query_width = if state.search_query.is_empty() {
crate::tui::text::width(if state.is_tv_mode {
@@ -92,11 +200,16 @@ pub(crate) fn search_deck_width(area: Rect, state: &AppState, landing: bool) ->
0
};
- query_width
+ let deck = query_width
.saturating_add(10)
.saturating_add(status_width)
.max(minimum.min(maximum))
- .min(maximum)
+ .min(maximum);
+ if HomeLayoutTier::for_width(area.width).is_compact() {
+ deck.min(area.width.saturating_sub(6)).max(30)
+ } else {
+ deck
+ }
}
fn render_search_state(
@@ -216,7 +329,11 @@ fn render_favorites_landing(frame: &mut Frame, area: Rect, state: &AppState, the
}
let overflow = state.favorites.items.len().saturating_sub(items.len());
- let card_width = area.width.clamp(20, 56);
+ let card_width = if HomeLayoutTier::for_width(area.width).is_compact() {
+ area.width.clamp(20, 44)
+ } else {
+ area.width.clamp(20, 56)
+ };
let row_count = items.len() as u16;
let overflow_row = u16::from(overflow > 0);
let content_height = (1 + row_count + overflow_row).min(area.height);
@@ -392,9 +509,10 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
|| (view == SearchViewState::Editing && state.search_results.is_empty())
{
let basic_terminal = state.basic_terminal;
- let logo_height = if basic_terminal { 2 } else { 6 };
+ let (tier, rows) = landing_split(area, state.is_tv_mode, basic_terminal);
+ let vertical_chunks = rows.rects.clone();
- let logo_text = if basic_terminal {
+ let logo_text = if basic_terminal || tier.is_compact() {
if state.is_tv_mode {
"█▀▄▀█ █▀█ █ █ █ █▀▀ █▀▄ █▀█ ▀▄▀\n█ ▀ █ █▄█ ▀▄▀ █ ██▄ █▄▀ █▄█ █ █TV".to_string()
} else {
@@ -418,27 +536,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.to_string()
};
- let logo_width: u16 = if basic_terminal {
- if state.is_tv_mode { 33 } else { 31 }
- } else if state.is_tv_mode {
- 75
- } else {
- 73
- };
- let vertical_chunks = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Percentage(16),
- Constraint::Length(logo_height),
- Constraint::Length(1),
- Constraint::Length(3),
- Constraint::Length(1),
- Constraint::Length(1),
- Constraint::Min(0),
- Constraint::Length(1),
- Constraint::Length(1),
- ])
- .split(area);
+ let logo_width: u16 = rows.logo_width;
let pad = area.width.saturating_sub(logo_width) / 2;
let horizontal_chunks = Layout::default()
@@ -448,7 +546,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
Constraint::Length(logo_width),
Constraint::Min(0),
])
- .split(vertical_chunks[1]);
+ .split(vertical_chunks[rows.logo]);
let version_chunks = Layout::default()
.direction(Direction::Horizontal)
@@ -457,7 +555,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
Constraint::Length(logo_width),
Constraint::Min(0),
])
- .split(vertical_chunks[2]);
+ .split(vertical_chunks[rows.version]);
let title_art = Paragraph::new(logo_text)
.alignment(Alignment::Left)
@@ -470,7 +568,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
frame.render_widget(version, version_chunks[1]);
let search_width = search_deck_width(area, state, true);
- search_bar_area = centered_width(vertical_chunks[4], search_width);
+ search_bar_area = centered_width(vertical_chunks[rows.search], search_width);
if !state.tv_config_popup {
render_search_bar(
@@ -485,7 +583,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
if state.favorites_landing_visible() {
- render_favorites_landing(frame, vertical_chunks[6], state, theme);
+ render_favorites_landing(frame, vertical_chunks[rows.favorites], state, theme);
}
let ctrl_s = crate::tui::text::ctrl_key("S");
@@ -554,16 +652,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let mut mode_spans = vec![];
for (i, tab) in mode_tabs.into_iter().enumerate() {
if i > 0 {
- mode_spans.push(Span::raw(" "));
+ mode_spans.push(Span::raw(if tier.is_compact() { " " } else { " " }));
}
mode_spans.extend(tab);
}
- frame.render_widget(
- Paragraph::new(Line::from(mode_spans)).alignment(Alignment::Center),
- vertical_chunks[7],
- );
-
let util_spans = vec![
Span::styled("[", theme.text_dim),
Span::styled("?", theme.shortcut),
@@ -576,10 +669,29 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
Span::styled("Quit", theme.text_dim),
];
- frame.render_widget(
- Paragraph::new(Line::from(util_spans)).alignment(Alignment::Center),
- vertical_chunks[8],
- );
+ match rows.util_row {
+ Some(util_idx) => {
+ frame.render_widget(
+ Paragraph::new(Line::from(mode_spans)).alignment(Alignment::Center),
+ vertical_chunks[rows.mode_row],
+ );
+ frame.render_widget(
+ Paragraph::new(Line::from(util_spans)).alignment(Alignment::Center),
+ vertical_chunks[util_idx],
+ );
+ }
+ None => {
+ let row_rect = vertical_chunks[rows.mode_row];
+ frame.render_widget(
+ Paragraph::new(Line::from(mode_spans)).alignment(Alignment::Left),
+ row_rect,
+ );
+ frame.render_widget(
+ Paragraph::new(Line::from(util_spans)).alignment(Alignment::Right),
+ row_rect,
+ );
+ }
+ }
} else {
if state.is_loading && state.search_results.is_empty() {
render_search_state(frame, area, state, theme, SearchViewState::Loading);
diff --git a/tests/update_lifecycle.rs b/tests/update_lifecycle.rs
index 15917e2..33f7b5d 100644
--- a/tests/update_lifecycle.rs
+++ b/tests/update_lifecycle.rs
@@ -71,8 +71,9 @@ async fn test_update_modal_mouse_hitbox_matches_rendered_geometry() {
assert_eq!(layout.popup_area.height, 11);
assert_eq!(layout.button_row_y, layout.popup_area.y + 9);
- assert_eq!(layout.update_btn_end_x, layout.popup_area.x + 24);
- assert_eq!(layout.open_btn_end_x, layout.popup_area.x + 48);
+ let footer_start = layout.popup_area.x + 1 + (70 - 56) / 2;
+ assert_eq!(layout.update_btn_end_x, footer_start + 18);
+ assert_eq!(layout.open_btn_end_x, layout.update_btn_end_x + 26);
}
#[tokio::test]