Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
feat: implement terminal environment detection and responsive UI layouts with improved theme-aware animations
Samir Hossains4efd49d895f9
diff --git a/src/cache.rs b/src/cache.rsindex 5c4f744..5764111 100644--- a/src/cache.rs+++ b/src/cache.rs@@ -242,5 +242,3 @@ pub fn set_homepage_cache(tab_id: &str, page: usize, data: &serde_json::Value) {let _ = fs::write(&path, content);}}--diff --git a/src/download.rs b/src/download.rsindex b9fce0d..c74eecb 100644--- a/src/download.rs+++ b/src/download.rs@@ -705,5 +705,3 @@ async fn retry_delay(attempt: usize) {tokio::time::sleep(Duration::from_secs(1 << (attempt - 1))).await;}}--diff --git a/src/providers/models.rs b/src/providers/models.rsindex c4800a9..1a77e60 100644--- a/src/providers/models.rs+++ b/src/providers/models.rs@@ -134,5 +134,3 @@ impl PlaybackSource {}}}--diff --git a/src/tui/app.rs b/src/tui/app.rsindex c319bd1..6d00590 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -4547,7 +4547,7 @@ impl App {}if let Some(prog) = self.state.download_progress {if let Some(dl_area) = download_area {- use ratatui::widgets::{Block, Borders, Clear, Gauge};+ use ratatui::widgets::{Block, Borders, Gauge};let status = self.state@@ -4576,7 +4576,7 @@ impl App {.gauge_style(self.theme.accent).ratio((prog / 100.0).clamp(0.0, 1.0));- frame.render_widget(Clear, dl_area);+ crate::tui::clear_area(frame, dl_area, &self.theme);frame.render_widget(gauge, dl_area);}}diff --git a/src/tui/mod.rs b/src/tui/mod.rsindex f0cb3ea..b1d812a 100644--- a/src/tui/mod.rs+++ b/src/tui/mod.rs@@ -3,7 +3,13 @@ pub mod app;pub mod event;pub mod iptv_data;pub mod state;+pub mod terminal;pub mod theme;++pub fn clear_area(frame: &mut ratatui::Frame, area: ratatui::layout::Rect, _theme: &theme::Theme) {+ frame.render_widget(ratatui::widgets::Clear, area);+}+pub mod screens {pub mod details;pub mod help;diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rsindex 37577bf..f4bddef 100644--- a/src/tui/screens/details.rs+++ b/src/tui/screens/details.rs@@ -4,8 +4,8 @@ use ratatui::{layout::{Alignment, Constraint, Direction, Layout, Rect},text::{Line, Span},widgets::{- Block, Borders, Clear, List, ListItem, Paragraph, Scrollbar, ScrollbarOrientation,- ScrollbarState, Wrap,+ Block, Borders, List, ListItem, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState,+ Wrap,},};@@ -138,14 +138,14 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)let poster_width = if state.image_supported {(inner_area.height as f32 * 1.33).ceil() as u16} else {- 0+ 20};let h_chunks = Layout::default().direction(Direction::Horizontal).constraints([Constraint::Length(poster_width),- Constraint::Length(if state.image_supported { 4 } else { 0 }),+ Constraint::Length(2),Constraint::Min(1),]).split(inner_area);@@ -157,46 +157,67 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)};let right_area = h_chunks[2];- if let Some(img) = &state.poster_image {- if state.poster_protocol.as_ref().map(|(r, _)| *r) != Some(poster_area)- && let Some(picker) = &mut state.image_picker- {- let size = ratatui::layout::Size::new(poster_area.width, poster_area.height);- if let Ok(proto) =- picker.new_protocol(img.clone(), size, ratatui_image::Resize::Fit(None))+ if state.image_supported {+ if let Some(img) = &state.poster_image {+ if state.poster_protocol.as_ref().map(|(r, _)| *r) != Some(poster_area)+ && let Some(picker) = &mut state.image_picker{- state.poster_protocol = Some((poster_area, proto));+ let size = ratatui::layout::Size::new(poster_area.width, poster_area.height);+ if let Ok(proto) =+ picker.new_protocol(img.clone(), size, ratatui_image::Resize::Fit(None))+ {+ state.poster_protocol = Some((poster_area, proto));+ }}- }- if let Some((_, proto)) = &state.poster_protocol {- if !state.show_help {- frame.render_widget(ratatui_image::Image::new(proto), poster_area);+ if let Some((_, proto)) = &state.poster_protocol {+ if !state.show_help {+ frame.render_widget(ratatui_image::Image::new(proto), poster_area);+ }}- }- } else if state.image_supported {- let current_spinner = if state.basic_terminal {- let frames = ['-', '\\', '|', '/'];- frames[(state.tick_count as usize) % frames.len()]} else {- let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];- frames[(state.tick_count as usize) % frames.len()]- };+ let current_spinner = if state.basic_terminal {+ let frames = ['-', '\\', '|', '/'];+ frames[(state.tick_count as usize) % frames.len()]+ } else {+ let frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];+ frames[(state.tick_count as usize) % frames.len()]+ };++ let placeholder_block = Block::default()+ .borders(Borders::ALL)+ .border_style(theme.muted);++ let inner = placeholder_block.inner(poster_area);++ let (pad, msg) = if state.is_loading {+ let p = "\n".repeat((inner.height.saturating_sub(1) / 2) as usize);+ (p, format!("{}\nLoading Art", current_spinner))+ } else {+ let p = "\n".repeat((inner.height.saturating_sub(1) / 2) as usize);+ (p, title.to_string())+ };+ let placeholder = Paragraph::new(format!("{}{}", pad, msg))+ .style(theme.text_dim)+ .alignment(Alignment::Center)+ .wrap(Wrap { trim: true })+ .block(placeholder_block);+ frame.render_widget(placeholder, poster_area);+ }+ } else {let placeholder_block = Block::default().borders(Borders::ALL).border_style(theme.muted);let inner = placeholder_block.inner(poster_area);-- let (pad, msg) = if state.is_loading {- let p = "\n".repeat((inner.height.saturating_sub(1) / 2) as usize);- (p, format!("{}\nLoading Art", current_spinner))+ let lines = if inner.height >= 5 {+ let pad_top = "\n".repeat((inner.height.saturating_sub(5) / 2) as usize);+ format!("{pad_top}Poster preview\nunsupported\n\nUse a graphics-\ncapable terminal")} else {- let p = "\n".repeat((inner.height.saturating_sub(1) / 2) as usize);- (p, title.to_string())+ "Poster\nunsupported".to_string()};- let placeholder = Paragraph::new(format!("{}{}", pad, msg))+ let placeholder = Paragraph::new(lines).style(theme.text_dim).alignment(Alignment::Center).wrap(Wrap { trim: true })@@ -679,7 +700,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)height: popup_height,};- frame.render_widget(ratatui::widgets::Clear, popup_area);+ crate::tui::clear_area(frame, popup_area, theme);let items: Vec<ratatui::widgets::ListItem> = state.subtitle_list@@ -724,7 +745,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)height: popup_height,};- frame.render_widget(ratatui::widgets::Clear, popup_area);+ crate::tui::clear_area(frame, popup_area, theme);let items: Vec<ratatui::widgets::ListItem> = state.available_players@@ -774,7 +795,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)popup_width,popup_height,);- frame.render_widget(Clear, popup_area);+ crate::tui::clear_area(frame, popup_area, theme);let season_idx = state.selected_season;let eps_count = if season_idx > 0 && season_idx <= state.available_episode_numbers.len() {@@ -844,7 +865,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)popup_width,popup_height,);- frame.render_widget(Clear, popup_area);+ crate::tui::clear_area(frame, popup_area, theme);let season_idx = state.selected_season;let ep_idx = state.selected_episode;diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rsindex 78640bf..eabc1ba 100644--- a/src/tui/screens/help.rs+++ b/src/tui/screens/help.rs@@ -3,7 +3,7 @@ use ratatui::{Frame,layout::{Alignment, Constraint, Direction, Layout, Rect},text::{Line, Span},- widgets::{Block, BorderType, Borders, Clear, Paragraph},+ widgets::{Block, BorderType, Borders, Paragraph},};pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {@@ -178,7 +178,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &AppState, theme: &Theme) {]).split(popup_layout[1])[1];- frame.render_widget(Clear, popup_chunk);+ crate::tui::clear_area(frame, popup_chunk, theme);let block = Block::default().title(" Keybindings Help ")diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex a85eabe..bddd6e8 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -110,6 +110,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)} else {if state.is_tv_mode { 57 } else { 55 }};+ let compact_footer = area.width < 100;+ let footer_height = if compact_footer { 2 } else { 1 };let vertical_chunks = Layout::default().direction(Direction::Vertical)@@ -121,7 +123,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)Constraint::Length(3),Constraint::Length(3),Constraint::Min(0),- Constraint::Length(1),+ Constraint::Length(footer_height),Constraint::Length(1),]).split(area);@@ -149,10 +151,10 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)theme.title} else {let t = state.tick_count as f32 / 8.0;-- let r = (49.0 + (203.0 - 49.0) * t) as u8;- let g = (50.0 + (166.0 - 50.0) * t) as u8;- let b = (68.0 + (247.0 - 68.0) * t) as u8;+ let (start, end) = logo_fade_colors(theme);+ let r = (start.0 + (end.0 - start.0) * t) as u8;+ let g = (start.1 + (end.1 - start.1) * t) as u8;+ let b = (start.2 + (end.2 - start.2) * t) as u8;ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(r, g, b))};@@ -162,9 +164,10 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)let row_tick_start = 1 + i as u64;if state.tick_count >= row_tick_start {let row_t = ((state.tick_count - row_tick_start) as f32 / 7.0).clamp(0.0, 1.0);- let r = (49.0 + (203.0 - 49.0) * row_t) as u8;- let g = (50.0 + (166.0 - 50.0) * row_t) as u8;- let b = (68.0 + (247.0 - 68.0) * row_t) as u8;+ let (start, end) = logo_fade_colors(theme);+ let r = (start.0 + (end.0 - start.0) * row_t) as u8;+ let g = (start.1 + (end.1 - start.1) * row_t) as u8;+ let b = (start.2 + (end.2 - start.2) * row_t) as u8;let row_style =ratatui::style::Style::default().fg(ratatui::style::Color::Rgb(r, g, b));@@ -185,7 +188,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)}let version_style = if state.tick_count < 6 {- ratatui::style::Style::default().fg(theme.base)+ theme.surface1} else {theme.text_dim};@@ -208,7 +211,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)frame.render_widget(search_bar, search_bar_area);}- let legend_line = ratatui::text::Line::from(vec![+ let primary_legend = vec![ratatui::text::Span::styled("[", theme.text_dim),ratatui::text::Span::styled("Ctrl+P", theme.shortcut),ratatui::text::Span::styled("] ", theme.text_dim),@@ -230,7 +233,16 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)ratatui::text::Span::styled("[", theme.text_dim),ratatui::text::Span::styled("Type", theme.shortcut),ratatui::text::Span::styled("] ", theme.text_dim),- ratatui::text::Span::styled("Search ", theme.text),+ ratatui::text::Span::styled(+ if compact_footer {+ "Search"+ } else {+ "Search "+ },+ theme.text,+ ),+ ];+ let secondary_legend = vec![ratatui::text::Span::styled("[", theme.text_dim),ratatui::text::Span::styled("↑↓", theme.shortcut),ratatui::text::Span::styled("] ", theme.text_dim),@@ -243,9 +255,19 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)ratatui::text::Span::styled("q", theme.shortcut),ratatui::text::Span::styled("] ", theme.text_dim),ratatui::text::Span::styled("Quit", theme.text),- ]);+ ];- let legend = Paragraph::new(legend_line).alignment(Alignment::Center);+ let legend = if compact_footer {+ Paragraph::new(vec![+ ratatui::text::Line::from(primary_legend),+ ratatui::text::Line::from(secondary_legend),+ ])+ } else {+ let mut legend = primary_legend;+ legend.extend(secondary_legend);+ Paragraph::new(ratatui::text::Line::from(legend))+ }+ .alignment(Alignment::Center);frame.render_widget(legend, vertical_chunks[7]);if let Some(version_str) = &state.update_available {@@ -401,9 +423,9 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)Constraint::Length(if state.image_supported {state.poster_rows + 1} else {- 0+ 12}),- Constraint::Length(if state.image_supported { 1 } else { 0 }),+ Constraint::Length(1),Constraint::Min(0),]).split(item_area);@@ -432,8 +454,8 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)frame.render_widget(indicator, v_layout[1]);}- if let Some(img) = state.search_posters.peek(&res.id) {- if state.image_supported {+ if state.image_supported {+ if let Some(img) = state.search_posters.peek(&res.id) {let target_dims = (poster_area.width, state.poster_rows);let needs_protocol =state.search_poster_protocols.peek(&res.id).map(|(d, _)| *d)@@ -459,7 +481,25 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)};frame.render_widget(ratatui_image::Image::new(proto), p_area);}+ } else {+ let placeholder = Paragraph::new("Poster\nunavailable")+ .style(theme.text_dim)+ .alignment(Alignment::Center);+ frame.render_widget(placeholder, poster_area);}+ } else {+ let placeholder_height = item_area.height.min(2);+ let v_center = item_area.height.saturating_sub(placeholder_height) / 2;+ let p_area = Rect {+ x: poster_area.x,+ y: poster_area.y + v_center,+ width: 12,+ height: placeholder_height,+ };+ let placeholder = Paragraph::new("Poster\nunsupported")+ .style(theme.text_dim)+ .alignment(Alignment::Center);+ frame.render_widget(placeholder, p_area);}let text_layout = Layout::default()@@ -645,7 +685,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)if dropdown_area.y + dropdown_area.height <= area.height || search_area.y > area.height / 2{- frame.render_widget(ratatui::widgets::Clear, dropdown_area);+ crate::tui::clear_area(frame, dropdown_area, theme);let items: Vec<ratatui::widgets::ListItem> = state.search_suggestions.iter()@@ -785,7 +825,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)height: popup_height,};- frame.render_widget(ratatui::widgets::Clear, popup_area);+ crate::tui::clear_area(frame, popup_area, theme);let items: Vec<ratatui::widgets::ListItem> = state.available_players@@ -819,3 +859,11 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)frame.render_stateful_widget(list, popup_area, &mut state.player_picker_state);}}++fn logo_fade_colors(theme: &Theme) -> ((f32, f32, f32), (f32, f32, f32)) {+ if theme.is_light {+ ((172.0, 176.0, 190.0), (136.0, 57.0, 239.0))+ } else {+ ((73.0, 76.0, 94.0), (203.0, 166.0, 247.0))+ }+}diff --git a/src/tui/state.rs b/src/tui/state.rsindex 1fcda93..edabde8 100644--- a/src/tui/state.rs+++ b/src/tui/state.rs@@ -176,17 +176,7 @@ impl Default for AppState {search_posters: lru::LruCache::new(std::num::NonZeroUsize::new(30).unwrap()),search_poster_protocols: lru::LruCache::new(std::num::NonZeroUsize::new(30).unwrap()),search_list_state: TableState::default(),- basic_terminal: {- let term = std::env::var("TERM").unwrap_or_default();- let term_program = std::env::var("TERM_PROGRAM").unwrap_or_default();- let is_windows = cfg!(target_os = "windows");- let is_dumb = term == "dumb" || term == "linux";- let is_apple_terminal = term_program == "Apple_Terminal";- let is_tmux = std::env::var("TMUX").is_ok();- let is_ssh =- std::env::var("SSH_TTY").is_ok() || std::env::var("SSH_CLIENT").is_ok();- is_windows || is_dumb || is_apple_terminal || is_tmux || is_ssh- },+ basic_terminal: crate::tui::terminal::uses_basic_ui(),selected_details: None,active_subject_id: None,selected_resources: None,@@ -217,15 +207,7 @@ impl Default for AppState {poster_image: None,poster_protocol: None,image_picker: None,- image_supported: {- let term = std::env::var("TERM").unwrap_or_default();- let term_program = std::env::var("TERM_PROGRAM").unwrap_or_default();- !(term_program == "Apple_Terminal"- || term == "dumb"- || term == "linux"- || std::env::var("TMUX").is_ok()- || std::env::var("SSH_TTY").is_ok())- },+ image_supported: crate::tui::terminal::should_query_images(),poster_rows: 3,image_cache: lru::LruCache::new(std::num::NonZeroUsize::new(10).unwrap()),show_help: false,diff --git a/src/tui/terminal.rs b/src/tui/terminal.rsnew file mode 100644index 0000000..0303ab0--- /dev/null+++ b/src/tui/terminal.rs@@ -0,0 +1,41 @@+fn env(name: &str) -> String {+ std::env::var(name).unwrap_or_default()+}++pub fn uses_basic_ui() -> bool {+ let term = env("TERM");+ let term_program = env("TERM_PROGRAM");++ cfg!(target_os = "windows")+ || term == "dumb"+ || term == "linux"+ || term_program == "Apple_Terminal"+ || std::env::var_os("TMUX").is_some()+ || std::env::var_os("SSH_TTY").is_some()+ || std::env::var_os("SSH_CLIENT").is_some()+}++pub fn should_query_images() -> bool {+ let term = env("TERM");+ let term_program = env("TERM_PROGRAM");++ term != "dumb"+ && term != "linux"+ && term_program != "Apple_Terminal"+ && std::env::var_os("TMUX").is_none()+ && std::env::var_os("SSH_TTY").is_none()+ && std::env::var_os("SSH_CLIENT").is_none()+}++pub fn background_is_light() -> bool {+ if let Ok(value) = std::env::var("COLORFGBG")+ && let Some(background) = value+ .split([';', ':'])+ .next_back()+ .and_then(|value| value.parse::<u8>().ok())+ {+ return matches!(background, 7 | 10..=15);+ }++ std::env::var("TERM_BACKGROUND").is_ok_and(|value| value.eq_ignore_ascii_case("light"))+}diff --git a/src/tui/theme.rs b/src/tui/theme.rsindex 6b06af0..4d5e42e 100644--- a/src/tui/theme.rs+++ b/src/tui/theme.rs@@ -21,71 +21,229 @@ pub struct Theme {pub sapphire: Style,pub subtext1: Style,pub base: Color,+ pub bg: Style,+ pub rosewater: Style,+ pub flamingo: Style,+ pub maroon: Style,+ pub surface0: Style,+ pub surface1: Style,+ pub surface2: Style,+ pub overlay0: Style,+ pub overlay1: Style,+ pub overlay2: Style,+ pub mantle: Style,+ pub crust: Style,+ pub is_light: bool,}impl Default for Theme {fn default() -> Self {+ Self::mocha()+ }+}++impl Theme {+ pub fn mocha() -> Self {Self {- border: Style::default().fg(Color::Rgb(88, 91, 112)),- border_focus: Style::default().fg(Color::Rgb(137, 180, 250)),- text: Style::default().fg(Color::Rgb(205, 214, 244)),- text_dim: Style::default().fg(Color::Rgb(166, 173, 200)),+ border: Style::default().fg(cp(88, 91, 112)),+ border_focus: Style::default().fg(cp(137, 180, 250)),+ text: Style::default().fg(cp(205, 214, 244)),+ text_dim: Style::default().fg(cp(166, 173, 200)),title: Style::default()- .fg(Color::Rgb(203, 166, 247))+ .fg(cp(203, 166, 247)).add_modifier(Modifier::BOLD),highlight: Style::default()- .fg(Color::Rgb(137, 180, 250))+ .fg(cp(137, 180, 250)).add_modifier(Modifier::BOLD),header: Style::default()- .fg(Color::Rgb(245, 194, 231))+ .fg(cp(245, 194, 231)).add_modifier(Modifier::BOLD),- error: Style::default().fg(Color::Rgb(243, 139, 168)),- success: Style::default().fg(Color::Rgb(166, 227, 161)),- shortcut: Style::default().fg(Color::Rgb(250, 179, 135)),- overlay: Style::default().fg(Color::Rgb(108, 112, 134)),- rating: Style::default().fg(Color::Rgb(249, 226, 175)),+ error: Style::default().fg(cp(243, 139, 168)),+ success: Style::default().fg(cp(166, 227, 161)),+ shortcut: Style::default().fg(cp(250, 179, 135)),+ overlay: Style::default().fg(cp(108, 112, 134)),+ rating: Style::default().fg(cp(249, 226, 175)),accent: Style::default()- .fg(Color::Rgb(137, 220, 235))+ .fg(cp(137, 220, 235)).add_modifier(Modifier::BOLD),- muted: Style::default().fg(Color::Rgb(88, 91, 112)),- teal: Style::default().fg(Color::Rgb(148, 226, 213)),- lavender: Style::default().fg(Color::Rgb(180, 190, 254)),- sapphire: Style::default().fg(Color::Rgb(116, 199, 236)),- subtext1: Style::default().fg(Color::Rgb(186, 194, 222)),- base: Color::Rgb(30, 30, 46),+ muted: Style::default().fg(cp(88, 91, 112)),+ teal: Style::default().fg(cp(148, 226, 213)),+ lavender: Style::default().fg(cp(180, 190, 254)),+ sapphire: Style::default().fg(cp(116, 199, 236)),+ subtext1: Style::default().fg(cp(186, 194, 222)),+ base: cp(30, 30, 46),+ bg: Style::default(),+ rosewater: Style::default().fg(cp(245, 224, 220)),+ flamingo: Style::default().fg(cp(242, 205, 205)),+ maroon: Style::default().fg(cp(235, 160, 172)),+ surface0: Style::default().fg(cp(56, 58, 74)),+ surface1: Style::default().fg(cp(73, 76, 94)),+ surface2: Style::default().fg(cp(88, 91, 112)),+ overlay0: Style::default().fg(cp(108, 112, 134)),+ overlay1: Style::default().fg(cp(127, 132, 156)),+ overlay2: Style::default().fg(cp(147, 153, 178)),+ mantle: Style::default().fg(cp(24, 24, 37)),+ crust: Style::default().fg(cp(17, 17, 27)),+ is_light: false,+ }+ }++ pub fn latte() -> Self {+ Self {+ border: Style::default().fg(cp(156, 160, 176)),+ border_focus: Style::default().fg(cp(30, 102, 245)),+ text: Style::default().fg(cp(76, 79, 105)),+ text_dim: Style::default().fg(cp(108, 111, 133)),+ title: Style::default()+ .fg(cp(136, 57, 239))+ .add_modifier(Modifier::BOLD),+ highlight: Style::default()+ .fg(cp(30, 102, 245))+ .add_modifier(Modifier::BOLD),+ header: Style::default()+ .fg(cp(234, 118, 203))+ .add_modifier(Modifier::BOLD),+ error: Style::default().fg(cp(210, 15, 57)),+ success: Style::default().fg(cp(64, 160, 43)),+ shortcut: Style::default().fg(cp(254, 100, 11)),+ overlay: Style::default().fg(cp(156, 160, 176)),+ rating: Style::default().fg(cp(223, 142, 29)),+ accent: Style::default()+ .fg(cp(23, 146, 153))+ .add_modifier(Modifier::BOLD),+ muted: Style::default().fg(cp(156, 160, 176)),+ teal: Style::default().fg(cp(23, 146, 153)),+ lavender: Style::default().fg(cp(114, 135, 253)),+ sapphire: Style::default().fg(cp(32, 159, 181)),+ subtext1: Style::default().fg(cp(92, 95, 119)),+ base: cp(239, 241, 245),+ bg: Style::default(),+ rosewater: Style::default().fg(cp(220, 138, 120)),+ flamingo: Style::default().fg(cp(221, 120, 120)),+ maroon: Style::default().fg(cp(230, 69, 83)),+ surface0: Style::default().fg(cp(204, 208, 218)),+ surface1: Style::default().fg(cp(188, 192, 204)),+ surface2: Style::default().fg(cp(172, 176, 190)),+ overlay0: Style::default().fg(cp(156, 160, 176)),+ overlay1: Style::default().fg(cp(140, 143, 161)),+ overlay2: Style::default().fg(cp(124, 127, 147)),+ mantle: Style::default().fg(cp(230, 233, 239)),+ crust: Style::default().fg(cp(220, 224, 232)),+ is_light: true,}}-}-impl Theme {pub fn new() -> Self {let colorterm = std::env::var("COLORTERM").unwrap_or_default().to_lowercase();let term = std::env::var("TERM").unwrap_or_default().to_lowercase();+ let term_program = std::env::var("TERM_PROGRAM").unwrap_or_default();+ let has_no_color = std::env::var("NO_COLOR").is_ok();+ let is_light = crate::tui::terminal::background_is_light();- let wt_truecolor = std::env::var("WT_SESSION").is_ok();- let truecolor = wt_truecolor- || colorterm == "truecolor"+ match std::env::var("MOVIEBOX_THEME")+ .unwrap_or_default()+ .to_ascii_lowercase()+ .as_str()+ {+ "latte" | "light" => return Self::latte(),+ "mocha" | "dark" => return Self::mocha(),+ _ => {}+ }++ if has_no_color {+ return Self::monochrome(is_light);+ }++ let truecolor = colorterm == "truecolor"|| colorterm == "24bit"- || term.contains("truecolor");+ || term.contains("truecolor")+ || term.contains("kitty")+ || std::env::var("WT_SESSION").is_ok()+ || term_program == "iTerm.app"+ || term_program == "Hyper"+ || term_program == "Tabby"+ || term_program == "WezTerm"+ || term_program == "WarpTerminal"+ || term_program == "vscode"+ || term_program == "ghostty";- if !truecolor- && (term.contains("apple")- || term == "dumb"- || term == "linux"- || std::env::var("TERM_PROGRAM").unwrap_or_default() == "Apple_Terminal")- {- Self::fallback()+ let basic = term == "dumb" || term == "linux" || term.contains("fbterm");+ let apple_term = term.contains("apple") || term_program == "Apple_Terminal";+ let has_256 = term.contains("256") || term.contains("xterm") || term.contains("screen");++ if truecolor {+ if is_light {+ Self::latte()+ } else {+ Self::mocha()+ }+ } else if basic || (apple_term && !has_256) || term == "xterm" {+ Self::fallback(is_light)+ } else if has_256 {+ if is_light {+ Self::latte()+ } else {+ Self::mocha()+ }} else {- Self::default()+ Self::fallback(is_light)}}- pub fn fallback() -> Self {+ pub fn monochrome(is_light: bool) -> Self {+ let foreground = if is_light { Color::Black } else { Color::White };+ let dim = if is_light {+ Color::DarkGray+ } else {+ Color::Gray+ };Self {border: Style::default().fg(Color::DarkGray),- border_focus: Style::default().fg(Color::Blue),+ border_focus: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ text: Style::default().fg(foreground),+ text_dim: Style::default().fg(dim),+ title: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ highlight: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ header: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ error: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ success: Style::default().fg(foreground),+ shortcut: Style::default().fg(foreground),+ overlay: Style::default().fg(Color::DarkGray),+ rating: Style::default().fg(foreground),+ accent: Style::default().fg(foreground).add_modifier(Modifier::BOLD),+ muted: Style::default().fg(Color::DarkGray),+ teal: Style::default().fg(foreground),+ lavender: Style::default().fg(foreground),+ sapphire: Style::default().fg(foreground),+ subtext1: Style::default().fg(foreground),+ base: Color::Reset,+ bg: Style::default(),+ rosewater: Style::default().fg(foreground),+ flamingo: Style::default().fg(foreground),+ maroon: Style::default().fg(foreground),+ surface0: Style::default().fg(Color::DarkGray),+ surface1: Style::default().fg(Color::DarkGray),+ surface2: Style::default().fg(Color::DarkGray),+ overlay0: Style::default().fg(Color::DarkGray),+ overlay1: Style::default().fg(dim),+ overlay2: Style::default().fg(dim),+ mantle: Style::default().fg(foreground),+ crust: Style::default().fg(foreground),+ is_light,+ }+ }++ pub fn fallback(is_light: bool) -> Self {+ if is_light {+ return Self::latte();+ }+ Self {+ border: Style::default().fg(Color::DarkGray),+ border_focus: Style::default()+ .fg(Color::Blue)+ .add_modifier(Modifier::BOLD),text: Style::default().fg(Color::White),text_dim: Style::default().fg(Color::Gray),title: Style::default()@@ -97,7 +255,7 @@ impl Theme {header: Style::default().fg(Color::Magenta).add_modifier(Modifier::BOLD),- error: Style::default().fg(Color::Red),+ error: Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),success: Style::default().fg(Color::Green),shortcut: Style::default().fg(Color::Yellow),overlay: Style::default().fg(Color::DarkGray),@@ -111,6 +269,23 @@ impl Theme {sapphire: Style::default().fg(Color::Cyan),subtext1: Style::default().fg(Color::White),base: Color::Black,+ bg: Style::default(),+ rosewater: Style::default().fg(Color::White),+ flamingo: Style::default().fg(Color::Magenta),+ maroon: Style::default().fg(Color::Red),+ surface0: Style::default().fg(Color::DarkGray),+ surface1: Style::default().fg(Color::DarkGray),+ surface2: Style::default().fg(Color::DarkGray),+ overlay0: Style::default().fg(Color::DarkGray),+ overlay1: Style::default().fg(Color::Gray),+ overlay2: Style::default().fg(Color::Gray),+ mantle: Style::default().fg(Color::Black),+ crust: Style::default().fg(Color::Black),+ is_light,}}}++fn cp(r: u8, g: u8, b: u8) -> Color {+ Color::Rgb(r, g, b)+}