Skip to content

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

refactor(tui): clean aligned two-tier footer dock with dynamic platform shortcuts

Samir Hossains2f17ec61741b
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index 1e9955a..dcaa229 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -263,12 +263,16 @@ impl App {
Constraint::Length(1),
Constraint::Min(0),
Constraint::Length(1),
+ Constraint::Length(1),
])
.split(area);
- let footer = vertical_chunks[6];
- if row == footer.y {
- self.handle_home_footer_click(col, area.width);
+ if row == vertical_chunks[6].y {
+ self.handle_home_mode_click(col, area.width);
+ return None;
+ }
+ if row == vertical_chunks[7].y {
+ self.handle_home_util_click(col, area.width);
return None;
}
@@ -359,45 +363,45 @@ impl App {
None
}
- fn handle_home_footer_click(&mut self, col: u16, width: u16) {
- enum FooterBtn {
+ fn handle_home_mode_click(&mut self, col: u16, width: u16) {
+ enum ModeBtn {
Streaming,
Tv,
Addon,
- Provider,
- Help,
- Quit,
}
- let mut buttons: Vec<(FooterBtn, u16)> = Vec::new();
+ let ctrl_s = crate::tui::text::ctrl_key("S");
+ let ctrl_t = crate::tui::text::ctrl_key("T");
+ let ctrl_a = crate::tui::text::ctrl_key("A");
+ let ctrl_p = crate::tui::text::ctrl_key("P");
+
+ let mut buttons: Vec<(ModeBtn, u16)> = Vec::new();
let sep = 3_u16;
- if self.state.addons_enabled {
- buttons.push((FooterBtn::Streaming, 19));
- buttons.push((FooterBtn::Tv, 12));
- buttons.push((FooterBtn::Addon, 16));
+ let is_streaming = !self.state.is_tv_mode && !self.state.is_addon_mode;
+ let b1_len = if is_streaming {
+ (1 + ctrl_p.len() + 2 + self.state.active_provider.label().chars().count()) as u16
+ } else {
+ (1 + ctrl_s.len() + 2 + 9) as u16
+ };
+ buttons.push((ModeBtn::Streaming, b1_len));
- if !self.state.is_tv_mode && !self.state.is_addon_mode {
- let p_len = 9 + self.state.active_provider.label().chars().count() as u16;
- buttons.push((FooterBtn::Provider, p_len));
- }
+ let b2_len = if self.state.is_tv_mode {
+ 6_u16
} else {
- if !self.state.is_tv_mode {
- let p_len = 9 + self.state.active_provider.label().chars().count() as u16;
- buttons.push((FooterBtn::Provider, p_len));
- }
- let tv_label = if self.state.is_tv_mode {
- "Streaming"
+ (1 + ctrl_t.len() + 2 + 2) as u16
+ };
+ buttons.push((ModeBtn::Tv, b2_len));
+
+ if self.state.addons_enabled {
+ let b3_len = if self.state.is_addon_mode {
+ 10_u16
} else {
- "TV"
+ (1 + ctrl_a.len() + 2 + 6) as u16
};
- let tv_w = 9 + tv_label.chars().count() as u16;
- buttons.push((FooterBtn::Tv, tv_w));
+ buttons.push((ModeBtn::Addon, b3_len));
}
- buttons.push((FooterBtn::Help, 8));
- buttons.push((FooterBtn::Quit, 8));
-
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;
@@ -407,22 +411,52 @@ impl App {
let end = start + w;
if col >= start && col <= end + 1 {
match btn {
- FooterBtn::Streaming => {
- self.action_sender.send(Action::SwitchToStreamingMode).ok();
- }
- FooterBtn::Tv => {
- self.action_sender.send(Action::ToggleTvMode).ok();
+ ModeBtn::Streaming => {
+ if is_streaming {
+ self.cycle_provider();
+ } else {
+ self.action_sender.send(Action::SwitchToStreamingMode).ok();
+ }
}
- FooterBtn::Addon => {
- self.action_sender.send(Action::ToggleAddonMode).ok();
+ ModeBtn::Tv => {
+ if !self.state.is_tv_mode {
+ self.action_sender.send(Action::ToggleTvMode).ok();
+ }
}
- FooterBtn::Provider => {
- self.cycle_provider();
+ ModeBtn::Addon => {
+ if !self.state.is_addon_mode {
+ self.action_sender.send(Action::ToggleAddonMode).ok();
+ }
}
- FooterBtn::Help => {
+ }
+ return;
+ }
+ curr_x += w + sep;
+ }
+ }
+
+ fn handle_home_util_click(&mut self, col: u16, width: u16) {
+ enum UtilBtn {
+ Help,
+ Quit,
+ }
+
+ let buttons: [(UtilBtn, u16); 2] = [(UtilBtn::Help, 8), (UtilBtn::Quit, 8)];
+ let sep = 3_u16;
+
+ 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;
+
+ for (btn, w) in buttons {
+ let start = curr_x;
+ let end = start + w;
+ if col >= start && col <= end + 1 {
+ match btn {
+ UtilBtn::Help => {
self.action_sender.send(Action::ToggleHelp).ok();
}
- FooterBtn::Quit => {
+ UtilBtn::Quit => {
self.action_sender.send(Action::Quit).ok();
}
}
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 69bbe23..b9b7f86 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -329,6 +329,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
Constraint::Length(1),
Constraint::Min(0),
Constraint::Length(1),
+ Constraint::Length(1),
])
.split(area);
@@ -376,93 +377,81 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
);
}
- let mut footer_spans = vec![];
- if state.addons_enabled {
- footer_spans.push(Span::styled("[", theme.text_dim));
- footer_spans.push(Span::styled("Ctrl+S", theme.shortcut));
- footer_spans.push(Span::styled("] ", theme.text_dim));
- footer_spans.push(Span::styled(
- "Streaming",
- if !state.is_tv_mode && !state.is_addon_mode {
- theme.text.add_modifier(Modifier::BOLD)
- } else {
- theme.text_dim
- },
+ let ctrl_s = crate::tui::text::ctrl_key("S");
+ let ctrl_t = crate::tui::text::ctrl_key("T");
+ let ctrl_a = crate::tui::text::ctrl_key("A");
+ let ctrl_p = crate::tui::text::ctrl_key("P");
+
+ let mut mode_spans = vec![];
+ if !state.is_tv_mode && !state.is_addon_mode {
+ mode_spans.push(Span::styled("[", theme.text_dim));
+ mode_spans.push(Span::styled(&ctrl_p, theme.shortcut));
+ mode_spans.push(Span::styled("] ", theme.text_dim));
+ mode_spans.push(Span::styled(
+ state.active_provider.label(),
+ theme.highlight.add_modifier(Modifier::BOLD),
));
- footer_spans.push(Span::raw(" "));
+ } else {
+ mode_spans.push(Span::styled("[", theme.text_dim));
+ mode_spans.push(Span::styled(&ctrl_s, theme.shortcut));
+ mode_spans.push(Span::styled("] ", theme.text_dim));
+ mode_spans.push(Span::styled("Streaming", theme.text_dim));
+ }
+
+ mode_spans.push(Span::raw(" "));
- footer_spans.push(Span::styled("[", theme.text_dim));
- footer_spans.push(Span::styled("Ctrl+T", theme.shortcut));
- footer_spans.push(Span::styled("] ", theme.text_dim));
- footer_spans.push(Span::styled(
+ if state.is_tv_mode {
+ mode_spans.push(Span::styled("[ ", theme.text_dim));
+ mode_spans.push(Span::styled(
"TV",
- if state.is_tv_mode {
- theme.text.add_modifier(Modifier::BOLD)
- } else {
- theme.text_dim
- },
- ));
- footer_spans.push(Span::raw(" "));
-
- footer_spans.push(Span::styled("[", theme.text_dim));
- footer_spans.push(Span::styled("Ctrl+A", theme.shortcut));
- footer_spans.push(Span::styled("] ", theme.text_dim));
- footer_spans.push(Span::styled(
- "Addons",
- if state.is_addon_mode {
- theme.text.add_modifier(Modifier::BOLD)
- } else {
- theme.text_dim
- },
+ theme.highlight.add_modifier(Modifier::BOLD),
));
- footer_spans.push(Span::raw(" "));
-
- if !state.is_tv_mode && !state.is_addon_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(" "));
- }
+ mode_spans.push(Span::styled(" ]", theme.text_dim));
} else {
- 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),
+ mode_spans.push(Span::styled("[", theme.text_dim));
+ mode_spans.push(Span::styled(&ctrl_t, theme.shortcut));
+ mode_spans.push(Span::styled("] ", theme.text_dim));
+ mode_spans.push(Span::styled("TV", theme.text_dim));
+ }
+
+ if state.addons_enabled {
+ mode_spans.push(Span::raw(" "));
+ if state.is_addon_mode {
+ mode_spans.push(Span::styled("[ ", theme.text_dim));
+ mode_spans.push(Span::styled(
+ "Addons",
+ theme.highlight.add_modifier(Modifier::BOLD),
));
- footer_spans.push(Span::raw(" "));
+ mode_spans.push(Span::styled(" ]", theme.text_dim));
+ } else {
+ mode_spans.push(Span::styled("[", theme.text_dim));
+ mode_spans.push(Span::styled(&ctrl_a, theme.shortcut));
+ mode_spans.push(Span::styled("] ", theme.text_dim));
+ mode_spans.push(Span::styled("Addons", theme.text_dim));
}
-
- footer_spans.push(Span::styled("[", theme.text_dim));
- footer_spans.push(Span::styled("Ctrl+T", theme.shortcut));
- footer_spans.push(Span::styled("] ", theme.text_dim));
- footer_spans.push(Span::styled(
- if state.is_tv_mode { "Streaming" } else { "TV" },
- theme.text_dim,
- ));
- 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(Line::from(footer_spans)).alignment(Alignment::Center),
+ Paragraph::new(Line::from(mode_spans)).alignment(Alignment::Center),
vertical_chunks[6],
);
+
+ let util_spans = 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(Line::from(util_spans)).alignment(Alignment::Center),
+ vertical_chunks[7],
+ );
} else {
let has_results = !state.search_results.is_empty();
let suggestion_height =
diff --git a/src/tui/text.rs b/src/tui/text.rs
index f944ae4..5a8da98 100644
--- a/src/tui/text.rs
+++ b/src/tui/text.rs
@@ -158,3 +158,13 @@ pub fn clean_stream_text(input: &str) -> String {
}
cleaned.trim().to_string()
}
+
+#[cfg(target_os = "macos")]
+pub const CTRL_PREFIX: &str = "^";
+
+#[cfg(not(target_os = "macos"))]
+pub const CTRL_PREFIX: &str = "Ctrl+";
+
+pub fn ctrl_key(key: &str) -> String {
+ format!("{CTRL_PREFIX}{key}")
+}