Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
refactor: remove log console, simplify state management, and add shift-enter for stream playback options
Samir Hossainsd91465ba95bf
diff --git a/LICENSE b/LICENSE-MITsimilarity index 100%rename from LICENSErename to LICENSE-MITdiff --git a/src/main.rs b/src/main.rsindex 144277b..86c071c 100644--- a/src/main.rs+++ b/src/main.rs@@ -2,12 +2,14 @@ use moviebox_tui::tui::app::App;#[tokio::main]async fn main() -> std::io::Result<()> {+ crossterm::execute!(std::io::stdout(), crossterm::event::EnableFocusChange)?;let mut terminal = ratatui::init();let mut app = App::new();let result = app.run(&mut terminal).await;ratatui::restore();+ crossterm::execute!(std::io::stdout(), crossterm::event::DisableFocusChange)?;result}diff --git a/src/tui/action.rs b/src/tui/action.rsindex 85cd522..5a52876 100644--- a/src/tui/action.rs+++ b/src/tui/action.rs@@ -1,11 +1,13 @@#[derive(Debug, Clone)]pub enum Action {+ FocusChange,+ ShowPlayerPicker(String, Option<String>),+ LaunchPlayer(crate::tui::state::PlayerKind, String, Option<String>),Tick,Key(crossterm::event::KeyEvent),Quit,GoBack,SelectLanguage(usize),- ToggleLogs,Resize(u16, u16),ToggleHelp,Search {@@ -35,15 +37,14 @@ pub enum Action {MoveDown,MoveLeft,MoveRight,- ClosePopup,Submit,TabPane,FetchPreview(String),PreviewSuccess(String, serde_json::Value),PreviewFailure(String),CopyLink,- PlayStream,- ShowSubtitlePopup(String, serde_json::Value),+ PlayStream(bool),+ ShowSubtitlePopup(String, serde_json::Value, bool),LaunchMpv(String, Option<String>),DownloadStream,UpdateDownload(Option<f64>, Option<String>),@@ -55,13 +56,10 @@ pub enum Action {subject_id: String,season: usize,episode: usize,- absolute_episode_index: usize,- resolution: String,},ResourcesSuccess(u64, usize, usize, serde_json::Value),ResourcesFailure(u64, String),PosterSuccess(String, std::sync::Arc<image::DynamicImage>),SearchPosterLoaded(String, Option<std::sync::Arc<image::DynamicImage>>),- Log(String),UpdateAvailable(String),}diff --git a/src/tui/app.rs b/src/tui/app.rsindex 6928b9d..80daf72 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -62,21 +62,6 @@ impl App {}}- fn get_absolute_episode_index(&self) -> usize {- let mut absolute_episode_index = 0;- let selected_season_idx = self.state.season_list_state.selected().unwrap_or(0);- for (i, season) in self.state.available_seasons.iter().enumerate() {- if i < selected_season_idx {- absolute_episode_index +=- season.get("maxEp").and_then(|m| m.as_i64()).unwrap_or(1) as usize;- } else {- break;- }- }- absolute_episode_index += self.state.episode_list_state.selected().unwrap_or(0);- absolute_episode_index- }-fn trigger_episode_fetch(&mut self) {if let Some(id) = &self.state.active_subject_id {let se_idx = self.state.season_list_state.selected().unwrap_or(0);@@ -128,8 +113,21 @@ impl App {pub async fn run(&mut self, terminal: &mut DefaultTerminal) -> std::io::Result<()> {if self.state.image_picker.is_none() && self.state.image_supported {match ratatui_image::picker::Picker::from_query_stdio() {- Ok(picker) => {+ Ok(mut picker) => {+ let size = picker.font_size();+ let fallback = format!("{:?}", size).contains("8") && format!("{:?}", size).contains("16");+ let empty = format!("{:?}", size).contains("0");+ if fallback || empty {+ if let Ok(picker2) = ratatui_image::picker::Picker::from_query_stdio() {+ picker = picker2;+ }+ }self.state.image_picker = Some(picker);++ std::thread::sleep(std::time::Duration::from_millis(30));+ while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {+ let _ = crossterm::event::read();+ }}Err(_) => {self.state.image_supported = false;@@ -139,26 +137,16 @@ impl App {let mut events = EventHandler::new(Duration::from_millis(100));- let init_sender = self.action_sender.clone();+ let _init_sender = self.action_sender.clone();let client_clone = self.client.clone();tokio::spawn(async move {- init_sender- .send(Action::Log(- "Initializing MovieBox-Tui client session...".to_string(),- ))- .ok();+match client_clone.init().await {Ok(_) => {- init_sender- .send(Action::Log(- "MovieBox-Tui client initialized successfully.".to_string(),- ))- .ok();+ let _ = _init_sender;}- Err(e) => {- init_sender- .send(Action::Log(format!("Initialization failed: {:?}", e)))- .ok();+ Err(_e) => {+}}});@@ -254,8 +242,6 @@ impl App {subject_id,season: se,episode: ep,- absolute_episode_index: 0,- resolution: "".to_string(),}).ok();}@@ -263,13 +249,29 @@ impl App {}}Action::Quit => {- self.state.add_log("Quitting...".to_string());return Some(());}+ Action::FocusChange => {+ self.state.poster_protocol = None;+ self.state.search_poster_protocols.clear();+ self.state.selected_resources = None;+ self.state.resource_list_state.select(None);+ if self.state.image_picker.is_some() {+ std::thread::sleep(std::time::Duration::from_millis(30));+ while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {+ let _ = crossterm::event::read();+ }+ }+ }Action::Resize(_w, _h) => {- self.state.image_picker = ratatui_image::picker::Picker::from_query_stdio().ok();-self.state.poster_protocol = None;+ self.state.search_poster_protocols.clear();+ if self.state.image_picker.is_some() {+ std::thread::sleep(std::time::Duration::from_millis(30));+ while crossterm::event::poll(std::time::Duration::ZERO).unwrap_or(false) {+ let _ = crossterm::event::read();+ }+ }}Action::Key(key) => {use crossterm::event::{KeyCode, KeyModifiers};@@ -281,7 +283,7 @@ impl App {return Some(());}KeyCode::Char('l') => {- self.action_sender.send(Action::ToggleLogs).ok();+}_ => {}}@@ -404,9 +406,6 @@ impl App {KeyCode::Char('y') | KeyCode::Char('c') => {self.action_sender.send(Action::CopyLink).ok();}- KeyCode::Char('p') | KeyCode::Char('P') => {- self.action_sender.send(Action::PlayStream).ok();- }KeyCode::Char('d') | KeyCode::Char('D') => {self.action_sender.send(Action::DownloadStream).ok();}@@ -430,12 +429,13 @@ impl App {self.action_sender.send(Action::MoveRight).ok();}KeyCode::Enter => {+ let open_with = key.modifiers.contains(crossterm::event::KeyModifiers::SHIFT);if self.state.subtitle_popup {self.action_sender.send(Action::Submit).ok();} else {match self.state.details_pane {crate::tui::state::DetailsPane::Streams => {- self.action_sender.send(Action::PlayStream).ok();+ self.action_sender.send(Action::PlayStream(open_with)).ok();}crate::tui::state::DetailsPane::Seasons => {self.action_sender.send(Action::MoveRight).ok();@@ -459,9 +459,6 @@ impl App {.unwrap_or("".to_string()),season: self.state.selected_season,episode: self.state.selected_episode,- absolute_episode_index: self- .get_absolute_episode_index(),- resolution: "".to_string(),}).ok();self.action_sender@@ -477,22 +474,19 @@ impl App {},}}- Action::ToggleLogs => {- self.state.show_logs = !self.state.show_logs;- }+Action::ToggleHelp => {- if matches!(- self.state.active_screen,- Screen::Home | Screen::Search | Screen::Details- ) {+ if matches!(self.state.active_screen, Screen::Home | Screen::Details) {self.state.show_help = !self.state.show_help;}}-- Action::ClosePopup => {- self.state.active_popup = None;- }Action::GoBack => {+ if self.state.player_picker_popup {+ self.state.player_picker_popup = false;+ self.state.player_picker_link = None;+ self.state.player_picker_subtitle = None;+ return None;+ }if self.state.subtitle_popup {self.state.subtitle_popup = false;self.state.pending_play_link = None;@@ -505,6 +499,7 @@ impl App {match self.state.active_screen {Screen::Home => {if !self.state.search_results.is_empty() {+ self.state.search_poster_protocols.clear();self.state.search_results.clear();self.state.search_query.clear();self.state.search_preview = None;@@ -512,11 +507,9 @@ impl App {self.state.status_timer = 150;}}- Screen::Search => {- self.state.active_screen = Screen::Home;- }Screen::Details => {self.state.active_screen = Screen::Home;+ self.state.language_chosen = false;self.state.status_message ="Select a movie/series and press Enter".to_string();self.state.status_timer = 150;@@ -635,7 +628,6 @@ impl App {self.state.suggest_index = None;self.state.status_message = format!("Searching for '{}'...", query);self.state.status_timer = 150;- self.state.add_log(format!("API Search request: {}", query));let client = self.client.clone();let sender = self.action_sender.clone();@@ -672,10 +664,6 @@ impl App {self.state.suggest_index = None;self.state.status_message = format!("Loading discover tab...");self.state.status_timer = 150;- self.state.add_log(format!(- "API Homepage request: tab_id={} page={}",- tab_id, page- ));let client = self.client.clone();let sender = self.action_sender.clone();@@ -840,9 +828,6 @@ impl App {self.state.status_message = format!("Found {} results.", count);self.state.status_timer = 150;- self.state- .add_log(format!("Search completed: {} items loaded.", count));-if self.state.current_page <= 1 {if let Some(res) = self.state.search_results.first() {self.state.search_list_state.select(Some(0));@@ -858,7 +843,6 @@ impl App {self.state.is_loading = false;self.state.status_message = format!("Search failed: {}", err);self.state.status_timer = 150;- self.state.add_log(format!("Search API Error: {}", err));}Action::HomepageSuccess {tab_id,@@ -1011,10 +995,21 @@ impl App {self.state.is_loading = false;self.state.status_message = format!("Discover failed: {}", err);self.state.status_timer = 150;- self.state.add_log(format!("Homepage API Error: {}", err));}Action::MoveUp => {- if self.state.subtitle_popup {+ if self.state.player_picker_popup {+ let i = match self.state.player_picker_state.selected() {+ Some(i) => {+ if i == 0 {+ self.state.available_players.len() - 1+ } else {+ i - 1+ }+ }+ None => 0,+ };+ self.state.player_picker_state.select(Some(i));+ } else if self.state.subtitle_popup {let current = self.state.subtitle_list_state.selected().unwrap_or(0);if current > 0 {self.state.subtitle_list_state.select(Some(current - 1));@@ -1107,7 +1102,19 @@ impl App {}}Action::MoveDown => {- if self.state.subtitle_popup {+ if self.state.player_picker_popup {+ let i = match self.state.player_picker_state.selected() {+ Some(i) => {+ if i >= self.state.available_players.len() - 1 {+ 0+ } else {+ i + 1+ }+ }+ None => 0,+ };+ self.state.player_picker_state.select(Some(i));+ } else if self.state.subtitle_popup {let current = self.state.subtitle_list_state.selected().unwrap_or(0);if current + 1 < self.state.subtitle_list.len() {self.state.subtitle_list_state.select(Some(current + 1));@@ -1324,9 +1331,12 @@ impl App {let idx = self.state.subtitle_list_state.selected().unwrap_or(0);let sub_url = self.state.subtitle_list.get(idx).map(|(_, u)| u.clone());if let Some(link) = self.state.pending_play_link.take() {- self.action_sender- .send(Action::LaunchMpv(link, sub_url))- .ok();+ let open_with = self.state.pending_open_with;+ if open_with {+ self.action_sender.send(Action::ShowPlayerPicker(link, sub_url)).ok();+ } else {+ self.action_sender.send(Action::LaunchMpv(link, sub_url)).ok();+ }}return None;}@@ -1344,7 +1354,6 @@ impl App {self.state.episode_list_state.select(Some(0));self.state.language_chosen = false;self.state.poster_image = None;- self.state.poster_protocol = None;self.state.available_seasons.clear();self.state.status_message =format!("Loading details for {}...", item.title);@@ -1356,6 +1365,7 @@ impl App {}}Action::FetchDetails(id) => {+ self.state.poster_protocol = None;self.state.is_loading = true;self.state.stream_cache.clear();let client = self.client.clone();@@ -1409,7 +1419,6 @@ impl App {return None;}self.state.preview_loading = true;- self.state.selected_poster = None;let client = self.client.clone();let sender = self.action_sender.clone();let id_clone = id.clone();@@ -1449,7 +1458,7 @@ impl App {self.state.preview_loading = false;- self.state.preview_cache.insert(id.clone(), json.clone());+ self.state.preview_cache.put(id.clone(), json.clone());self.state.search_preview = Some(json.clone());self.state.poster_image = None;self.state.poster_protocol = None;@@ -1497,12 +1506,11 @@ impl App {}Action::SearchPosterLoaded(id, img_opt) => {if let Some(img) = img_opt {- self.state.search_posters.insert(id, img);+ self.state.search_posters.put(id, img);}}Action::PreviewFailure(err) => {self.state.preview_loading = false;- self.state.add_log(format!("Preview fetch failed: {}", err));}Action::CopyLink => {@@ -1513,15 +1521,13 @@ impl App {let _ = clipboard.set_text(link.clone());self.state.toast_message = Some("✓ Copied stream link!".to_string());self.state.toast_timer = 30;- self.state- .add_log("Stream link successfully copied to clipboard.".to_string());} else {self.state.status_message = format!("Link: {}", link);self.state.status_timer = 150;}}}- Action::PlayStream => {+ Action::PlayStream(open_with) => {if self.state.active_screen == Screen::Details&& let Some(link) = self.get_selected_link(){@@ -1543,17 +1549,25 @@ impl App {let link_clone = link.clone();tokio::spawn(async move {if let Ok(res) = client.get_ext_captions(&subject_id, &rid).await {- sender.send(Action::ShowSubtitlePopup(link_clone, res)).ok();+ sender.send(Action::ShowSubtitlePopup(link_clone, res, open_with)).ok();} else {- sender.send(Action::LaunchMpv(link_clone, None)).ok();+ if open_with {+ sender.send(Action::ShowPlayerPicker(link_clone, None)).ok();+ } else {+ sender.send(Action::LaunchMpv(link_clone, None)).ok();+ }}});} else {- self.action_sender.send(Action::LaunchMpv(link, None)).ok();+ if open_with {+ self.action_sender.send(Action::ShowPlayerPicker(link, None)).ok();+ } else {+ self.action_sender.send(Action::LaunchMpv(link, None)).ok();+ }}}}- Action::ShowSubtitlePopup(link, ext_captions) => {+ Action::ShowSubtitlePopup(link, ext_captions, open_with) => {let mut options = vec![("None".to_string(), "".to_string())];if let Some(captions_list) =@@ -1581,8 +1595,13 @@ impl App {self.state.subtitle_list = options;self.state.subtitle_list_state.select(Some(0));self.state.pending_play_link = Some(link);+ self.state.pending_open_with = open_with;} else {- self.action_sender.send(Action::LaunchMpv(link, None)).ok();+ if open_with {+ self.action_sender.send(Action::ShowPlayerPicker(link, None)).ok();+ } else {+ self.action_sender.send(Action::LaunchMpv(link, None)).ok();+ }}}Action::LaunchMpv(link, subtitle_url) => {@@ -1593,6 +1612,12 @@ impl App {let mut cmd = Command::new("mpv");cmd.arg(&link).stdout(Stdio::null()).stderr(Stdio::null());+ #[cfg(unix)]+ {+ use std::os::unix::process::CommandExt;+ cmd.process_group(0);+ }+if let Some(sub) = subtitle_url {if !sub.is_empty() {cmd.arg(format!("--sub-file={}", sub));@@ -1600,13 +1625,10 @@ impl App {}if cmd.spawn().is_ok() {- self.state.add_log("MPV started successfully.".to_string());} else {self.state.toast_message =Some("✗ Error: mpv player not found in PATH".to_string());self.state.toast_timer = 60;- self.state- .add_log("Error starting mpv process. Command failed.".to_string());}}Action::DownloadStream => {@@ -2176,8 +2198,6 @@ impl App {subject_id: id,season: se,episode: ep,- absolute_episode_index: self.get_absolute_episode_index(),- resolution: "".to_string(),}).ok();}@@ -2191,8 +2211,6 @@ impl App {subject_id,season,episode,- absolute_episode_index: _,- resolution: _,} => {self.state.active_resource_request =self.state.active_resource_request.wrapping_add(1);@@ -2263,7 +2281,7 @@ impl App {if let Some(ref subject_id) = self.state.active_subject_id {self.state.stream_cache- .insert((subject_id.clone(), target_se, target_ep), filtered.clone());+ .put((subject_id.clone(), target_se, target_ep), filtered.clone());}let mut result = serde_json::Map::new();@@ -2303,8 +2321,80 @@ impl App {self.state.toast_message = Some("✗ Cancelling download...".to_string());self.state.toast_timer = 40;}- Action::Log(msg) => {- self.state.add_log(msg);++ Action::ShowPlayerPicker(link, subtitle) => {+ let mut players = Vec::new();+ if std::path::Path::new("/Applications/IINA.app").exists()+ || std::process::Command::new("which").arg("iina").output().map(|o| o.status.success()).unwrap_or(false)+ {+ players.push(crate::tui::state::PlayerKind::Iina);+ }+ if std::path::Path::new("/Applications/mpv.app").exists()+ || std::process::Command::new("which").arg("mpv").output().map(|o| o.status.success()).unwrap_or(false)+ {+ players.push(crate::tui::state::PlayerKind::Mpv);+ }+ if std::path::Path::new("/Applications/VLC.app").exists()+ || std::process::Command::new("which").arg("vlc").output().map(|o| o.status.success()).unwrap_or(false)+ {+ players.push(crate::tui::state::PlayerKind::Vlc);+ }++ if players.is_empty() {+ self.state.toast_message =+ Some("✗ No media player found. Install mpv, IINA, or VLC.".to_string());+ self.state.toast_timer = 150;+ return None;+ }+ self.state.available_players = players;+ self.state.player_picker_popup = true;+ self.state.player_picker_link = Some(link);+ self.state.player_picker_subtitle = subtitle;+ self.state.player_picker_state.select(Some(0));+ self.state.subtitle_popup = false;+ }+ Action::LaunchPlayer(kind, link, sub) => {+ let mut cmd = match kind {+ crate::tui::state::PlayerKind::Mpv => {+ let mut c = std::process::Command::new("mpv");+ c.arg(&link);+ if let Some(s) = sub {+ c.arg(format!("--sub-file={}", s));+ }+ c+ }+ crate::tui::state::PlayerKind::Iina => {+ let mut c = std::process::Command::new("open");+ c.arg("-a").arg("IINA").arg(&link);+ c+ }+ crate::tui::state::PlayerKind::Vlc => {+ let mut c = if std::path::Path::new("/Applications/VLC.app").exists() {+ std::process::Command::new("/Applications/VLC.app/Contents/MacOS/VLC")+ } else {+ std::process::Command::new("vlc")+ };+ c.arg(&link);+ if let Some(s) = sub {+ c.arg("--sub-file").arg(s);+ }+ c+ }+ };+ cmd.stdout(std::process::Stdio::null());+ cmd.stderr(std::process::Stdio::null());++ #[cfg(unix)]+ {+ use std::os::unix::process::CommandExt;+ cmd.process_group(0);+ }++ if cmd.spawn().is_err() {+ self.state.toast_message = Some("✗ Failed to launch player".to_string());+ self.state.toast_timer = 60;+ }+ self.state.player_picker_popup = false;}Action::UpdateAvailable(version) => {self.state.update_available = Some(version);@@ -2356,13 +2446,11 @@ impl App {Screen::Details => {super::screens::details::draw(frame, area, &mut self.state, &self.theme);}- _ => {}- }- if self.state.show_logs {- super::screens::logs::draw(frame, area, &self.state, &self.theme);}++if self.state.show_help {super::screens::help::draw(frame, area, &self.state, &self.theme);}diff --git a/src/tui/event.rs b/src/tui/event.rsindex 68b737e..bfb4b61 100644--- a/src/tui/event.rs+++ b/src/tui/event.rs@@ -25,6 +25,9 @@ impl EventHandler {break;}}+ Ok(CrosstermEvent::FocusGained) => {+ let _ = event_sender.send(Action::FocusChange);+ }Ok(CrosstermEvent::Resize(w, h)) => {if event_sender.send(Action::Resize(w, h)).is_err() {break;diff --git a/src/tui/mod.rs b/src/tui/mod.rsindex b1a3097..a18f60b 100644--- a/src/tui/mod.rs+++ b/src/tui/mod.rs@@ -7,5 +7,4 @@ pub mod screens {pub mod details;pub mod help;pub mod home;- pub mod logs;}diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rsindex 0fec004..7497c89 100644--- a/src/tui/screens/details.rs+++ b/src/tui/screens/details.rs@@ -13,7 +13,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)let chunks = Layout::default().direction(Direction::Vertical).constraints([- Constraint::Length(14),+ Constraint::Min(12),Constraint::Length(1),Constraint::Min(10),Constraint::Length(1),@@ -606,7 +606,50 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)frame.render_stateful_widget(list, popup_area, &mut state.subtitle_list_state);}- let footer_text = "Enter Play D Download C Copy Link Esc Back";+ if state.player_picker_popup {+ let popup_width = 40;+ let popup_height = std::cmp::min(15, state.available_players.len() as u16 + 2);++ let area = frame.area();+ let popup_area = ratatui::layout::Rect {+ x: area.width.saturating_sub(popup_width) / 2,+ y: area.height.saturating_sub(popup_height) / 2,+ width: popup_width,+ height: popup_height,+ };++ frame.render_widget(ratatui::widgets::Clear, popup_area);++ let items: Vec<ratatui::widgets::ListItem> = state+ .available_players+ .iter()+ .map(|k| {+ let text = match k {+ crate::tui::state::PlayerKind::Mpv => "mpv (terminal)",+ crate::tui::state::PlayerKind::Iina => "IINA (macOS)",+ crate::tui::state::PlayerKind::Vlc => "VLC (cross-platform)",+ };+ ratatui::widgets::ListItem::new(text)+ })+ .collect();++ let list = ratatui::widgets::List::new(items)+ .block(+ ratatui::widgets::Block::default()+ .title(" Open With ")+ .title_style(theme.title)+ .borders(ratatui::widgets::Borders::ALL)+ .border_type(ratatui::widgets::BorderType::Rounded)+ .border_style(theme.border),+ )+ .highlight_style(theme.highlight)+ .highlight_symbol("▌ ");++ frame.render_stateful_widget(list, popup_area, &mut state.player_picker_state);+ }++ let footer_text =+ "Enter Play ⇧+Enter Open With... D Download C Copy Link Esc Back";let footer_p = Paragraph::new(footer_text).alignment(Alignment::Center).style(theme.muted);diff --git a/src/tui/screens/help.rs b/src/tui/screens/help.rsindex d03eb4c..945dda0 100644--- a/src/tui/screens/help.rs+++ b/src/tui/screens/help.rs@@ -7,26 +7,6 @@ use ratatui::{};pub fn draw(frame: &mut Frame, area: Rect, _state: &AppState, theme: &Theme) {- let popup_layout = Layout::default()- .direction(Direction::Vertical)- .constraints([- Constraint::Percentage(25),- Constraint::Length(16),- Constraint::Percentage(25),- ])- .split(area);-- let popup_chunk = Layout::default()- .direction(Direction::Horizontal)- .constraints([- Constraint::Percentage(25),- Constraint::Min(45),- Constraint::Percentage(25),- ])- .split(popup_layout[1])[1];-- frame.render_widget(Clear, popup_chunk);-let help_text = vec![Line::from(vec![Span::styled(" Global",@@ -84,8 +64,12 @@ pub fn draw(frame: &mut Frame, area: Rect, _state: &AppState, theme: &Theme) {theme.header.add_modifier(ratatui::style::Modifier::BOLD),)]),Line::from(vec![- Span::styled(" [p] ", theme.header),- Span::styled("Play Video", theme.text),+ Span::styled(" [Enter] ", theme.header),+ Span::styled("Play Video in mpv", theme.text),+ ]),+ Line::from(vec![+ Span::styled(" [⇧+Enter] ", theme.header),+ Span::styled("Open Player Picker", theme.text),]),Line::from(vec![Span::styled(" [d] ", theme.header),@@ -97,6 +81,29 @@ pub fn draw(frame: &mut Frame, area: Rect, _state: &AppState, theme: &Theme) {]),];+ let height = help_text.len() as u16 + 2;+ let margin_y = area.height.saturating_sub(height) / 2;++ let popup_layout = Layout::default()+ .direction(Direction::Vertical)+ .constraints([+ Constraint::Length(margin_y),+ Constraint::Length(height),+ Constraint::Min(0),+ ])+ .split(area);++ let popup_chunk = Layout::default()+ .direction(Direction::Horizontal)+ .constraints([+ Constraint::Percentage(25),+ Constraint::Min(45),+ Constraint::Percentage(25),+ ])+ .split(popup_layout[1])[1];++ frame.render_widget(Clear, popup_chunk);+let block = Block::default().title(" Keybindings Help ").title_alignment(Alignment::Center)diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex 309008b..eb87a65 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -332,7 +332,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)}let mut poster_rendered = false;- if let Some(img) = state.search_posters.get(&res.id) {+ if let Some(img) = state.search_posters.peek(&res.id) {if state.image_supported {let needs_protocol =state.search_poster_protocols.get(&res.id).map(|(r, _)| *r)diff --git a/src/tui/state.rs b/src/tui/state.rsindex cb66516..40295d1 100644--- a/src/tui/state.rs+++ b/src/tui/state.rs@@ -1,9 +1,15 @@use ratatui::widgets::{ListState, TableState};+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum PlayerKind {+ Mpv,+ Iina,+ Vlc,+}+#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum Screen {Home,- Search,Details,}@@ -43,7 +49,7 @@ pub struct AppState {pub is_homepage_mode: bool,pub current_tab_id: String,pub current_page: usize,- pub search_posters: std::collections::HashMap<String, std::sync::Arc<image::DynamicImage>>,+ pub search_posters: lru::LruCache<String, std::sync::Arc<image::DynamicImage>>,pub search_poster_protocols: std::collections::HashMap<String,(ratatui::layout::Rect, ratatui_image::protocol::Protocol),@@ -53,12 +59,8 @@ pub struct AppState {pub selected_details: Option<serde_json::Value>,pub active_subject_id: Option<String>,pub selected_resources: Option<serde_json::Value>,- pub stream_cache: std::collections::HashMap<(String, usize, usize), Vec<serde_json::Value>>,- pub preview_cache: std::collections::HashMap<String, serde_json::Value>,- pub active_popup: Option<String>,- pub selected_poster: Option<std::sync::Arc<image::DynamicImage>>,- pub selected_poster_protocol:- Option<(ratatui::layout::Rect, ratatui_image::protocol::Protocol)>,+ pub stream_cache: lru::LruCache<(String, usize, usize), Vec<serde_json::Value>>,+ pub preview_cache: lru::LruCache<String, serde_json::Value>,pub resource_list_state: ListState,pub details_pane: DetailsPane,@@ -79,16 +81,17 @@ pub struct AppState {pub image_supported: bool,pub image_cache: lru::LruCache<String, std::sync::Arc<image::DynamicImage>>,- pub show_logs: bool,pub show_help: bool,pub visible_items: usize,- pub logs: Vec<String>,- pub logs_scroll: usize,pub active_resource_request: u64,pub pending_episode_fetch: Option<(String, usize, usize)>,pub last_episode_nav: std::time::Instant,- pub active_error: Option<String>,+ pub player_picker_popup: bool,+ pub player_picker_state: ListState,+ pub player_picker_link: Option<String>,+ pub player_picker_subtitle: Option<String>,+ pub available_players: Vec<PlayerKind>,pub is_loading: bool,pub status_message: String,pub status_timer: usize,@@ -106,6 +109,7 @@ pub struct AppState {pub subtitle_list: Vec<(String, String)>,pub subtitle_list_state: ListState,pub pending_play_link: Option<String>,+ pub pending_open_with: bool,pub basic_terminal: bool,}@@ -123,18 +127,15 @@ impl Default for AppState {is_homepage_mode: false,current_tab_id: String::new(),current_page: 1,- search_posters: std::collections::HashMap::new(),+ search_posters: lru::LruCache::new(std::num::NonZeroUsize::new(30).unwrap()),search_poster_protocols: std::collections::HashMap::new(),search_list_state: TableState::default(),basic_terminal: std::env::var("TERM_PROGRAM").unwrap_or_default() == "Apple_Terminal",selected_details: None,active_subject_id: None,selected_resources: None,- stream_cache: std::collections::HashMap::new(),- preview_cache: std::collections::HashMap::new(),- active_popup: None,- selected_poster: None,- selected_poster_protocol: None,+ stream_cache: lru::LruCache::new(std::num::NonZeroUsize::new(50).unwrap()),+ preview_cache: lru::LruCache::new(std::num::NonZeroUsize::new(30).unwrap()),resource_list_state: ListState::default(),details_pane: DetailsPane::default(),@@ -153,15 +154,16 @@ impl Default for AppState {image_picker: None,image_supported: true,image_cache: lru::LruCache::new(std::num::NonZeroUsize::new(10).unwrap()),- show_logs: false,show_help: false,visible_items: 10,- logs: vec!["MovieBox-Tui started.".to_string()],- logs_scroll: 0,active_resource_request: 0,pending_episode_fetch: None,last_episode_nav: std::time::Instant::now(),- active_error: None,+ player_picker_popup: false,+ player_picker_state: ListState::default(),+ player_picker_link: None,+ player_picker_subtitle: None,+ available_players: Vec::new(),is_loading: false,status_message: String::new(),status_timer: 0,@@ -177,16 +179,7 @@ impl Default for AppState {subtitle_list: Vec::new(),subtitle_list_state: ListState::default(),pending_play_link: None,+ pending_open_with: false,}}}--impl AppState {- pub fn add_log(&mut self, msg: String) {- self.logs.push(msg);- if self.logs.len() > 200 {- self.logs.remove(0);- }- self.logs_scroll = self.logs.len().saturating_sub(1);- }-}