Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2953d73487 | |||
| cddfedf1a0 | |||
| 821a844fe0 | |||
| b7cc219f40 | |||
| b5fde2d5d4 | |||
| d53542afa6 | |||
| be9ee8c005 | |||
| 7c083cfb0e | |||
| b438065c23 | |||
| 0fa26db116 | |||
| 0ec328881a |
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-player"
|
name = "cm-player"
|
||||||
version = "0.1.26"
|
version = "0.1.37"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -50,22 +50,6 @@ impl ApiResponse {
|
|||||||
data: None,
|
data: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn success_with_data(data: serde_json::Value) -> Self {
|
|
||||||
Self {
|
|
||||||
success: true,
|
|
||||||
message: None,
|
|
||||||
data: Some(data),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn error(message: String) -> Self {
|
|
||||||
Self {
|
|
||||||
success: false,
|
|
||||||
message: Some(message),
|
|
||||||
data: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start the API server on a Unix socket
|
/// Start the API server on a Unix socket
|
||||||
|
|||||||
309
src/main.rs
309
src/main.rs
@@ -16,12 +16,15 @@ use ratatui::{backend::CrosstermBackend, Terminal};
|
|||||||
use state::{AppState, PlayerState};
|
use state::{AppState, PlayerState};
|
||||||
use std::io::{self, BufRead, BufReader, Write};
|
use std::io::{self, BufRead, BufReader, Write};
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
use tracing_subscriber;
|
use tracing_subscriber;
|
||||||
|
|
||||||
// UI update intervals and thresholds
|
// UI update intervals and thresholds
|
||||||
const METADATA_UPDATE_INTERVAL: u32 = 20; // Update metadata every N iterations (~2 seconds)
|
|
||||||
const POLL_DURATION_STOPPED_MS: u64 = 200; // 5 FPS when stopped
|
const POLL_DURATION_STOPPED_MS: u64 = 200; // 5 FPS when stopped
|
||||||
const POLL_DURATION_ACTIVE_MS: u64 = 100; // 10 FPS when playing/paused
|
const POLL_DURATION_ACTIVE_MS: u64 = 200; // 5 FPS when playing/paused - single batch poll
|
||||||
const DOUBLE_CLICK_MS: u128 = 500; // Double-click detection threshold
|
const DOUBLE_CLICK_MS: u128 = 500; // Double-click detection threshold
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
@@ -226,7 +229,7 @@ fn action_play_selection(state: &mut AppState, player: &mut player::Player, skip
|
|||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
// Explicitly resume playback in case MPV was paused
|
// Explicitly resume playback in case MPV was paused
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update once MPV has it ready
|
||||||
tracing::info!("Playing: {:?} (playlist: {} tracks)", path, state.playlist.len());
|
tracing::info!("Playing: {:?} (playlist: {} tracks)", path, state.playlist.len());
|
||||||
}
|
}
|
||||||
if state.visual_mode {
|
if state.visual_mode {
|
||||||
@@ -254,7 +257,6 @@ fn action_toggle_play_pause(state: &mut AppState, player: &mut player::Player) -
|
|||||||
if let Some(ref path) = state.current_file {
|
if let Some(ref path) = state.current_file {
|
||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
|
||||||
tracing::info!("Restarting playback: {:?}", path);
|
tracing::info!("Restarting playback: {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,14 +266,44 @@ fn action_toggle_play_pause(state: &mut AppState, player: &mut player::Player) -
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn action_stop(state: &mut AppState, player: &mut player::Player) -> Result<()> {
|
fn action_stop(state: &mut AppState, player: &mut player::Player, skip_position_update: &mut bool) -> Result<()> {
|
||||||
player.stop()?;
|
player.stop()?;
|
||||||
state.current_position = 0.0;
|
state.current_position = 0.0;
|
||||||
state.current_duration = 0.0;
|
state.current_duration = 0.0;
|
||||||
|
*skip_position_update = true; // Prevent auto-advance on manual stop
|
||||||
tracing::info!("Stopped");
|
tracing::info!("Stopped");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn action_volume_up(state: &mut AppState, player: &mut player::Player) -> Result<()> {
|
||||||
|
state.volume = (state.volume + 5).min(100);
|
||||||
|
player.set_volume(state.volume)?;
|
||||||
|
tracing::info!("Volume: {}%", state.volume);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn action_volume_down(state: &mut AppState, player: &mut player::Player) -> Result<()> {
|
||||||
|
state.volume = (state.volume - 5).max(0);
|
||||||
|
player.set_volume(state.volume)?;
|
||||||
|
tracing::info!("Volume: {}%", state.volume);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn action_volume_set(state: &mut AppState, player: &mut player::Player, volume: i64) -> Result<()> {
|
||||||
|
state.volume = volume.clamp(0, 100);
|
||||||
|
player.set_volume(state.volume)?;
|
||||||
|
tracing::info!("Volume: {}%", state.volume);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn action_seek(player: &mut player::Player, seconds: f64) -> Result<()> {
|
||||||
|
if player.get_player_state() != Some(PlayerState::Stopped) {
|
||||||
|
player.seek(seconds)?;
|
||||||
|
tracing::info!("Seek {}s", seconds);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn action_remove_from_playlist(state: &mut AppState, player: &mut player::Player) -> Result<()> {
|
fn action_remove_from_playlist(state: &mut AppState, player: &mut player::Player) -> Result<()> {
|
||||||
let was_playing_removed = state.playlist_index == state.selected_playlist_index;
|
let was_playing_removed = state.playlist_index == state.selected_playlist_index;
|
||||||
let was_playing = player.get_player_state() == Some(PlayerState::Playing);
|
let was_playing = player.get_player_state() == Some(PlayerState::Playing);
|
||||||
@@ -287,7 +319,7 @@ fn action_remove_from_playlist(state: &mut AppState, player: &mut player::Player
|
|||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
// Explicitly resume playback in case MPV was paused
|
// Explicitly resume playback in case MPV was paused
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -319,7 +351,7 @@ fn action_navigate_track(state: &mut AppState, player: &mut player::Player, dire
|
|||||||
*skip_position_update = true; // Skip position update after track change
|
*skip_position_update = true; // Skip position update after track change
|
||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("{} track: {:?}", track_name, path);
|
tracing::info!("{} track: {:?}", track_name, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,7 +360,7 @@ fn action_navigate_track(state: &mut AppState, player: &mut player::Player, dire
|
|||||||
if let Some(ref path) = state.current_file {
|
if let Some(ref path) = state.current_file {
|
||||||
*skip_position_update = true; // Skip position update after track change
|
*skip_position_update = true; // Skip position update after track change
|
||||||
player.play_paused(path)?;
|
player.play_paused(path)?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("{} track (paused): {:?}", track_name, path);
|
tracing::info!("{} track (paused): {:?}", track_name, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,6 +383,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
|||||||
state.playlist_index = state.selected_playlist_index;
|
state.playlist_index = state.selected_playlist_index;
|
||||||
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
||||||
|
|
||||||
|
|
||||||
if preserve_pause {
|
if preserve_pause {
|
||||||
if let Some(player_state) = player.get_player_state() {
|
if let Some(player_state) = player.get_player_state() {
|
||||||
match player_state {
|
match player_state {
|
||||||
@@ -359,7 +392,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
|||||||
*skip_position_update = true; // Skip position update after track change
|
*skip_position_update = true; // Skip position update after track change
|
||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("Jumped to track: {:?}", path);
|
tracing::info!("Jumped to track: {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +400,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
|||||||
if let Some(ref path) = state.current_file {
|
if let Some(ref path) = state.current_file {
|
||||||
*skip_position_update = true; // Skip position update after track change
|
*skip_position_update = true; // Skip position update after track change
|
||||||
player.play_paused(path)?;
|
player.play_paused(path)?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("Jumped to track (paused): {:?}", path);
|
tracing::info!("Jumped to track (paused): {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,7 +409,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
|||||||
*skip_position_update = true; // Skip position update after track change
|
*skip_position_update = true; // Skip position update after track change
|
||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("Started playing track: {:?}", path);
|
tracing::info!("Started playing track: {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,7 +421,7 @@ fn action_play_from_playlist(state: &mut AppState, player: &mut player::Player,
|
|||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
// Explicitly resume playback in case MPV was paused
|
// Explicitly resume playback in case MPV was paused
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
player.update_metadata();
|
// Metadata will be fetched by periodic update
|
||||||
tracing::info!("Playing from playlist: {:?}", path);
|
tracing::info!("Playing from playlist: {:?}", path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,7 +449,7 @@ fn handle_context_menu_action(menu_type: state::ContextMenuType, selected: usize
|
|||||||
}
|
}
|
||||||
state::ContextMenuType::TitleBar => {
|
state::ContextMenuType::TitleBar => {
|
||||||
match selected {
|
match selected {
|
||||||
0 => action_stop(state, player)?,
|
0 => action_stop(state, player, skip_position_update)?,
|
||||||
1 => {
|
1 => {
|
||||||
state.cycle_play_mode();
|
state.cycle_play_mode();
|
||||||
tracing::info!("Play mode: {:?}", state.play_mode);
|
tracing::info!("Play mode: {:?}", state.play_mode);
|
||||||
@@ -438,7 +471,6 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
player: &mut player::Player,
|
player: &mut player::Player,
|
||||||
api_rx: std::sync::mpsc::Receiver<api::ApiCommand>,
|
api_rx: std::sync::mpsc::Receiver<api::ApiCommand>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut metadata_update_counter = 0u32;
|
|
||||||
let mut last_position = 0.0f64;
|
let mut last_position = 0.0f64;
|
||||||
let mut needs_redraw = true;
|
let mut needs_redraw = true;
|
||||||
let mut skip_position_update = false;
|
let mut skip_position_update = false;
|
||||||
@@ -455,26 +487,11 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
tracing::debug!("Processing API command: {:?}", cmd);
|
tracing::debug!("Processing API command: {:?}", cmd);
|
||||||
match cmd {
|
match cmd {
|
||||||
api::ApiCommand::PlayPause => {
|
api::ApiCommand::PlayPause => {
|
||||||
if let Some(player_state) = player.get_player_state() {
|
action_toggle_play_pause(state, player)?;
|
||||||
match player_state {
|
state_changed = true;
|
||||||
PlayerState::Stopped => {
|
|
||||||
// Play current file or first in playlist
|
|
||||||
if state.current_file.is_none() && !state.playlist.is_empty() {
|
|
||||||
state.current_file = Some(state.playlist[0].clone());
|
|
||||||
}
|
|
||||||
if let Some(ref file) = state.current_file {
|
|
||||||
player.play(file)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PlayerState::Playing => player.pause()?,
|
|
||||||
PlayerState::Paused => player.resume()?,
|
|
||||||
}
|
|
||||||
state_changed = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
api::ApiCommand::Stop => {
|
api::ApiCommand::Stop => {
|
||||||
player.stop()?;
|
action_stop(state, player, &mut skip_position_update)?;
|
||||||
state.current_file = None;
|
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::Next => {
|
api::ApiCommand::Next => {
|
||||||
@@ -486,26 +503,23 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::VolumeUp => {
|
api::ApiCommand::VolumeUp => {
|
||||||
state.volume = (state.volume + 5).min(100);
|
action_volume_up(state, player)?;
|
||||||
player.set_volume(state.volume)?;
|
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::VolumeDown => {
|
api::ApiCommand::VolumeDown => {
|
||||||
state.volume = (state.volume - 5).max(0);
|
action_volume_down(state, player)?;
|
||||||
player.set_volume(state.volume)?;
|
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::VolumeSet { volume } => {
|
api::ApiCommand::VolumeSet { volume } => {
|
||||||
state.volume = volume.clamp(0, 100);
|
action_volume_set(state, player, volume)?;
|
||||||
player.set_volume(state.volume)?;
|
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::SeekForward { seconds } => {
|
api::ApiCommand::SeekForward { seconds } => {
|
||||||
player.seek(seconds)?;
|
action_seek(player, seconds)?;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::SeekBackward { seconds } => {
|
api::ApiCommand::SeekBackward { seconds } => {
|
||||||
player.seek(-seconds)?;
|
action_seek(player, -seconds)?;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
api::ApiCommand::GetStatus => {
|
api::ApiCommand::GetStatus => {
|
||||||
@@ -518,19 +532,22 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if mpv process died (e.g., user closed video window)
|
// Check if mpv process died (e.g., user closed video window or force killed)
|
||||||
if !player.is_process_alive() {
|
if !player.is_process_alive() {
|
||||||
if let Some(player_state) = player.get_player_state() {
|
tracing::info!("MPV process died, recreating...");
|
||||||
if player_state != PlayerState::Stopped {
|
state.current_position = 0.0;
|
||||||
state.current_position = 0.0;
|
state.current_duration = 0.0;
|
||||||
state.current_duration = 0.0;
|
state.current_file = None;
|
||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
skip_position_update = true; // Prevent auto-advance when MPV was killed
|
||||||
}
|
|
||||||
|
// Recreate player for next playback
|
||||||
|
*player = player::Player::new()?;
|
||||||
|
previous_player_state = Some(PlayerState::Stopped);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update properties to keep state synchronized with MPV
|
// Always update all properties in one batch to keep state synchronized with MPV
|
||||||
player.update_properties();
|
player.update_all_properties();
|
||||||
|
|
||||||
// Only proceed if we can successfully query player state
|
// Only proceed if we can successfully query player state
|
||||||
let Some(player_state) = player.get_player_state() else {
|
let Some(player_state) = player.get_player_state() else {
|
||||||
@@ -556,8 +573,10 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
// Check if track ended and play next
|
// Check if track ended and play next
|
||||||
// When MPV finishes playing a file, it goes to idle (Stopped state)
|
// When MPV finishes playing a file, it goes to idle (Stopped state)
|
||||||
// Detect Playing → Stopped transition = track ended, play next
|
// Detect Playing → Stopped transition = track ended, play next
|
||||||
|
// But skip this check if we just manually stopped (skip_position_update flag)
|
||||||
if previous_player_state == Some(PlayerState::Playing)
|
if previous_player_state == Some(PlayerState::Playing)
|
||||||
&& player_state == PlayerState::Stopped
|
&& player_state == PlayerState::Stopped
|
||||||
|
&& !skip_position_update
|
||||||
{
|
{
|
||||||
let should_continue = state.play_next();
|
let should_continue = state.play_next();
|
||||||
// play_next() returns true if should continue playing, false if should stop
|
// play_next() returns true if should continue playing, false if should stop
|
||||||
@@ -572,9 +591,6 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
player.play(path)?;
|
player.play(path)?;
|
||||||
player.resume()?;
|
player.resume()?;
|
||||||
}
|
}
|
||||||
// Update metadata immediately when track changes
|
|
||||||
player.update_metadata();
|
|
||||||
metadata_update_counter = 0;
|
|
||||||
// Auto-scroll playlist to show current track (only if user is not browsing playlist)
|
// Auto-scroll playlist to show current track (only if user is not browsing playlist)
|
||||||
if !state.focus_playlist {
|
if !state.focus_playlist {
|
||||||
let playlist_visible_height = playlist_area.height.saturating_sub(2) as usize;
|
let playlist_visible_height = playlist_area.height.saturating_sub(2) as usize;
|
||||||
@@ -587,16 +603,8 @@ fn run_app<B: ratatui::backend::Backend>(
|
|||||||
state_changed = true;
|
state_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only update metadata and track playback when not stopped
|
// Only update playback position when not stopped
|
||||||
if player_state != PlayerState::Stopped {
|
if player_state != PlayerState::Stopped {
|
||||||
// Update metadata periodically to reduce IPC calls
|
|
||||||
metadata_update_counter += 1;
|
|
||||||
if metadata_update_counter >= METADATA_UPDATE_INTERVAL {
|
|
||||||
player.update_metadata();
|
|
||||||
metadata_update_counter = 0;
|
|
||||||
state_changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update position and duration from player
|
// Update position and duration from player
|
||||||
// Skip this iteration if we just started a new track to avoid stale MPV values
|
// Skip this iteration if we just started a new track to avoid stale MPV values
|
||||||
if skip_position_update {
|
if skip_position_update {
|
||||||
@@ -673,15 +681,50 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
KeyCode::Char('y') | KeyCode::Char('Y') => {
|
KeyCode::Char('y') | KeyCode::Char('Y') => {
|
||||||
state.show_refresh_confirm = false;
|
state.show_refresh_confirm = false;
|
||||||
state.is_refreshing = true;
|
state.is_refreshing = true;
|
||||||
terminal.draw(|f| { let _ = ui::render(f, state, player); })?; // Show "Refreshing library..." immediately
|
state.refresh_file_count = 0;
|
||||||
tracing::info!("Rescanning...");
|
terminal.draw(|f| { let _ = ui::render(f, state, player); })?;
|
||||||
|
|
||||||
let cache_dir = cache::get_cache_dir()?;
|
let cache_dir = cache::get_cache_dir()?;
|
||||||
let new_cache = scanner::scan_paths(&state.config.scan_paths.paths)?;
|
|
||||||
|
// Delete old cache files to ensure fresh scan
|
||||||
|
let _ = std::fs::remove_file(cache_dir.join("file_tree.json"));
|
||||||
|
let _ = std::fs::remove_file(cache_dir.join("metadata.json"));
|
||||||
|
|
||||||
|
// Create atomic counter for file count
|
||||||
|
let counter = Arc::new(AtomicUsize::new(0));
|
||||||
|
let counter_clone = Arc::clone(&counter);
|
||||||
|
|
||||||
|
// Spawn background thread to perform scan
|
||||||
|
let paths = state.config.scan_paths.paths.clone();
|
||||||
|
let scan_thread = thread::spawn(move || {
|
||||||
|
scanner::scan_paths(&paths, &counter_clone)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Poll counter and update UI while scanning
|
||||||
|
while !scan_thread.is_finished() {
|
||||||
|
state.refresh_file_count = counter.load(Ordering::Relaxed);
|
||||||
|
terminal.draw(|f| { let _ = ui::render(f, state, player); })?;
|
||||||
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the result
|
||||||
|
let new_cache = scan_thread.join().map_err(|_| anyhow::anyhow!("Scan thread panicked"))??;
|
||||||
|
|
||||||
new_cache.save(&cache_dir)?;
|
new_cache.save(&cache_dir)?;
|
||||||
|
|
||||||
|
// Replace old cache completely
|
||||||
state.cache = new_cache;
|
state.cache = new_cache;
|
||||||
state.refresh_flattened_items();
|
state.refresh_flattened_items(); // This also cleans up playlist and expanded_dirs
|
||||||
|
|
||||||
|
// If current file was removed, stop playback
|
||||||
|
if state.current_file.is_none() {
|
||||||
|
player.stop()?;
|
||||||
|
state.current_position = 0.0;
|
||||||
|
state.current_duration = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
state.is_refreshing = false;
|
state.is_refreshing = false;
|
||||||
tracing::info!("Rescan complete");
|
state.refresh_file_count = 0;
|
||||||
}
|
}
|
||||||
KeyCode::Char('n') | KeyCode::Char('N') | KeyCode::Esc => {
|
KeyCode::Char('n') | KeyCode::Char('N') | KeyCode::Esc => {
|
||||||
state.show_refresh_confirm = false;
|
state.show_refresh_confirm = false;
|
||||||
@@ -694,6 +737,20 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
// Handle search mode separately
|
// Handle search mode separately
|
||||||
if state.search_mode {
|
if state.search_mode {
|
||||||
match key.code {
|
match key.code {
|
||||||
|
KeyCode::Char('n') => {
|
||||||
|
if state.focus_playlist {
|
||||||
|
state.next_playlist_search_result();
|
||||||
|
} else {
|
||||||
|
state.next_search_result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
KeyCode::Char('N') => {
|
||||||
|
if state.focus_playlist {
|
||||||
|
state.prev_playlist_search_result();
|
||||||
|
} else {
|
||||||
|
state.prev_search_result();
|
||||||
|
}
|
||||||
|
}
|
||||||
KeyCode::Char(c) => {
|
KeyCode::Char(c) => {
|
||||||
if state.focus_playlist {
|
if state.focus_playlist {
|
||||||
state.append_playlist_search_char(c);
|
state.append_playlist_search_char(c);
|
||||||
@@ -708,20 +765,6 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
state.backspace_search();
|
state.backspace_search();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Tab => {
|
|
||||||
if state.focus_playlist {
|
|
||||||
state.playlist_tab_search_next();
|
|
||||||
} else {
|
|
||||||
state.tab_search_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::BackTab => {
|
|
||||||
if state.focus_playlist {
|
|
||||||
state.playlist_tab_search_prev();
|
|
||||||
} else {
|
|
||||||
state.tab_search_prev();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
if state.focus_playlist {
|
if state.focus_playlist {
|
||||||
state.execute_playlist_search();
|
state.execute_playlist_search();
|
||||||
@@ -784,32 +827,11 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(KeyCode::Esc, _) => {
|
(KeyCode::Esc, _) => {
|
||||||
if !state.search_matches.is_empty() {
|
|
||||||
state.search_matches.clear();
|
|
||||||
}
|
|
||||||
if !state.playlist_search_matches.is_empty() {
|
|
||||||
state.playlist_search_matches.clear();
|
|
||||||
state.playlist_tab_search_results.clear();
|
|
||||||
}
|
|
||||||
if state.visual_mode {
|
if state.visual_mode {
|
||||||
state.visual_mode = false;
|
state.visual_mode = false;
|
||||||
state.marked_files.clear();
|
state.marked_files.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(KeyCode::Char('n'), _) => {
|
|
||||||
if !state.search_matches.is_empty() {
|
|
||||||
state.next_search_match();
|
|
||||||
} else if !state.playlist_search_matches.is_empty() {
|
|
||||||
state.next_playlist_search_match();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(KeyCode::Char('N'), KeyModifiers::SHIFT) => {
|
|
||||||
if !state.search_matches.is_empty() {
|
|
||||||
state.prev_search_match();
|
|
||||||
} else if !state.playlist_search_matches.is_empty() {
|
|
||||||
state.prev_playlist_search_match();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(KeyCode::Char('J'), KeyModifiers::SHIFT) => {
|
(KeyCode::Char('J'), KeyModifiers::SHIFT) => {
|
||||||
// Next track
|
// Next track
|
||||||
action_navigate_track(state, player, 1, skip_position_update)?;
|
action_navigate_track(state, player, 1, skip_position_update)?;
|
||||||
@@ -892,7 +914,7 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
(KeyCode::Char('s'), _) => {
|
(KeyCode::Char('s'), _) => {
|
||||||
action_stop(state, player)?;
|
action_stop(state, player, skip_position_update)?;
|
||||||
}
|
}
|
||||||
(KeyCode::Char('m'), _) => {
|
(KeyCode::Char('m'), _) => {
|
||||||
state.cycle_play_mode();
|
state.cycle_play_mode();
|
||||||
@@ -906,28 +928,16 @@ fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, st
|
|||||||
action_toggle_play_pause(state, player)?;
|
action_toggle_play_pause(state, player)?;
|
||||||
}
|
}
|
||||||
(KeyCode::Char('H'), KeyModifiers::SHIFT) => {
|
(KeyCode::Char('H'), KeyModifiers::SHIFT) => {
|
||||||
if player.get_player_state() != Some(PlayerState::Stopped) {
|
action_seek(player, -10.0)?;
|
||||||
player.seek(-10.0)?;
|
|
||||||
tracing::info!("Seek backward 10s");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(KeyCode::Char('L'), KeyModifiers::SHIFT) => {
|
(KeyCode::Char('L'), KeyModifiers::SHIFT) => {
|
||||||
if player.get_player_state() != Some(PlayerState::Stopped) {
|
action_seek(player, 10.0)?;
|
||||||
player.seek(10.0)?;
|
|
||||||
tracing::info!("Seek forward 10s");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
(KeyCode::Char('+'), _) | (KeyCode::Char('='), _) => {
|
(KeyCode::Char('+'), _) | (KeyCode::Char('='), _) => {
|
||||||
let new_volume = (state.volume + 5).min(100);
|
action_volume_up(state, player)?;
|
||||||
state.volume = new_volume;
|
|
||||||
player.set_volume(new_volume)?;
|
|
||||||
tracing::info!("Volume: {}%", new_volume);
|
|
||||||
}
|
}
|
||||||
(KeyCode::Char('-'), _) => {
|
(KeyCode::Char('-'), _) => {
|
||||||
let new_volume = (state.volume - 5).max(0);
|
action_volume_down(state, player)?;
|
||||||
state.volume = new_volume;
|
|
||||||
player.set_volume(new_volume)?;
|
|
||||||
tracing::info!("Volume: {}%", new_volume);
|
|
||||||
}
|
}
|
||||||
(KeyCode::Char('r'), _) => {
|
(KeyCode::Char('r'), _) => {
|
||||||
state.show_refresh_confirm = true;
|
state.show_refresh_confirm = true;
|
||||||
@@ -1030,10 +1040,7 @@ fn handle_mouse_event(state: &mut AppState, mouse: MouseEvent, title_bar_area: r
|
|||||||
&& y < title_bar_area.y + title_bar_area.height
|
&& y < title_bar_area.y + title_bar_area.height
|
||||||
{
|
{
|
||||||
// Scroll on title bar = decrease volume
|
// Scroll on title bar = decrease volume
|
||||||
let new_volume = (state.volume - 5).max(0);
|
action_volume_down(state, player)?;
|
||||||
state.volume = new_volume;
|
|
||||||
player.set_volume(new_volume)?;
|
|
||||||
tracing::info!("Volume: {}%", new_volume);
|
|
||||||
} else if x >= playlist_area.x
|
} else if x >= playlist_area.x
|
||||||
&& x < playlist_area.x + playlist_area.width
|
&& x < playlist_area.x + playlist_area.width
|
||||||
&& y >= playlist_area.y
|
&& y >= playlist_area.y
|
||||||
@@ -1056,10 +1063,7 @@ fn handle_mouse_event(state: &mut AppState, mouse: MouseEvent, title_bar_area: r
|
|||||||
&& y < title_bar_area.y + title_bar_area.height
|
&& y < title_bar_area.y + title_bar_area.height
|
||||||
{
|
{
|
||||||
// Scroll on title bar = increase volume
|
// Scroll on title bar = increase volume
|
||||||
let new_volume = (state.volume + 5).min(100);
|
action_volume_up(state, player)?;
|
||||||
state.volume = new_volume;
|
|
||||||
player.set_volume(new_volume)?;
|
|
||||||
tracing::info!("Volume: {}%", new_volume);
|
|
||||||
} else if x >= playlist_area.x
|
} else if x >= playlist_area.x
|
||||||
&& x < playlist_area.x + playlist_area.width
|
&& x < playlist_area.x + playlist_area.width
|
||||||
&& y >= playlist_area.y
|
&& y >= playlist_area.y
|
||||||
@@ -1097,15 +1101,55 @@ fn handle_mouse_event(state: &mut AppState, mouse: MouseEvent, title_bar_area: r
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Check if click is on the panel title border (to switch focus)
|
||||||
|
// The visible area is whichever one is not Rect::default()
|
||||||
|
else if (file_panel_area.width > 0 && y == file_panel_area.y) ||
|
||||||
|
(playlist_area.width > 0 && y == playlist_area.y) {
|
||||||
|
// Click is on the top border line where "Files | Playlist" is shown
|
||||||
|
// Get the actual visible area (not the default one)
|
||||||
|
let area = if file_panel_area.width > 0 { file_panel_area } else { playlist_area };
|
||||||
|
|
||||||
|
// Build title text to calculate positions
|
||||||
|
let playlist_text = if !state.playlist.is_empty() {
|
||||||
|
format!("Playlist [{}/{}]", state.playlist_index + 1, state.playlist.len())
|
||||||
|
} else {
|
||||||
|
"Playlist (empty)".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Title is left-aligned by default in ratatui, starts after left border
|
||||||
|
// Border character takes 1 position, then title starts
|
||||||
|
let title_start_x = area.x + 1;
|
||||||
|
|
||||||
|
// Calculate where "Files" and "Playlist" text are
|
||||||
|
let files_start = title_start_x;
|
||||||
|
let files_end = files_start + 5; // "Files" is 5 chars
|
||||||
|
let separator_start = files_end;
|
||||||
|
let separator_end = separator_start + 3; // " | " is 3 chars
|
||||||
|
let playlist_start = separator_end;
|
||||||
|
let playlist_end = playlist_start + playlist_text.len() as u16;
|
||||||
|
|
||||||
|
match button {
|
||||||
|
MouseButton::Left => {
|
||||||
|
if x >= files_start && x < files_end {
|
||||||
|
// Clicked on "Files" - switch to file panel
|
||||||
|
state.focus_playlist = false;
|
||||||
|
} else if x >= playlist_start && x < playlist_end {
|
||||||
|
// Clicked on "Playlist" - switch to playlist
|
||||||
|
state.focus_playlist = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Check if click is within file panel area
|
// Check if click is within file panel area
|
||||||
else if x >= file_panel_area.x
|
else if x >= file_panel_area.x
|
||||||
&& x < file_panel_area.x + file_panel_area.width
|
&& x < file_panel_area.x + file_panel_area.width
|
||||||
&& y >= file_panel_area.y
|
&& y >= file_panel_area.y
|
||||||
&& y < file_panel_area.y + file_panel_area.height
|
&& y < file_panel_area.y + file_panel_area.height
|
||||||
{
|
{
|
||||||
// Calculate which item was clicked (accounting for borders and scroll offset)
|
// Calculate which item was clicked (accounting for scroll offset and outer border)
|
||||||
// Border takes 1 line at top, so subtract 1 from y position
|
// Outer border takes 1 line at top, content starts at file_panel_area.y + 1
|
||||||
let relative_y = (y - file_panel_area.y).saturating_sub(1);
|
let relative_y = y.saturating_sub(file_panel_area.y + 1);
|
||||||
let clicked_index = state.scroll_offset + relative_y as usize;
|
let clicked_index = state.scroll_offset + relative_y as usize;
|
||||||
|
|
||||||
// Set selection to clicked item if valid
|
// Set selection to clicked item if valid
|
||||||
@@ -1164,8 +1208,9 @@ fn handle_mouse_event(state: &mut AppState, mouse: MouseEvent, title_bar_area: r
|
|||||||
&& y >= playlist_area.y
|
&& y >= playlist_area.y
|
||||||
&& y < playlist_area.y + playlist_area.height
|
&& y < playlist_area.y + playlist_area.height
|
||||||
{
|
{
|
||||||
// Calculate which track was clicked (accounting for borders)
|
// Calculate which track was clicked (accounting for outer border)
|
||||||
let relative_y = (y - playlist_area.y).saturating_sub(1);
|
// Outer border takes 1 line at top, content starts at playlist_area.y + 1
|
||||||
|
let relative_y = y.saturating_sub(playlist_area.y + 1);
|
||||||
let clicked_track = relative_y as usize;
|
let clicked_track = relative_y as usize;
|
||||||
|
|
||||||
// Add scroll offset to get actual index
|
// Add scroll offset to get actual index
|
||||||
|
|||||||
@@ -76,8 +76,10 @@ impl Player {
|
|||||||
let stream = match UnixStream::connect(&self.socket_path) {
|
let stream = match UnixStream::connect(&self.socket_path) {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Connection failed - MPV probably not ready yet
|
// Connection failed - MPV probably not ready yet or has been killed
|
||||||
return Err(anyhow::anyhow!("Failed to connect: {}", e));
|
// Don't propagate error - just leave socket as None
|
||||||
|
tracing::debug!("Failed to connect to MPV socket: {}", e);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,84 +121,75 @@ impl Player {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_property(&mut self, property: &str) -> Option<Value> {
|
fn get_properties_batch(&mut self, properties: &[&str]) -> std::collections::HashMap<String, Value> {
|
||||||
// Try to connect - if respawning or connection fails, return None
|
let mut results = std::collections::HashMap::new();
|
||||||
if let Err(e) = self.connect() {
|
|
||||||
tracing::debug!("Failed to connect for property '{}': {}", property, e);
|
// Try to connect
|
||||||
return None;
|
if self.connect().is_err() {
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmd = json!({
|
|
||||||
"command": ["get_property", property],
|
|
||||||
"request_id": 1
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(ref mut socket) = self.socket {
|
if let Some(ref mut socket) = self.socket {
|
||||||
let msg = format!("{}\n", cmd);
|
// Send all property requests at once with unique request_ids
|
||||||
|
for (idx, property) in properties.iter().enumerate() {
|
||||||
// Write command
|
let cmd = json!({
|
||||||
if let Err(e) = socket.write_all(msg.as_bytes()) {
|
"command": ["get_property", property],
|
||||||
tracing::warn!("Failed to write get_property command for '{}': {}", property, e);
|
"request_id": idx + 1
|
||||||
self.socket = None;
|
});
|
||||||
return None;
|
let msg = format!("{}\n", cmd);
|
||||||
|
if socket.write_all(msg.as_bytes()).is_err() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to read response with timeout
|
// Read all responses
|
||||||
|
// IMPORTANT: Socket is non-blocking, need to set blocking mode for read
|
||||||
socket.set_nonblocking(false).ok();
|
socket.set_nonblocking(false).ok();
|
||||||
socket.set_read_timeout(Some(Duration::from_millis(100))).ok();
|
|
||||||
|
|
||||||
let cloned_socket = match socket.try_clone() {
|
let cloned_socket = match socket.try_clone() {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
tracing::warn!("Failed to clone socket for '{}': {}", property, e);
|
|
||||||
socket.set_nonblocking(true).ok();
|
socket.set_nonblocking(true).ok();
|
||||||
return None;
|
return results;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set timeout on cloned socket too (clone doesn't copy settings)
|
|
||||||
cloned_socket.set_nonblocking(false).ok();
|
cloned_socket.set_nonblocking(false).ok();
|
||||||
cloned_socket.set_read_timeout(Some(Duration::from_millis(100))).ok();
|
|
||||||
|
|
||||||
let mut reader = BufReader::new(cloned_socket);
|
let mut reader = BufReader::new(cloned_socket);
|
||||||
let mut response = String::new();
|
|
||||||
if let Err(e) = reader.read_line(&mut response) {
|
// Read responses - stop if we timeout or hit an error
|
||||||
tracing::debug!("Failed to read response for '{}': {}", property, e);
|
for _ in 0..properties.len() {
|
||||||
socket.set_nonblocking(true).ok();
|
let mut response = String::new();
|
||||||
return None;
|
if reader.read_line(&mut response).is_err() {
|
||||||
|
// Timeout or error - stop reading
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse response
|
||||||
|
if let Ok(parsed) = serde_json::from_str::<Value>(&response) {
|
||||||
|
// Check for success
|
||||||
|
if let Some(error) = parsed.get("error").and_then(|e| e.as_str()) {
|
||||||
|
if error == "success" {
|
||||||
|
// Get request_id to match with property
|
||||||
|
if let Some(req_id) = parsed.get("request_id").and_then(|id| id.as_i64()) {
|
||||||
|
let idx = (req_id - 1) as usize;
|
||||||
|
if idx < properties.len() {
|
||||||
|
if let Some(data) = parsed.get("data") {
|
||||||
|
results.insert(properties[idx].to_string(), data.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Restore non-blocking mode
|
||||||
socket.set_nonblocking(true).ok();
|
socket.set_nonblocking(true).ok();
|
||||||
|
|
||||||
// Parse and validate response
|
|
||||||
let parsed: Value = match serde_json::from_str(&response) {
|
|
||||||
Ok(v) => v,
|
|
||||||
Err(e) => {
|
|
||||||
tracing::warn!("Failed to parse JSON response for '{}': {} (response: {})", property, e, response.trim());
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Check for errors in response
|
|
||||||
// MPV returns {"error": "success"} when there's NO error
|
|
||||||
if let Some(error) = parsed.get("error").and_then(|e| e.as_str()) {
|
|
||||||
if error != "success" {
|
|
||||||
tracing::debug!("MPV returned error for '{}': {}", property, error);
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate request_id matches (should be 1)
|
|
||||||
if let Some(req_id) = parsed.get("request_id").and_then(|id| id.as_i64()) {
|
|
||||||
if req_id != 1 {
|
|
||||||
tracing::warn!("Request ID mismatch for '{}': expected 1, got {}", property, req_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsed.get("data").cloned();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
results
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play(&mut self, path: &Path) -> Result<()> {
|
pub fn play(&mut self, path: &Path) -> Result<()> {
|
||||||
@@ -242,84 +235,73 @@ impl Player {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_properties(&mut self) {
|
pub fn update_all_properties(&mut self) {
|
||||||
// Update position
|
// Fetch ALL properties in one batch
|
||||||
if let Some(val) = self.get_property("time-pos") {
|
let results = self.get_properties_batch(&[
|
||||||
|
"time-pos",
|
||||||
|
"duration",
|
||||||
|
"metadata/by-key/artist",
|
||||||
|
"metadata/by-key/ARTIST",
|
||||||
|
"metadata/by-key/album",
|
||||||
|
"metadata/by-key/ALBUM",
|
||||||
|
"metadata/by-key/title",
|
||||||
|
"metadata/by-key/TITLE",
|
||||||
|
"media-title",
|
||||||
|
"audio-codec-name",
|
||||||
|
"audio-bitrate",
|
||||||
|
"audio-params/samplerate",
|
||||||
|
"demuxer-cache-duration",
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Position
|
||||||
|
if let Some(val) = results.get("time-pos") {
|
||||||
if let Some(pos) = val.as_f64() {
|
if let Some(pos) = val.as_f64() {
|
||||||
self.position = pos;
|
self.position = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update duration
|
// Duration
|
||||||
if let Some(val) = self.get_property("duration") {
|
if let Some(val) = results.get("duration") {
|
||||||
if let Some(dur) = val.as_f64() {
|
if let Some(dur) = val.as_f64() {
|
||||||
self.duration = dur;
|
self.duration = dur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_metadata(&mut self) {
|
// Artist - try lowercase first, then uppercase
|
||||||
// Try to get artist directly
|
self.artist = results.get("metadata/by-key/artist")
|
||||||
if let Some(val) = self.get_property("metadata/by-key/artist") {
|
.and_then(|v| v.as_str().map(|s| s.to_string()))
|
||||||
self.artist = val.as_str().map(|s| s.to_string());
|
.or_else(|| results.get("metadata/by-key/ARTIST")
|
||||||
}
|
.and_then(|v| v.as_str().map(|s| s.to_string())));
|
||||||
// Fallback to ARTIST (uppercase)
|
|
||||||
if self.artist.is_none() {
|
|
||||||
if let Some(val) = self.get_property("metadata/by-key/ARTIST") {
|
|
||||||
self.artist = val.as_str().map(|s| s.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get album directly
|
// Album - try lowercase first, then uppercase
|
||||||
if let Some(val) = self.get_property("metadata/by-key/album") {
|
self.album = results.get("metadata/by-key/album")
|
||||||
self.album = val.as_str().map(|s| s.to_string());
|
.and_then(|v| v.as_str().map(|s| s.to_string()))
|
||||||
}
|
.or_else(|| results.get("metadata/by-key/ALBUM")
|
||||||
// Fallback to ALBUM (uppercase)
|
.and_then(|v| v.as_str().map(|s| s.to_string())));
|
||||||
if self.album.is_none() {
|
|
||||||
if let Some(val) = self.get_property("metadata/by-key/ALBUM") {
|
|
||||||
self.album = val.as_str().map(|s| s.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to get title directly
|
// Title - try lowercase, then uppercase, then media-title
|
||||||
if let Some(val) = self.get_property("metadata/by-key/title") {
|
self.media_title = results.get("metadata/by-key/title")
|
||||||
self.media_title = val.as_str().map(|s| s.to_string());
|
.and_then(|v| v.as_str().map(|s| s.to_string()))
|
||||||
}
|
.or_else(|| results.get("metadata/by-key/TITLE")
|
||||||
// Fallback to TITLE (uppercase)
|
.and_then(|v| v.as_str().map(|s| s.to_string())))
|
||||||
if self.media_title.is_none() {
|
.or_else(|| results.get("media-title")
|
||||||
if let Some(val) = self.get_property("metadata/by-key/TITLE") {
|
.and_then(|v| v.as_str().map(|s| s.to_string())));
|
||||||
self.media_title = val.as_str().map(|s| s.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final fallback to media-title if metadata doesn't have title
|
// Audio codec
|
||||||
if self.media_title.is_none() {
|
self.audio_codec = results.get("audio-codec-name")
|
||||||
if let Some(val) = self.get_property("media-title") {
|
.and_then(|v| v.as_str().map(|s| s.to_string()));
|
||||||
self.media_title = val.as_str().map(|s| s.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update audio codec
|
// Audio bitrate (convert from bps to kbps)
|
||||||
if let Some(val) = self.get_property("audio-codec-name") {
|
self.audio_bitrate = results.get("audio-bitrate")
|
||||||
self.audio_codec = val.as_str().map(|s| s.to_string());
|
.and_then(|v| v.as_f64().map(|b| b / 1000.0));
|
||||||
}
|
|
||||||
|
|
||||||
// Update audio bitrate (convert from bps to kbps)
|
// Sample rate
|
||||||
if let Some(val) = self.get_property("audio-bitrate") {
|
self.sample_rate = results.get("audio-params/samplerate")
|
||||||
self.audio_bitrate = val.as_f64().map(|b| b / 1000.0);
|
.and_then(|v| v.as_i64());
|
||||||
}
|
|
||||||
|
|
||||||
// Update sample rate
|
// Cache duration
|
||||||
if let Some(val) = self.get_property("audio-params/samplerate") {
|
self.cache_duration = results.get("demuxer-cache-duration")
|
||||||
self.sample_rate = val.as_i64();
|
.and_then(|v| v.as_f64());
|
||||||
}
|
|
||||||
|
|
||||||
// Update cache duration (how many seconds are buffered ahead)
|
|
||||||
if let Some(val) = self.get_property("demuxer-cache-duration") {
|
|
||||||
self.cache_duration = val.as_f64();
|
|
||||||
} else {
|
|
||||||
self.cache_duration = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_position(&self) -> Option<f64> {
|
pub fn get_position(&self) -> Option<f64> {
|
||||||
@@ -330,20 +312,14 @@ impl Player {
|
|||||||
Some(self.duration)
|
Some(self.duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_idle(&mut self) -> Option<bool> {
|
|
||||||
self.get_property("idle-active")
|
|
||||||
.and_then(|v| v.as_bool())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_paused(&mut self) -> Option<bool> {
|
|
||||||
self.get_property("pause")
|
|
||||||
.and_then(|v| v.as_bool())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_player_state(&mut self) -> Option<crate::state::PlayerState> {
|
pub fn get_player_state(&mut self) -> Option<crate::state::PlayerState> {
|
||||||
use crate::state::PlayerState;
|
use crate::state::PlayerState;
|
||||||
let is_idle = self.is_idle()?;
|
|
||||||
let is_paused = self.is_paused()?;
|
// Batch fetch both properties at once
|
||||||
|
let results = self.get_properties_batch(&["idle-active", "pause"]);
|
||||||
|
|
||||||
|
let is_idle = results.get("idle-active").and_then(|v| v.as_bool())?;
|
||||||
|
let is_paused = results.get("pause").and_then(|v| v.as_bool())?;
|
||||||
|
|
||||||
Some(if is_idle {
|
Some(if is_idle {
|
||||||
PlayerState::Stopped
|
PlayerState::Stopped
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::cache::{Cache, FileMetadata, FileTreeNode};
|
use crate::cache::{Cache, FileMetadata, FileTreeNode};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
const AUDIO_EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg", "m4a", "aac", "opus", "wma"];
|
const AUDIO_EXTENSIONS: &[&str] = &["mp3", "flac", "wav", "ogg", "m4a", "aac", "opus", "wma"];
|
||||||
@@ -33,7 +34,7 @@ pub fn is_video_file(path: &Path) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scan_directory(root_path: &Path) -> Result<FileTreeNode> {
|
fn scan_directory_internal(root_path: &Path, counter: &AtomicUsize) -> Result<FileTreeNode> {
|
||||||
let name = root_path
|
let name = root_path
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -62,10 +63,16 @@ pub fn scan_directory(root_path: &Path) -> Result<FileTreeNode> {
|
|||||||
|
|
||||||
if entry.file_type().is_dir() {
|
if entry.file_type().is_dir() {
|
||||||
// Recursively scan subdirectories
|
// Recursively scan subdirectories
|
||||||
if let Ok(child_node) = scan_directory(path) {
|
if let Ok(child_node) = scan_directory_internal(path, counter) {
|
||||||
node.children.push(child_node);
|
// Only add directory if it contains media files or non-empty subdirectories
|
||||||
|
if !child_node.children.is_empty() {
|
||||||
|
node.children.push(child_node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if is_media_file(path) {
|
} else if is_media_file(path) {
|
||||||
|
// Increment counter for each media file found
|
||||||
|
counter.fetch_add(1, Ordering::Relaxed);
|
||||||
|
|
||||||
// Add media file
|
// Add media file
|
||||||
let file_name = path
|
let file_name = path
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -97,13 +104,13 @@ pub fn scan_directory(root_path: &Path) -> Result<FileTreeNode> {
|
|||||||
Ok(node)
|
Ok(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn scan_paths(paths: &[PathBuf]) -> Result<Cache> {
|
pub fn scan_paths(paths: &[PathBuf], counter: &AtomicUsize) -> Result<Cache> {
|
||||||
let mut cache = Cache::new();
|
let mut cache = Cache::new();
|
||||||
|
|
||||||
for path in paths {
|
for path in paths {
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
tracing::info!("Scanning path: {:?}", path);
|
tracing::info!("Scanning path: {:?}", path);
|
||||||
let tree_node = scan_directory(path)?;
|
let tree_node = scan_directory_internal(path, counter)?;
|
||||||
|
|
||||||
// Collect all metadata from the tree
|
// Collect all metadata from the tree
|
||||||
collect_metadata(&tree_node, &mut cache);
|
collect_metadata(&tree_node, &mut cache);
|
||||||
|
|||||||
611
src/state/mod.rs
611
src/state/mod.rs
@@ -74,14 +74,10 @@ pub struct AppState {
|
|||||||
pub is_refreshing: bool,
|
pub is_refreshing: bool,
|
||||||
pub search_mode: bool,
|
pub search_mode: bool,
|
||||||
pub search_query: String,
|
pub search_query: String,
|
||||||
pub search_matches: Vec<PathBuf>,
|
pub search_results: Vec<PathBuf>,
|
||||||
pub search_match_index: usize,
|
pub search_result_index: usize,
|
||||||
pub tab_search_results: Vec<PathBuf>,
|
pub playlist_search_results: Vec<usize>,
|
||||||
pub tab_search_index: usize,
|
pub playlist_search_result_index: usize,
|
||||||
pub playlist_search_matches: Vec<usize>,
|
|
||||||
pub playlist_search_match_index: usize,
|
|
||||||
pub playlist_tab_search_results: Vec<usize>,
|
|
||||||
pub playlist_tab_search_index: usize,
|
|
||||||
pub visual_mode: bool,
|
pub visual_mode: bool,
|
||||||
pub visual_anchor: usize,
|
pub visual_anchor: usize,
|
||||||
pub saved_expanded_dirs: HashSet<PathBuf>,
|
pub saved_expanded_dirs: HashSet<PathBuf>,
|
||||||
@@ -92,6 +88,8 @@ pub struct AppState {
|
|||||||
pub last_click_is_playlist: bool,
|
pub last_click_is_playlist: bool,
|
||||||
pub context_menu: Option<ContextMenu>,
|
pub context_menu: Option<ContextMenu>,
|
||||||
pub play_mode: PlayMode,
|
pub play_mode: PlayMode,
|
||||||
|
pub last_error: Option<String>,
|
||||||
|
pub refresh_file_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -131,14 +129,10 @@ impl AppState {
|
|||||||
is_refreshing: false,
|
is_refreshing: false,
|
||||||
search_mode: false,
|
search_mode: false,
|
||||||
search_query: String::new(),
|
search_query: String::new(),
|
||||||
search_matches: Vec::new(),
|
search_results: Vec::new(),
|
||||||
search_match_index: 0,
|
search_result_index: 0,
|
||||||
tab_search_results: Vec::new(),
|
playlist_search_results: Vec::new(),
|
||||||
tab_search_index: 0,
|
playlist_search_result_index: 0,
|
||||||
playlist_search_matches: Vec::new(),
|
|
||||||
playlist_search_match_index: 0,
|
|
||||||
playlist_tab_search_results: Vec::new(),
|
|
||||||
playlist_tab_search_index: 0,
|
|
||||||
visual_mode: false,
|
visual_mode: false,
|
||||||
visual_anchor: 0,
|
visual_anchor: 0,
|
||||||
saved_expanded_dirs: HashSet::new(),
|
saved_expanded_dirs: HashSet::new(),
|
||||||
@@ -149,6 +143,8 @@ impl AppState {
|
|||||||
last_click_is_playlist: false,
|
last_click_is_playlist: false,
|
||||||
context_menu: None,
|
context_menu: None,
|
||||||
play_mode: PlayMode::Normal,
|
play_mode: PlayMode::Normal,
|
||||||
|
last_error: None,
|
||||||
|
refresh_file_count: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,8 +583,84 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn refresh_flattened_items(&mut self) {
|
pub fn refresh_flattened_items(&mut self) {
|
||||||
// Keep current expanded state after rescan
|
// Clean up expanded_dirs - remove paths that no longer exist in new cache
|
||||||
|
self.cleanup_expanded_dirs();
|
||||||
|
|
||||||
|
// Rebuild view with cleaned expanded state
|
||||||
self.rebuild_flattened_items();
|
self.rebuild_flattened_items();
|
||||||
|
|
||||||
|
// Clean up playlist - remove files that no longer exist in cache
|
||||||
|
self.cleanup_playlist();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_expanded_dirs(&mut self) {
|
||||||
|
// Build a set of valid directory paths from the cache
|
||||||
|
let mut valid_dirs = std::collections::HashSet::new();
|
||||||
|
fn collect_dirs(node: &crate::cache::FileTreeNode, dirs: &mut std::collections::HashSet<std::path::PathBuf>) {
|
||||||
|
if node.is_dir {
|
||||||
|
dirs.insert(node.path.clone());
|
||||||
|
}
|
||||||
|
for child in &node.children {
|
||||||
|
collect_dirs(child, dirs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for root in &self.cache.file_tree {
|
||||||
|
collect_dirs(root, &mut valid_dirs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove invalid paths from expanded_dirs
|
||||||
|
let original_len = self.expanded_dirs.len();
|
||||||
|
self.expanded_dirs.retain(|path| valid_dirs.contains(path));
|
||||||
|
|
||||||
|
if self.expanded_dirs.len() < original_len {
|
||||||
|
tracing::info!("Cleaned up expanded_dirs: removed {} invalid paths", original_len - self.expanded_dirs.len());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_playlist(&mut self) {
|
||||||
|
// Build a set of valid paths from the cache for fast lookup
|
||||||
|
let mut valid_paths = std::collections::HashSet::new();
|
||||||
|
fn collect_paths(node: &crate::cache::FileTreeNode, paths: &mut std::collections::HashSet<std::path::PathBuf>) {
|
||||||
|
if !node.is_dir {
|
||||||
|
paths.insert(node.path.clone());
|
||||||
|
}
|
||||||
|
for child in &node.children {
|
||||||
|
collect_paths(child, paths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for root in &self.cache.file_tree {
|
||||||
|
collect_paths(root, &mut valid_paths);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if current file is invalid
|
||||||
|
let current_file_invalid = if let Some(ref current) = self.current_file {
|
||||||
|
!valid_paths.contains(current)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
};
|
||||||
|
|
||||||
|
if current_file_invalid {
|
||||||
|
self.current_file = None;
|
||||||
|
tracing::info!("Current playing file was deleted, cleared current_file");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove files from playlist that don't exist in cache
|
||||||
|
let original_len = self.playlist.len();
|
||||||
|
self.playlist.retain(|path| valid_paths.contains(path));
|
||||||
|
|
||||||
|
// Adjust indices if playlist was modified
|
||||||
|
if self.playlist.len() < original_len {
|
||||||
|
// Ensure playlist_index is valid
|
||||||
|
if self.playlist_index >= self.playlist.len() && !self.playlist.is_empty() {
|
||||||
|
self.playlist_index = self.playlist.len() - 1;
|
||||||
|
}
|
||||||
|
// Ensure selected_playlist_index is valid
|
||||||
|
if self.selected_playlist_index >= self.playlist.len() && !self.playlist.is_empty() {
|
||||||
|
self.selected_playlist_index = self.playlist.len() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tracing::info!("Cleaned up playlist: removed {} deleted files", original_len - self.playlist.len());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rebuild_flattened_items(&mut self) {
|
pub fn rebuild_flattened_items(&mut self) {
|
||||||
@@ -604,16 +676,12 @@ impl AppState {
|
|||||||
|
|
||||||
if self.focus_playlist {
|
if self.focus_playlist {
|
||||||
// Clear playlist search state
|
// Clear playlist search state
|
||||||
self.playlist_search_matches.clear();
|
self.playlist_search_results.clear();
|
||||||
self.playlist_search_match_index = 0;
|
self.playlist_search_result_index = 0;
|
||||||
self.playlist_tab_search_results.clear();
|
|
||||||
self.playlist_tab_search_index = 0;
|
|
||||||
} else {
|
} else {
|
||||||
// Clear file search state
|
// Clear file search state
|
||||||
self.search_matches.clear();
|
self.search_results.clear();
|
||||||
self.search_match_index = 0;
|
self.search_result_index = 0;
|
||||||
self.tab_search_results.clear();
|
|
||||||
self.tab_search_index = 0;
|
|
||||||
// Save current folder state
|
// Save current folder state
|
||||||
self.saved_expanded_dirs = self.expanded_dirs.clone();
|
self.saved_expanded_dirs = self.expanded_dirs.clone();
|
||||||
}
|
}
|
||||||
@@ -621,15 +689,16 @@ impl AppState {
|
|||||||
|
|
||||||
pub fn exit_search_mode(&mut self) {
|
pub fn exit_search_mode(&mut self) {
|
||||||
self.search_mode = false;
|
self.search_mode = false;
|
||||||
|
self.search_query.clear();
|
||||||
|
|
||||||
if self.focus_playlist {
|
if self.focus_playlist {
|
||||||
// Clear playlist search state
|
// Clear playlist search state
|
||||||
self.playlist_tab_search_results.clear();
|
self.playlist_search_results.clear();
|
||||||
self.playlist_tab_search_index = 0;
|
self.playlist_search_result_index = 0;
|
||||||
} else {
|
} else {
|
||||||
// Clear file search state
|
// Clear file search state
|
||||||
self.tab_search_results.clear();
|
self.search_results.clear();
|
||||||
self.tab_search_index = 0;
|
self.search_result_index = 0;
|
||||||
// Restore folder state from before search
|
// Restore folder state from before search
|
||||||
self.expanded_dirs = self.saved_expanded_dirs.clone();
|
self.expanded_dirs = self.saved_expanded_dirs.clone();
|
||||||
self.rebuild_flattened_items();
|
self.rebuild_flattened_items();
|
||||||
@@ -648,9 +717,8 @@ impl AppState {
|
|||||||
|
|
||||||
fn perform_incremental_search(&mut self) {
|
fn perform_incremental_search(&mut self) {
|
||||||
if self.search_query.is_empty() {
|
if self.search_query.is_empty() {
|
||||||
self.tab_search_results.clear();
|
self.search_results.clear();
|
||||||
self.tab_search_index = 0;
|
self.search_result_index = 0;
|
||||||
// Don't rebuild tree on every keystroke - only when exiting search
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -659,8 +727,8 @@ impl AppState {
|
|||||||
collect_matching_paths(&self.cache.file_tree, &self.search_query, &mut matching_paths_with_scores);
|
collect_matching_paths(&self.cache.file_tree, &self.search_query, &mut matching_paths_with_scores);
|
||||||
|
|
||||||
if matching_paths_with_scores.is_empty() {
|
if matching_paths_with_scores.is_empty() {
|
||||||
self.tab_search_results.clear();
|
self.search_results.clear();
|
||||||
self.tab_search_index = 0;
|
self.search_result_index = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -674,22 +742,30 @@ impl AppState {
|
|||||||
// Sort by score (highest first), then by original index to prefer first occurrence
|
// Sort by score (highest first), then by original index to prefer first occurrence
|
||||||
indexed_matches.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.2.cmp(&b.2)));
|
indexed_matches.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.2.cmp(&b.2)));
|
||||||
|
|
||||||
// Store all matches for tab completion
|
// Store all matches
|
||||||
self.tab_search_results = indexed_matches.iter().map(|(path, _, _)| path.clone()).collect();
|
self.search_results = indexed_matches.iter().map(|(path, _, _)| path.clone()).collect();
|
||||||
self.tab_search_index = 0;
|
self.search_result_index = 0;
|
||||||
|
|
||||||
// Only expand and rebuild if this is a new best match
|
// Jump to first match
|
||||||
let best_match = self.tab_search_results[0].clone();
|
self.jump_to_current_search_result();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn jump_to_current_search_result(&mut self) {
|
||||||
|
if self.search_results.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let current_match = self.search_results[self.search_result_index].clone();
|
||||||
|
|
||||||
// Check if we need to expand folders for this match
|
// Check if we need to expand folders for this match
|
||||||
let needs_expand = best_match.ancestors()
|
let needs_expand = current_match.ancestors()
|
||||||
.skip(1) // Skip the file itself
|
.skip(1) // Skip the file itself
|
||||||
.any(|p| !self.expanded_dirs.contains(p));
|
.any(|p| !self.expanded_dirs.contains(p));
|
||||||
|
|
||||||
if needs_expand {
|
if needs_expand {
|
||||||
// Close all folders and expand only for the best match
|
// Close all folders and expand only for the current match
|
||||||
self.expanded_dirs.clear();
|
self.expanded_dirs.clear();
|
||||||
let mut parent = best_match.parent();
|
let mut parent = current_match.parent();
|
||||||
while let Some(p) = parent {
|
while let Some(p) = parent {
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
self.expanded_dirs.insert(p.to_path_buf());
|
||||||
parent = p.parent();
|
parent = p.parent();
|
||||||
@@ -699,8 +775,8 @@ impl AppState {
|
|||||||
self.rebuild_flattened_items();
|
self.rebuild_flattened_items();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the best match in the flattened list and jump to it
|
// Find the match in the flattened list and jump to it
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == best_match) {
|
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == current_match) {
|
||||||
self.selected_index = idx;
|
self.selected_index = idx;
|
||||||
|
|
||||||
// Scroll to show the match
|
// Scroll to show the match
|
||||||
@@ -718,233 +794,26 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn next_search_result(&mut self) {
|
||||||
|
if !self.search_results.is_empty() {
|
||||||
|
self.search_result_index = (self.search_result_index + 1) % self.search_results.len();
|
||||||
|
self.jump_to_current_search_result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn prev_search_result(&mut self) {
|
||||||
|
if !self.search_results.is_empty() {
|
||||||
|
self.search_result_index = if self.search_result_index == 0 {
|
||||||
|
self.search_results.len() - 1
|
||||||
|
} else {
|
||||||
|
self.search_result_index - 1
|
||||||
|
};
|
||||||
|
self.jump_to_current_search_result();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn execute_search(&mut self) {
|
pub fn execute_search(&mut self) {
|
||||||
if self.search_query.is_empty() {
|
self.exit_search_mode();
|
||||||
self.search_mode = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect all matching paths with scores and preserve order
|
|
||||||
let mut matching_paths_with_scores = Vec::new();
|
|
||||||
collect_matching_paths(&self.cache.file_tree, &self.search_query, &mut matching_paths_with_scores);
|
|
||||||
|
|
||||||
if matching_paths_with_scores.is_empty() {
|
|
||||||
self.search_mode = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add index to preserve original tree order when scores are equal
|
|
||||||
let mut indexed_matches: Vec<(PathBuf, i32, usize)> = matching_paths_with_scores
|
|
||||||
.into_iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(idx, (path, score))| (path, score, idx))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// Sort by score (highest first), then by original index to prefer first occurrence
|
|
||||||
indexed_matches.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.2.cmp(&b.2)));
|
|
||||||
|
|
||||||
let matching_paths_with_scores: Vec<(PathBuf, i32)> = indexed_matches
|
|
||||||
.into_iter()
|
|
||||||
.map(|(path, score, _)| (path, score))
|
|
||||||
.collect();
|
|
||||||
let matching_paths: Vec<PathBuf> = matching_paths_with_scores.iter().map(|(path, _)| path.clone()).collect();
|
|
||||||
|
|
||||||
// Store matching paths (not indices, as they change when folders collapse)
|
|
||||||
self.search_matches = matching_paths;
|
|
||||||
|
|
||||||
if !self.search_matches.is_empty() {
|
|
||||||
self.search_match_index = 0;
|
|
||||||
// Close all folders and expand only for first match
|
|
||||||
self.expanded_dirs.clear();
|
|
||||||
let first_match = self.search_matches[0].clone();
|
|
||||||
let mut parent = first_match.parent();
|
|
||||||
while let Some(p) = parent {
|
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
|
||||||
parent = p.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild flattened items
|
|
||||||
self.rebuild_flattened_items();
|
|
||||||
|
|
||||||
// Find first match in flattened list
|
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == first_match) {
|
|
||||||
self.selected_index = idx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.search_mode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_search_match(&mut self) {
|
|
||||||
if !self.search_matches.is_empty() {
|
|
||||||
self.search_match_index = (self.search_match_index + 1) % self.search_matches.len();
|
|
||||||
let target_path = self.search_matches[self.search_match_index].clone();
|
|
||||||
|
|
||||||
// Close all folders and expand only for this match
|
|
||||||
self.expanded_dirs.clear();
|
|
||||||
let mut parent = target_path.parent();
|
|
||||||
while let Some(p) = parent {
|
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
|
||||||
parent = p.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild flattened items
|
|
||||||
self.rebuild_flattened_items();
|
|
||||||
|
|
||||||
// Find the path in current flattened items
|
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == target_path) {
|
|
||||||
self.selected_index = idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
// Account for "... X more below" indicator which takes one line
|
|
||||||
let visible_end = self.scroll_offset + self.file_panel_visible_height;
|
|
||||||
let items_below = if visible_end < self.flattened_items.len() {
|
|
||||||
self.flattened_items.len() - visible_end
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let effective_height = if items_below > 0 {
|
|
||||||
self.file_panel_visible_height.saturating_sub(1)
|
|
||||||
} else {
|
|
||||||
self.file_panel_visible_height
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.selected_index < self.scroll_offset {
|
|
||||||
self.scroll_offset = self.selected_index;
|
|
||||||
} else if self.selected_index >= self.scroll_offset + effective_height {
|
|
||||||
self.scroll_offset = self.selected_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prev_search_match(&mut self) {
|
|
||||||
if !self.search_matches.is_empty() {
|
|
||||||
if self.search_match_index == 0 {
|
|
||||||
self.search_match_index = self.search_matches.len() - 1;
|
|
||||||
} else {
|
|
||||||
self.search_match_index -= 1;
|
|
||||||
}
|
|
||||||
let target_path = self.search_matches[self.search_match_index].clone();
|
|
||||||
|
|
||||||
// Close all folders and expand only for this match
|
|
||||||
self.expanded_dirs.clear();
|
|
||||||
let mut parent = target_path.parent();
|
|
||||||
while let Some(p) = parent {
|
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
|
||||||
parent = p.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild flattened items
|
|
||||||
self.rebuild_flattened_items();
|
|
||||||
|
|
||||||
// Find the path in current flattened items
|
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == target_path) {
|
|
||||||
self.selected_index = idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
// Account for "... X more below" indicator which takes one line
|
|
||||||
let visible_end = self.scroll_offset + self.file_panel_visible_height;
|
|
||||||
let items_below = if visible_end < self.flattened_items.len() {
|
|
||||||
self.flattened_items.len() - visible_end
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let effective_height = if items_below > 0 {
|
|
||||||
self.file_panel_visible_height.saturating_sub(1)
|
|
||||||
} else {
|
|
||||||
self.file_panel_visible_height
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.selected_index < self.scroll_offset {
|
|
||||||
self.scroll_offset = self.selected_index;
|
|
||||||
} else if self.selected_index >= self.scroll_offset + effective_height {
|
|
||||||
self.scroll_offset = self.selected_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tab_search_next(&mut self) {
|
|
||||||
if self.tab_search_results.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cycle to next match
|
|
||||||
self.tab_search_index = (self.tab_search_index + 1) % self.tab_search_results.len();
|
|
||||||
let next_match = self.tab_search_results[self.tab_search_index].clone();
|
|
||||||
|
|
||||||
// Close all folders and expand only for this match
|
|
||||||
self.expanded_dirs.clear();
|
|
||||||
let mut parent = next_match.parent();
|
|
||||||
while let Some(p) = parent {
|
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
|
||||||
parent = p.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild flattened items
|
|
||||||
self.rebuild_flattened_items();
|
|
||||||
|
|
||||||
// Find and select the match
|
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == next_match) {
|
|
||||||
self.selected_index = idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
let effective_height = calculate_effective_height(
|
|
||||||
self.scroll_offset,
|
|
||||||
self.file_panel_visible_height,
|
|
||||||
self.flattened_items.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if self.selected_index < self.scroll_offset {
|
|
||||||
self.scroll_offset = self.selected_index;
|
|
||||||
} else if self.selected_index >= self.scroll_offset + effective_height {
|
|
||||||
self.scroll_offset = self.selected_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tab_search_prev(&mut self) {
|
|
||||||
if self.tab_search_results.is_empty() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cycle to previous match
|
|
||||||
if self.tab_search_index == 0 {
|
|
||||||
self.tab_search_index = self.tab_search_results.len() - 1;
|
|
||||||
} else {
|
|
||||||
self.tab_search_index -= 1;
|
|
||||||
}
|
|
||||||
let prev_match = self.tab_search_results[self.tab_search_index].clone();
|
|
||||||
|
|
||||||
// Close all folders and expand only for this match
|
|
||||||
self.expanded_dirs.clear();
|
|
||||||
let mut parent = prev_match.parent();
|
|
||||||
while let Some(p) = parent {
|
|
||||||
self.expanded_dirs.insert(p.to_path_buf());
|
|
||||||
parent = p.parent();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild flattened items
|
|
||||||
self.rebuild_flattened_items();
|
|
||||||
|
|
||||||
// Find and select the match
|
|
||||||
if let Some(idx) = self.flattened_items.iter().position(|item| item.path == prev_match) {
|
|
||||||
self.selected_index = idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
let effective_height = calculate_effective_height(
|
|
||||||
self.scroll_offset,
|
|
||||||
self.file_panel_visible_height,
|
|
||||||
self.flattened_items.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if self.selected_index < self.scroll_offset {
|
|
||||||
self.scroll_offset = self.selected_index;
|
|
||||||
} else if self.selected_index >= self.scroll_offset + effective_height {
|
|
||||||
self.scroll_offset = self.selected_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_playlist_search_char(&mut self, c: char) {
|
pub fn append_playlist_search_char(&mut self, c: char) {
|
||||||
@@ -959,8 +828,8 @@ impl AppState {
|
|||||||
|
|
||||||
fn perform_playlist_incremental_search(&mut self) {
|
fn perform_playlist_incremental_search(&mut self) {
|
||||||
if self.search_query.is_empty() {
|
if self.search_query.is_empty() {
|
||||||
self.playlist_tab_search_results.clear();
|
self.playlist_search_results.clear();
|
||||||
self.playlist_tab_search_index = 0;
|
self.playlist_search_result_index = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -977,21 +846,29 @@ impl AppState {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if matching_indices_with_scores.is_empty() {
|
if matching_indices_with_scores.is_empty() {
|
||||||
self.playlist_tab_search_results.clear();
|
self.playlist_search_results.clear();
|
||||||
self.playlist_tab_search_index = 0;
|
self.playlist_search_result_index = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by score (highest first)
|
// Sort by score (highest first)
|
||||||
matching_indices_with_scores.sort_by(|a, b| b.1.cmp(&a.1));
|
matching_indices_with_scores.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
|
||||||
// Store all matches for tab completion
|
// Store all matches
|
||||||
self.playlist_tab_search_results = matching_indices_with_scores.iter().map(|(idx, _)| *idx).collect();
|
self.playlist_search_results = matching_indices_with_scores.iter().map(|(idx, _)| *idx).collect();
|
||||||
self.playlist_tab_search_index = 0;
|
self.playlist_search_result_index = 0;
|
||||||
|
|
||||||
// Jump to best match
|
// Jump to first match
|
||||||
let best_match_idx = self.playlist_tab_search_results[0];
|
self.jump_to_current_playlist_search_result();
|
||||||
self.selected_playlist_index = best_match_idx;
|
}
|
||||||
|
|
||||||
|
fn jump_to_current_playlist_search_result(&mut self) {
|
||||||
|
if self.playlist_search_results.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let match_idx = self.playlist_search_results[self.playlist_search_result_index];
|
||||||
|
self.selected_playlist_index = match_idx;
|
||||||
|
|
||||||
// Scroll to show the match
|
// Scroll to show the match
|
||||||
let effective_height = calculate_effective_height(
|
let effective_height = calculate_effective_height(
|
||||||
@@ -1007,174 +884,26 @@ impl AppState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn playlist_tab_search_next(&mut self) {
|
pub fn next_playlist_search_result(&mut self) {
|
||||||
if self.playlist_tab_search_results.is_empty() {
|
if !self.playlist_search_results.is_empty() {
|
||||||
return;
|
self.playlist_search_result_index = (self.playlist_search_result_index + 1) % self.playlist_search_results.len();
|
||||||
}
|
self.jump_to_current_playlist_search_result();
|
||||||
|
|
||||||
// Cycle to next match
|
|
||||||
self.playlist_tab_search_index = (self.playlist_tab_search_index + 1) % self.playlist_tab_search_results.len();
|
|
||||||
let next_match_idx = self.playlist_tab_search_results[self.playlist_tab_search_index];
|
|
||||||
self.selected_playlist_index = next_match_idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
let effective_height = calculate_effective_height(
|
|
||||||
self.playlist_scroll_offset,
|
|
||||||
self.playlist_visible_height,
|
|
||||||
self.playlist.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if self.selected_playlist_index < self.playlist_scroll_offset {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index;
|
|
||||||
} else if self.selected_playlist_index >= self.playlist_scroll_offset + effective_height {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index - effective_height + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn playlist_tab_search_prev(&mut self) {
|
pub fn prev_playlist_search_result(&mut self) {
|
||||||
if self.playlist_tab_search_results.is_empty() {
|
if !self.playlist_search_results.is_empty() {
|
||||||
return;
|
self.playlist_search_result_index = if self.playlist_search_result_index == 0 {
|
||||||
}
|
self.playlist_search_results.len() - 1
|
||||||
|
} else {
|
||||||
// Cycle to previous match
|
self.playlist_search_result_index - 1
|
||||||
if self.playlist_tab_search_index == 0 {
|
};
|
||||||
self.playlist_tab_search_index = self.playlist_tab_search_results.len() - 1;
|
self.jump_to_current_playlist_search_result();
|
||||||
} else {
|
|
||||||
self.playlist_tab_search_index -= 1;
|
|
||||||
}
|
|
||||||
let prev_match_idx = self.playlist_tab_search_results[self.playlist_tab_search_index];
|
|
||||||
self.selected_playlist_index = prev_match_idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
let effective_height = calculate_effective_height(
|
|
||||||
self.playlist_scroll_offset,
|
|
||||||
self.playlist_visible_height,
|
|
||||||
self.playlist.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
if self.selected_playlist_index < self.playlist_scroll_offset {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index;
|
|
||||||
} else if self.selected_playlist_index >= self.playlist_scroll_offset + effective_height {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index - effective_height + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute_playlist_search(&mut self) {
|
pub fn execute_playlist_search(&mut self) {
|
||||||
if self.search_query.is_empty() {
|
self.exit_search_mode();
|
||||||
self.search_mode = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect all matching indices with scores
|
|
||||||
let mut matching_indices_with_scores: Vec<(usize, i32)> = self.playlist
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter_map(|(idx, path)| {
|
|
||||||
let filename = path.file_name()
|
|
||||||
.and_then(|n| n.to_str())
|
|
||||||
.unwrap_or("");
|
|
||||||
fuzzy_match(filename, &self.search_query).map(|score| (idx, score))
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
if matching_indices_with_scores.is_empty() {
|
|
||||||
self.search_mode = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort by score (highest first)
|
|
||||||
matching_indices_with_scores.sort_by(|a, b| b.1.cmp(&a.1));
|
|
||||||
|
|
||||||
// Store matching indices
|
|
||||||
self.playlist_search_matches = matching_indices_with_scores.iter().map(|(idx, _)| *idx).collect();
|
|
||||||
|
|
||||||
if !self.playlist_search_matches.is_empty() {
|
|
||||||
self.playlist_search_match_index = 0;
|
|
||||||
let first_match_idx = self.playlist_search_matches[0];
|
|
||||||
self.selected_playlist_index = first_match_idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
// Account for "... X more below" indicator which takes one line
|
|
||||||
let visible_end = self.playlist_scroll_offset + self.playlist_visible_height;
|
|
||||||
let items_below = if visible_end < self.playlist.len() {
|
|
||||||
self.playlist.len() - visible_end
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let effective_height = if items_below > 0 {
|
|
||||||
self.playlist_visible_height.saturating_sub(1)
|
|
||||||
} else {
|
|
||||||
self.playlist_visible_height
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.selected_playlist_index < self.playlist_scroll_offset {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index;
|
|
||||||
} else if self.selected_playlist_index >= self.playlist_scroll_offset + effective_height {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.search_mode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_playlist_search_match(&mut self) {
|
|
||||||
if !self.playlist_search_matches.is_empty() {
|
|
||||||
self.playlist_search_match_index = (self.playlist_search_match_index + 1) % self.playlist_search_matches.len();
|
|
||||||
let match_idx = self.playlist_search_matches[self.playlist_search_match_index];
|
|
||||||
self.selected_playlist_index = match_idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
// Account for "... X more below" indicator which takes one line
|
|
||||||
let visible_end = self.playlist_scroll_offset + self.playlist_visible_height;
|
|
||||||
let items_below = if visible_end < self.playlist.len() {
|
|
||||||
self.playlist.len() - visible_end
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let effective_height = if items_below > 0 {
|
|
||||||
self.playlist_visible_height.saturating_sub(1)
|
|
||||||
} else {
|
|
||||||
self.playlist_visible_height
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.selected_playlist_index < self.playlist_scroll_offset {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index;
|
|
||||||
} else if self.selected_playlist_index >= self.playlist_scroll_offset + effective_height {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn prev_playlist_search_match(&mut self) {
|
|
||||||
if !self.playlist_search_matches.is_empty() {
|
|
||||||
if self.playlist_search_match_index == 0 {
|
|
||||||
self.playlist_search_match_index = self.playlist_search_matches.len() - 1;
|
|
||||||
} else {
|
|
||||||
self.playlist_search_match_index -= 1;
|
|
||||||
}
|
|
||||||
let match_idx = self.playlist_search_matches[self.playlist_search_match_index];
|
|
||||||
self.selected_playlist_index = match_idx;
|
|
||||||
|
|
||||||
// Scroll to show the match
|
|
||||||
// Account for "... X more below" indicator which takes one line
|
|
||||||
let visible_end = self.playlist_scroll_offset + self.playlist_visible_height;
|
|
||||||
let items_below = if visible_end < self.playlist.len() {
|
|
||||||
self.playlist.len() - visible_end
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let effective_height = if items_below > 0 {
|
|
||||||
self.playlist_visible_height.saturating_sub(1)
|
|
||||||
} else {
|
|
||||||
self.playlist_visible_height
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.selected_playlist_index < self.playlist_scroll_offset {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index;
|
|
||||||
} else if self.selected_playlist_index >= self.playlist_scroll_offset + effective_height {
|
|
||||||
self.playlist_scroll_offset = self.selected_playlist_index - effective_height + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
278
src/ui/mod.rs
278
src/ui/mod.rs
@@ -28,24 +28,60 @@ pub fn render(frame: &mut Frame, state: &mut AppState, player: &mut Player) -> (
|
|||||||
])
|
])
|
||||||
.split(frame.area());
|
.split(frame.area());
|
||||||
|
|
||||||
// Main content: left (files) | right (status + playlist)
|
// Always use tab mode - show only the focused panel
|
||||||
// Switch proportions based on focus: 80/20 for focused panel
|
let tab_mode = true;
|
||||||
let (left_percent, right_percent) = if state.focus_playlist {
|
|
||||||
(20, 80) // Playlist focused: small file panel, large playlist
|
// Build the title with focused panel in bold
|
||||||
|
let file_style = if !state.focus_playlist {
|
||||||
|
Style::default().fg(Theme::bright_foreground()).add_modifier(Modifier::BOLD)
|
||||||
} else {
|
} else {
|
||||||
(80, 20) // File panel focused: large file panel, small playlist
|
Style::default().fg(Theme::bright_foreground())
|
||||||
};
|
};
|
||||||
|
|
||||||
let content_chunks = Layout::default()
|
let playlist_style = if state.focus_playlist {
|
||||||
.direction(Direction::Horizontal)
|
Style::default().fg(Theme::bright_foreground()).add_modifier(Modifier::BOLD)
|
||||||
.constraints([Constraint::Percentage(left_percent), Constraint::Percentage(right_percent)])
|
} else {
|
||||||
.split(main_chunks[1]);
|
Style::default().fg(Theme::bright_foreground())
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add playlist counter
|
||||||
|
let playlist_text = if !state.playlist.is_empty() {
|
||||||
|
format!("playlist [{}/{}]", state.playlist_index + 1, state.playlist.len())
|
||||||
|
} else {
|
||||||
|
"playlist (empty)".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
let title = Line::from(vec![
|
||||||
|
Span::styled("files", file_style),
|
||||||
|
Span::raw(" | "),
|
||||||
|
Span::styled(playlist_text, playlist_style),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create one border around the entire content area with fixed gray border
|
||||||
|
let main_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.title(title)
|
||||||
|
.style(Theme::widget_border_style());
|
||||||
|
|
||||||
|
let inner_area = main_block.inner(main_chunks[1]);
|
||||||
|
|
||||||
render_title_bar(frame, state, player, main_chunks[0]);
|
render_title_bar(frame, state, player, main_chunks[0]);
|
||||||
render_file_panel(frame, state, content_chunks[0]);
|
frame.render_widget(main_block, main_chunks[1]);
|
||||||
render_right_panel(frame, state, content_chunks[1]);
|
|
||||||
|
// Tab mode - show only focused panel
|
||||||
|
if state.focus_playlist {
|
||||||
|
render_right_panel(frame, state, inner_area, tab_mode);
|
||||||
|
} else {
|
||||||
|
render_file_panel(frame, state, inner_area, tab_mode);
|
||||||
|
}
|
||||||
|
|
||||||
render_status_bar(frame, state, player, main_chunks[2]);
|
render_status_bar(frame, state, player, main_chunks[2]);
|
||||||
|
|
||||||
|
// Show refreshing popup if scanning
|
||||||
|
if state.is_refreshing {
|
||||||
|
render_refresh_popup(frame, state.refresh_file_count);
|
||||||
|
}
|
||||||
|
|
||||||
// Show confirmation popup if needed
|
// Show confirmation popup if needed
|
||||||
if state.show_refresh_confirm {
|
if state.show_refresh_confirm {
|
||||||
render_confirm_popup(frame, "Refresh library?", "This may take a while");
|
render_confirm_popup(frame, "Refresh library?", "This may take a while");
|
||||||
@@ -57,7 +93,12 @@ pub fn render(frame: &mut Frame, state: &mut AppState, player: &mut Player) -> (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return title bar area, file panel area, and playlist area for mouse event handling
|
// Return title bar area, file panel area, and playlist area for mouse event handling
|
||||||
(main_chunks[0], content_chunks[0], content_chunks[1])
|
// Use main_chunks[1] (full area) so mouse coordinates align properly
|
||||||
|
if state.focus_playlist {
|
||||||
|
(main_chunks[0], Rect::default(), main_chunks[1])
|
||||||
|
} else {
|
||||||
|
(main_chunks[0], main_chunks[1], Rect::default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_search_matches<'a>(text: &str, query: &str, is_selected: bool) -> Vec<Span<'a>> {
|
fn highlight_search_matches<'a>(text: &str, query: &str, is_selected: bool) -> Vec<Span<'a>> {
|
||||||
@@ -115,13 +156,13 @@ fn highlight_search_matches<'a>(text: &str, query: &str, is_selected: bool) -> V
|
|||||||
spans
|
spans
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_file_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
fn render_file_panel(frame: &mut Frame, state: &mut AppState, area: Rect, _tab_mode: bool) {
|
||||||
// Calculate visible height (subtract 2 for borders)
|
// Calculate visible height (no borders on individual panels now)
|
||||||
let visible_height = area.height.saturating_sub(2) as usize;
|
let visible_height = area.height as usize;
|
||||||
// Store visible height for keyboard navigation scroll calculations
|
// Store visible height for keyboard navigation scroll calculations
|
||||||
state.file_panel_visible_height = visible_height;
|
state.file_panel_visible_height = visible_height;
|
||||||
|
|
||||||
let in_search = !state.focus_playlist && (state.search_mode || !state.search_matches.is_empty());
|
let in_search = !state.focus_playlist && state.search_mode;
|
||||||
let search_query = if in_search { state.search_query.to_lowercase() } else { String::new() };
|
let search_query = if in_search { state.search_query.to_lowercase() } else { String::new() };
|
||||||
|
|
||||||
// Calculate how many items are below the visible area
|
// Calculate how many items are below the visible area
|
||||||
@@ -233,14 +274,7 @@ fn render_file_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
items.push(more_item);
|
items.push(more_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
let list = List::new(items)
|
let list = List::new(items);
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.title("files")
|
|
||||||
.style(Theme::widget_border_style())
|
|
||||||
.title_style(Theme::title_style()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut list_state = ListState::default();
|
let mut list_state = ListState::default();
|
||||||
// Don't set selection to avoid automatic scrolling - we manage scroll manually
|
// Don't set selection to avoid automatic scrolling - we manage scroll manually
|
||||||
@@ -249,9 +283,9 @@ fn render_file_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
frame.render_stateful_widget(list, area, &mut list_state);
|
frame.render_stateful_widget(list, area, &mut list_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect, _tab_mode: bool) {
|
||||||
// Calculate visible height (subtract 2 for borders)
|
// Calculate visible height (no borders on individual panels now)
|
||||||
let visible_height = area.height.saturating_sub(2) as usize;
|
let visible_height = area.height as usize;
|
||||||
// Store visible height for keyboard navigation scroll calculations
|
// Store visible height for keyboard navigation scroll calculations
|
||||||
state.playlist_visible_height = visible_height;
|
state.playlist_visible_height = visible_height;
|
||||||
|
|
||||||
@@ -272,7 +306,7 @@ fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check if in playlist search mode
|
// Check if in playlist search mode
|
||||||
let in_playlist_search = state.focus_playlist && (state.search_mode || !state.playlist_tab_search_results.is_empty() || !state.playlist_search_matches.is_empty());
|
let in_playlist_search = state.focus_playlist && state.search_mode;
|
||||||
let playlist_search_query = if in_playlist_search { state.search_query.to_lowercase() } else { String::new() };
|
let playlist_search_query = if in_playlist_search { state.search_query.to_lowercase() } else { String::new() };
|
||||||
|
|
||||||
// Playlist panel (no longer need the player status box)
|
// Playlist panel (no longer need the player status box)
|
||||||
@@ -292,12 +326,17 @@ fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
let is_selected = state.focus_playlist && idx == state.selected_playlist_index;
|
let is_selected = state.focus_playlist && idx == state.selected_playlist_index;
|
||||||
let is_playing = idx == state.playlist_index;
|
let is_playing = idx == state.playlist_index;
|
||||||
|
|
||||||
|
// Add playing indicator arrow
|
||||||
|
let indicator = if is_playing { "▸ " } else { " " };
|
||||||
|
|
||||||
// Build line with search highlighting if searching
|
// Build line with search highlighting if searching
|
||||||
let line = if in_playlist_search && !playlist_search_query.is_empty() {
|
let mut line_spans = vec![Span::raw(indicator)];
|
||||||
Line::from(highlight_search_matches(&filename, &playlist_search_query, is_selected))
|
if in_playlist_search && !playlist_search_query.is_empty() {
|
||||||
|
line_spans.extend(highlight_search_matches(&filename, &playlist_search_query, is_selected));
|
||||||
} else {
|
} else {
|
||||||
Line::from(filename)
|
line_spans.push(Span::raw(filename));
|
||||||
};
|
}
|
||||||
|
let line = Line::from(line_spans);
|
||||||
|
|
||||||
let style = if is_selected && is_playing {
|
let style = if is_selected && is_playing {
|
||||||
// Both selected and playing: selection bar with bold
|
// Both selected and playing: selection bar with bold
|
||||||
@@ -335,20 +374,7 @@ fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
playlist_items.push(more_item);
|
playlist_items.push(more_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
let playlist_title = if !state.playlist.is_empty() {
|
let playlist_widget = List::new(playlist_items);
|
||||||
format!("playlist [{}/{}]", state.playlist_index + 1, state.playlist.len())
|
|
||||||
} else {
|
|
||||||
"playlist (empty)".to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
let playlist_widget = List::new(playlist_items)
|
|
||||||
.block(
|
|
||||||
Block::default()
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.title(playlist_title)
|
|
||||||
.style(Theme::widget_border_style())
|
|
||||||
.title_style(Theme::title_style()),
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut playlist_state = ListState::default();
|
let mut playlist_state = ListState::default();
|
||||||
// Don't set selection to avoid automatic scrolling - we manage scroll manually
|
// Don't set selection to avoid automatic scrolling - we manage scroll manually
|
||||||
@@ -358,12 +384,17 @@ fn render_right_panel(frame: &mut Frame, state: &mut AppState, area: Rect) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_title_bar(frame: &mut Frame, state: &AppState, player: &mut Player, area: Rect) {
|
fn render_title_bar(frame: &mut Frame, state: &AppState, player: &mut Player, area: Rect) {
|
||||||
// Default to stopped if we can't query MPV
|
// Get player state
|
||||||
let player_state = player.get_player_state().unwrap_or(PlayerState::Stopped);
|
let player_state = player.get_player_state().unwrap_or(PlayerState::Stopped);
|
||||||
let background_color = match player_state {
|
|
||||||
PlayerState::Playing => Theme::success(), // Green for playing
|
// Title bar background color: red for error, gray for stopped/paused, green for playing
|
||||||
PlayerState::Paused => Theme::highlight(), // Blue for paused
|
let background_color = if state.last_error.is_some() {
|
||||||
PlayerState::Stopped => Theme::dim_foreground(), // Gray for stopped
|
Theme::error()
|
||||||
|
} else {
|
||||||
|
match player_state {
|
||||||
|
PlayerState::Playing => Theme::success(), // Green for playing
|
||||||
|
PlayerState::Paused | PlayerState::Stopped => Theme::border(), // Gray for paused/stopped
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Split the title bar into left and right sections
|
// Split the title bar into left and right sections
|
||||||
@@ -388,16 +419,7 @@ fn render_title_bar(frame: &mut Frame, state: &AppState, player: &mut Player, ar
|
|||||||
// Right side: Status • Progress • Volume • Search (if active)
|
// Right side: Status • Progress • Volume • Search (if active)
|
||||||
let mut right_spans = Vec::new();
|
let mut right_spans = Vec::new();
|
||||||
|
|
||||||
if state.is_refreshing {
|
{
|
||||||
// Show only "Refreshing library..." when refreshing
|
|
||||||
right_spans.push(Span::styled(
|
|
||||||
"Refreshing library... ",
|
|
||||||
Style::default()
|
|
||||||
.fg(Theme::background())
|
|
||||||
.bg(background_color)
|
|
||||||
.add_modifier(Modifier::BOLD)
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
// Status (bold when playing)
|
// Status (bold when playing)
|
||||||
let status_text = match player_state {
|
let status_text = match player_state {
|
||||||
PlayerState::Stopped => "Stopped",
|
PlayerState::Stopped => "Stopped",
|
||||||
@@ -485,8 +507,8 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, player: &mut Player, a
|
|||||||
// Show search prompt with current query and match count - LEFT aligned
|
// Show search prompt with current query and match count - LEFT aligned
|
||||||
if state.focus_playlist {
|
if state.focus_playlist {
|
||||||
// Searching in playlist
|
// Searching in playlist
|
||||||
if !state.playlist_tab_search_results.is_empty() {
|
if !state.playlist_search_results.is_empty() {
|
||||||
format!("/{}_ Playlist Search: {}/{}", state.search_query, state.playlist_tab_search_index + 1, state.playlist_tab_search_results.len())
|
format!("/{}_ Playlist Search: {}/{}", state.search_query, state.playlist_search_result_index + 1, state.playlist_search_results.len())
|
||||||
} else if !state.search_query.is_empty() {
|
} else if !state.search_query.is_empty() {
|
||||||
format!("/{}_ [no matches]", state.search_query)
|
format!("/{}_ [no matches]", state.search_query)
|
||||||
} else {
|
} else {
|
||||||
@@ -494,20 +516,14 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, player: &mut Player, a
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Searching in file panel
|
// Searching in file panel
|
||||||
if !state.tab_search_results.is_empty() {
|
if !state.search_results.is_empty() {
|
||||||
format!("/{}_ Search: {}/{}", state.search_query, state.tab_search_index + 1, state.tab_search_results.len())
|
format!("/{}_ Search: {}/{}", state.search_query, state.search_result_index + 1, state.search_results.len())
|
||||||
} else if !state.search_query.is_empty() {
|
} else if !state.search_query.is_empty() {
|
||||||
format!("/{}_ [no matches]", state.search_query)
|
format!("/{}_ [no matches]", state.search_query)
|
||||||
} else {
|
} else {
|
||||||
format!("/{}_", state.search_query)
|
format!("/{}_", state.search_query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !state.search_matches.is_empty() {
|
|
||||||
// Show search navigation when file search results are active
|
|
||||||
format!("/{} Search: {}/{}", state.search_query, state.search_match_index + 1, state.search_matches.len())
|
|
||||||
} else if !state.playlist_search_matches.is_empty() {
|
|
||||||
// Show search navigation when playlist search results are active
|
|
||||||
format!("/{} Playlist Search: {}/{}", state.search_query, state.playlist_search_match_index + 1, state.playlist_search_matches.len())
|
|
||||||
} else if state.visual_mode {
|
} else if state.visual_mode {
|
||||||
// Show visual mode indicator
|
// Show visual mode indicator
|
||||||
format!("-- VISUAL -- {} files marked", state.marked_files.len())
|
format!("-- VISUAL -- {} files marked", state.marked_files.len())
|
||||||
@@ -590,23 +606,9 @@ fn render_status_bar(frame: &mut Frame, state: &AppState, player: &mut Player, a
|
|||||||
|
|
||||||
fn render_progress_bar(frame: &mut Frame, _state: &AppState, player: &mut Player, area: Rect, progress_percent: f64) {
|
fn render_progress_bar(frame: &mut Frame, _state: &AppState, player: &mut Player, area: Rect, progress_percent: f64) {
|
||||||
// Get metadata to display
|
// Get metadata to display
|
||||||
let mut left_parts = Vec::new();
|
|
||||||
let mut right_parts = Vec::new();
|
let mut right_parts = Vec::new();
|
||||||
|
|
||||||
// Left side: Artist | Album | Title
|
// Right side: Bitrate | Codec | Sample rate (metrics that must always be visible)
|
||||||
if let Some(ref artist) = player.artist {
|
|
||||||
left_parts.push(artist.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref album) = player.album {
|
|
||||||
left_parts.push(album.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(ref title) = player.media_title {
|
|
||||||
left_parts.push(title.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Right side: Bitrate | Codec | Sample rate | Cache
|
|
||||||
if let Some(bitrate) = player.audio_bitrate {
|
if let Some(bitrate) = player.audio_bitrate {
|
||||||
right_parts.push(format!("{:.0} kbps", bitrate));
|
right_parts.push(format!("{:.0} kbps", bitrate));
|
||||||
}
|
}
|
||||||
@@ -619,21 +621,59 @@ fn render_progress_bar(frame: &mut Frame, _state: &AppState, player: &mut Player
|
|||||||
right_parts.push(format!("{} Hz", samplerate));
|
right_parts.push(format!("{} Hz", samplerate));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build text parts
|
// Build right text
|
||||||
let left_text = if !left_parts.is_empty() {
|
|
||||||
format!(" {}", left_parts.join(" | "))
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
let right_text = if !right_parts.is_empty() {
|
let right_text = if !right_parts.is_empty() {
|
||||||
format!("{} ", right_parts.join(" | "))
|
format!("{} ", right_parts.join(" | "))
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate filled width based on progress
|
// Calculate available space
|
||||||
let total_width = area.width as usize;
|
let total_width = area.width as usize;
|
||||||
|
let right_text_len = right_text.chars().count();
|
||||||
|
|
||||||
|
// Reserve space: 1 char at start, gap between left and right
|
||||||
|
let available_for_left = total_width.saturating_sub(right_text_len).saturating_sub(2);
|
||||||
|
|
||||||
|
// Collect left side metadata
|
||||||
|
let mut left_fields = Vec::new();
|
||||||
|
if let Some(ref artist) = player.artist {
|
||||||
|
left_fields.push(("artist", artist.as_str()));
|
||||||
|
}
|
||||||
|
if let Some(ref album) = player.album {
|
||||||
|
left_fields.push(("album", album.as_str()));
|
||||||
|
}
|
||||||
|
if let Some(ref title) = player.media_title {
|
||||||
|
left_fields.push(("title", title.as_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate space per field (divide available space among fields)
|
||||||
|
let left_text = if !left_fields.is_empty() {
|
||||||
|
let num_fields = left_fields.len();
|
||||||
|
let separator_space = (num_fields - 1) * 3; // " | " between fields
|
||||||
|
let available_for_fields = available_for_left.saturating_sub(separator_space);
|
||||||
|
let max_per_field = available_for_fields / num_fields;
|
||||||
|
|
||||||
|
// Truncate each field individually
|
||||||
|
let truncated_fields: Vec<String> = left_fields.iter().map(|(_name, value)| {
|
||||||
|
if value.chars().count() > max_per_field && max_per_field > 3 {
|
||||||
|
let mut s: String = value.chars().take(max_per_field - 3).collect();
|
||||||
|
s.push_str("...");
|
||||||
|
s
|
||||||
|
} else if value.chars().count() > max_per_field {
|
||||||
|
// Very tight space, just cut hard
|
||||||
|
value.chars().take(max_per_field).collect()
|
||||||
|
} else {
|
||||||
|
value.to_string()
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
format!(" {}", truncated_fields.join(" | "))
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate filled width based on progress
|
||||||
let filled_width = (total_width as f64 * progress_percent) as usize;
|
let filled_width = (total_width as f64 * progress_percent) as usize;
|
||||||
|
|
||||||
// Build the full line character by character with proper spacing
|
// Build the full line character by character with proper spacing
|
||||||
@@ -679,6 +719,56 @@ fn render_progress_bar(frame: &mut Frame, _state: &AppState, player: &mut Player
|
|||||||
frame.render_widget(progress_widget, area);
|
frame.render_widget(progress_widget, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_refresh_popup(frame: &mut Frame, file_count: usize) {
|
||||||
|
// Create centered popup area - bigger for two lines
|
||||||
|
let area = frame.area();
|
||||||
|
let popup_width = 50;
|
||||||
|
let popup_height = 5;
|
||||||
|
|
||||||
|
let popup_area = Rect {
|
||||||
|
x: (area.width.saturating_sub(popup_width)) / 2,
|
||||||
|
y: (area.height.saturating_sub(popup_height)) / 2,
|
||||||
|
width: popup_width.min(area.width),
|
||||||
|
height: popup_height.min(area.height),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use Clear widget to completely erase the background
|
||||||
|
frame.render_widget(Clear, popup_area);
|
||||||
|
|
||||||
|
// Render the popup block with solid background
|
||||||
|
let block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.style(Style::default()
|
||||||
|
.bg(Theme::background())
|
||||||
|
.fg(Theme::bright_foreground()));
|
||||||
|
|
||||||
|
let inner = block.inner(popup_area);
|
||||||
|
frame.render_widget(block, popup_area);
|
||||||
|
|
||||||
|
// Build two-line message
|
||||||
|
let lines = if file_count > 0 {
|
||||||
|
vec![
|
||||||
|
Line::from("Refreshing library..."),
|
||||||
|
Line::from(""),
|
||||||
|
Line::from(format!("{} files found", file_count))
|
||||||
|
.style(Style::default().fg(Theme::highlight())),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![
|
||||||
|
Line::from("Refreshing library..."),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Render message centered
|
||||||
|
let message_widget = Paragraph::new(lines)
|
||||||
|
.alignment(Alignment::Center)
|
||||||
|
.style(Style::default()
|
||||||
|
.fg(Theme::bright_foreground())
|
||||||
|
.bg(Theme::background()));
|
||||||
|
|
||||||
|
frame.render_widget(message_widget, inner);
|
||||||
|
}
|
||||||
|
|
||||||
fn render_confirm_popup(frame: &mut Frame, title: &str, message: &str) {
|
fn render_confirm_popup(frame: &mut Frame, title: &str, message: &str) {
|
||||||
// Create centered popup area
|
// Create centered popup area
|
||||||
let area = frame.area();
|
let area = frame.area();
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ impl Theme {
|
|||||||
Color::Rgb(215, 175, 95) // #d7af5f
|
Color::Rgb(215, 175, 95) // #d7af5f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn normal_red() -> Color {
|
||||||
|
Color::Rgb(215, 95, 95) // #d75f5f
|
||||||
|
}
|
||||||
|
|
||||||
// Semantic mappings
|
// Semantic mappings
|
||||||
pub fn secondary_text() -> Color {
|
pub fn secondary_text() -> Color {
|
||||||
Self::foreground()
|
Self::foreground()
|
||||||
@@ -47,10 +51,6 @@ impl Theme {
|
|||||||
Self::dim_foreground()
|
Self::dim_foreground()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn border_title() -> Color {
|
|
||||||
Self::bright_foreground()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn highlight() -> Color {
|
pub fn highlight() -> Color {
|
||||||
Self::normal_blue()
|
Self::normal_blue()
|
||||||
}
|
}
|
||||||
@@ -63,17 +63,15 @@ impl Theme {
|
|||||||
Self::normal_yellow()
|
Self::normal_yellow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn error() -> Color {
|
||||||
|
Self::normal_red()
|
||||||
|
}
|
||||||
|
|
||||||
// Styles
|
// Styles
|
||||||
pub fn widget_border_style() -> Style {
|
pub fn widget_border_style() -> Style {
|
||||||
Style::default().fg(Self::border()).bg(Self::background())
|
Style::default().fg(Self::border()).bg(Self::background())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title_style() -> Style {
|
|
||||||
Style::default()
|
|
||||||
.fg(Self::border_title())
|
|
||||||
.bg(Self::background())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn secondary() -> Style {
|
pub fn secondary() -> Style {
|
||||||
Style::default()
|
Style::default()
|
||||||
.fg(Self::secondary_text())
|
.fg(Self::secondary_text())
|
||||||
|
|||||||
Reference in New Issue
Block a user