Skip to content

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

feat: improve terminal compatibility with basic UI mode, dynamic poster scaling, and cross-platform player support

Samir Hossains9c6f47e350f5
diff --git a/Cargo.lock b/Cargo.lock
index d48441e..47e8a26 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2616,7 +2616,6 @@ dependencies = [
"base64-simd",
"icy_sixel",
"image",
- "pkg-config",
"rand 0.8.7",
"ratatui",
"rustix 0.38.44",
diff --git a/Cargo.toml b/Cargo.toml
index e25e783..58a8cda 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,7 +23,7 @@ lru = "0.18.1"
md-5 = "0.11.0"
rand = "0.10.2"
ratatui = "0.30.2"
-ratatui-image = "11.0.6"
+ratatui-image = { version = "11.0.6", default-features = false, features = ["crossterm", "image-defaults"] }
reqwest = { version = "0.13.4", features = ["json"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.150"
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 9c4be18..abf97bf 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -117,6 +117,10 @@ impl App {
if matches!(picker.protocol_type(), ratatui_image::picker::ProtocolType::Halfblocks) {
self.state.image_supported = false;
} else {
+ 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);
}
@@ -2397,9 +2401,18 @@ impl App {
c
}
crate::tui::state::PlayerKind::Iina => {
- let mut c = std::process::Command::new("open");
- c.arg("-a").arg("IINA").arg(&link);
- c
+ #[cfg(target_os = "macos")]
+ {
+ let mut c = std::process::Command::new("open");
+ c.arg("-a").arg("IINA").arg(&link);
+ c
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ let mut c = std::process::Command::new("mpv");
+ c.arg(&link);
+ c
+ }
}
crate::tui::state::PlayerKind::Vlc => {
let mut c = if std::path::Path::new("/Applications/VLC.app").exists() {
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index f69fbc9..a3f5c98 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -316,7 +316,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
.highlight_style(theme.highlight)
- .highlight_symbol("▌ ");
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
if let Some(area) = lang_area {
frame.render_stateful_widget(lang_list, area, &mut state.language_list_state);
@@ -349,7 +349,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
.highlight_style(theme.highlight)
- .highlight_symbol("▌ ");
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
if let Some(area) = seasons_area {
frame.render_stateful_widget(seasons_list, area, &mut state.season_list_state);
@@ -382,7 +382,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.padding(ratatui::widgets::Padding::horizontal(1)),
)
.highlight_style(theme.highlight)
- .highlight_symbol("▌ ");
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
if let Some(area) = eps_area {
frame.render_stateful_widget(eps_list, area, &mut state.episode_list_state);
@@ -455,7 +455,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
};
let is_selected = Some(i) == selected_idx;
- let pointer = if is_selected { "▌ " } else { " " };
+ let pointer = if is_selected {
+ if state.basic_terminal { "> " } else { "▌ " }
+ } else {
+ " "
+ };
let stream_style = if is_selected {
theme.highlight
@@ -611,7 +615,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.border_style(theme.border),
)
.highlight_style(theme.highlight)
- .highlight_symbol("▌ ");
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
frame.render_stateful_widget(list, popup_area, &mut state.subtitle_list_state);
}
@@ -653,7 +657,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.border_style(theme.border),
)
.highlight_style(theme.highlight)
- .highlight_symbol("▌ ");
+ .highlight_symbol(if state.basic_terminal { "> " } else { "▌ " });
frame.render_stateful_widget(list, popup_area, &mut state.player_picker_state);
}
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 4419d15..9c50882 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -262,7 +262,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
let selected_idx = state.search_list_state.selected();
let offset = state.search_list_state.offset();
- let row_height = 3;
+ let row_height = state.poster_rows;
state.visible_items = (chunks[1].height as usize) / (row_height as usize);
let rows: Vec<Row> = state
.search_results
@@ -291,7 +291,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
x: inner_area.x,
y: current_y,
width: inner_area.width,
- height: 3.min(inner_area.y + inner_area.height.saturating_sub(current_y)),
+ height: state.poster_rows.min(inner_area.y + inner_area.height.saturating_sub(current_y)),
};
if item_area.height == 0 {
@@ -304,7 +304,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.direction(Direction::Horizontal)
.constraints([
Constraint::Length(2),
- Constraint::Length(if state.image_supported { 4 } else { 0 }),
+ Constraint::Length(if state.image_supported { state.poster_rows + 1 } else { 0 }),
Constraint::Length(if state.image_supported { 1 } else { 0 }),
Constraint::Min(0),
])
@@ -340,7 +340,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
if let Some(picker) = &mut state.image_picker {
let size = ratatui::layout::Size::new(
poster_area.width,
- poster_area.height.min(3),
+ poster_area.height.min(state.poster_rows),
);
if let Ok(proto) = picker.new_protocol(
(**img).clone(),
@@ -355,7 +355,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
}
if let Some((_, proto)) = state.search_poster_protocols.get(&res.id) {
let p_area = Rect {
- height: poster_area.height.min(3),
+ height: poster_area.height.min(state.poster_rows),
..poster_area
};
frame.render_widget(ratatui_image::Image::new(proto), p_area);
@@ -414,7 +414,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.or_else(|| meta.get("imdbRatingValue"))
.and_then(|v| v.as_str());
if let Some(r) = rating {
- info_spans.push(ratatui::text::Span::styled("★ ", theme.rating));
+ let star = if state.basic_terminal { "* " } else { "★ " };
+ info_spans.push(ratatui::text::Span::styled(star, theme.rating));
info_spans.push(ratatui::text::Span::styled(r, theme.text));
info_spans.push(ratatui::text::Span::styled(" • ", theme.text_dim));
}
@@ -466,7 +467,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.begin_symbol(Some("▲"))
.end_symbol(Some("▼"))
.track_symbol(Some("│"))
- .thumb_symbol("█");
+ .thumb_symbol(if state.basic_terminal { "|" } else { "█" });
let mut scrollbar_state = ratatui::widgets::ScrollbarState::default()
.content_length(content_len.saturating_sub(state.visible_items))
diff --git a/src/tui/state.rs b/src/tui/state.rs
index b56330c..f9ef551 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -79,6 +79,7 @@ pub struct AppState {
pub poster_protocol: Option<(ratatui::layout::Rect, ratatui_image::protocol::Protocol)>,
pub image_picker: Option<ratatui_image::picker::Picker>,
pub image_supported: bool,
+ pub poster_rows: u16,
pub image_cache: lru::LruCache<String, std::sync::Arc<image::DynamicImage>>,
pub show_help: bool,
@@ -169,10 +170,12 @@ impl Default for AppState {
|| term_program.to_lowercase() == "ghostty"
|| term_program.to_lowercase() == "wezterm"
|| std::env::var("WEZTERM_UNIX_SOCKET").is_ok()
+ || std::env::var("WEZTERM_EXECUTABLE").is_ok()
|| std::env::var("ITERM_SESSION_ID").is_ok()
|| term == "xterm-kitty"
}
},
+ poster_rows: 3,
image_cache: lru::LruCache::new(std::num::NonZeroUsize::new(10).unwrap()),
show_help: false,
visible_items: 10,
diff --git a/src/tui/theme.rs b/src/tui/theme.rs
index f2769c1..66597d6 100644
--- a/src/tui/theme.rs
+++ b/src/tui/theme.rs
@@ -52,7 +52,8 @@ impl Theme {
let colorterm = std::env::var("COLORTERM").unwrap_or_default().to_lowercase();
let term = std::env::var("TERM").unwrap_or_default().to_lowercase();
- let truecolor = colorterm == "truecolor" || colorterm == "24bit" || term.contains("truecolor");
+ let wt_truecolor = std::env::var("WT_SESSION").is_ok();
+ let truecolor = wt_truecolor || colorterm == "truecolor" || colorterm == "24bit" || term.contains("truecolor");
if !truecolor && (term.contains("apple") || term == "dumb" || term == "linux" || std::env::var("TERM_PROGRAM").unwrap_or_default() == "Apple_Terminal") {
Self::fallback()