Implement vim-style navigation and visual mode
All checks were successful
Build and Release / build-and-release (push) Successful in 51s
All checks were successful
Build and Release / build-and-release (push) Successful in 51s
- Add vim-style h key: closes folders and jumps to parent - Implement stop() method in player for proper playback stopping - Add space key to restart playback when stopped - Add playlist color coding: green (playing), blue (paused), yellow (stopped) - Fix n/p keys to preserve player state when switching tracks - Implement vim-style visual mode with v key for multi-file selection - Visual mode exits automatically on play/add actions - Remove unused play_previous method - Bump version to 0.1.7
This commit is contained in:
92
src/main.rs
92
src/main.rs
@@ -161,24 +161,40 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
}
|
||||
(KeyCode::Esc, _) => {
|
||||
state.search_matches.clear();
|
||||
if state.visual_mode {
|
||||
state.visual_mode = false;
|
||||
state.marked_files.clear();
|
||||
}
|
||||
}
|
||||
(KeyCode::Char('n'), _) => {
|
||||
if !state.search_matches.is_empty() {
|
||||
state.next_search_match();
|
||||
} else {
|
||||
// If stopped, start from current index (0), otherwise go to next
|
||||
if state.player_state == PlayerState::Stopped && !state.playlist.is_empty() {
|
||||
} else if !state.playlist.is_empty() {
|
||||
// Advance to next track
|
||||
if state.playlist_index + 1 < state.playlist.len() {
|
||||
state.playlist_index += 1;
|
||||
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
||||
state.player_state = PlayerState::Playing;
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Starting playlist: {:?}", path);
|
||||
}
|
||||
} else {
|
||||
state.play_next();
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Next track: {:?}", path);
|
||||
|
||||
match state.player_state {
|
||||
PlayerState::Playing => {
|
||||
// Keep playing
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Next track: {:?}", path);
|
||||
}
|
||||
}
|
||||
PlayerState::Paused => {
|
||||
// Load but stay paused
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.pause()?;
|
||||
tracing::info!("Next track (paused): {:?}", path);
|
||||
}
|
||||
}
|
||||
PlayerState::Stopped => {
|
||||
// Just update current file, stay stopped
|
||||
tracing::info!("Next track selected (stopped): {:?}", state.current_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,15 +225,40 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
}
|
||||
(KeyCode::Char('a'), _) => {
|
||||
state.add_to_playlist();
|
||||
if state.visual_mode {
|
||||
state.visual_mode = false;
|
||||
state.marked_files.clear();
|
||||
}
|
||||
}
|
||||
(KeyCode::Char('c'), _) => {
|
||||
state.clear_playlist();
|
||||
}
|
||||
(KeyCode::Char('p'), _) => {
|
||||
state.play_previous();
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Previous track: {:?}", path);
|
||||
if !state.playlist.is_empty() && state.playlist_index > 0 {
|
||||
state.playlist_index -= 1;
|
||||
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
||||
|
||||
match state.player_state {
|
||||
PlayerState::Playing => {
|
||||
// Keep playing
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Previous track: {:?}", path);
|
||||
}
|
||||
}
|
||||
PlayerState::Paused => {
|
||||
// Load but stay paused
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
player.pause()?;
|
||||
tracing::info!("Previous track (paused): {:?}", path);
|
||||
}
|
||||
}
|
||||
PlayerState::Stopped => {
|
||||
// Just update current file, stay stopped
|
||||
tracing::info!("Previous track selected (stopped): {:?}", state.current_file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(KeyCode::Enter, _) => {
|
||||
@@ -226,9 +267,14 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
player.play(path)?;
|
||||
tracing::info!("Playing: {:?} (playlist: {} tracks)", path, state.playlist.len());
|
||||
}
|
||||
if state.visual_mode {
|
||||
state.visual_mode = false;
|
||||
state.marked_files.clear();
|
||||
}
|
||||
}
|
||||
(KeyCode::Char('s'), _) => {
|
||||
// s: Stop playback
|
||||
player.stop()?;
|
||||
state.player_state = PlayerState::Stopped;
|
||||
state.current_position = 0.0;
|
||||
state.current_duration = 0.0;
|
||||
@@ -246,7 +292,17 @@ async fn handle_key_event<B: ratatui::backend::Backend>(terminal: &mut Terminal<
|
||||
state.player_state = PlayerState::Playing;
|
||||
tracing::info!("Resumed");
|
||||
}
|
||||
PlayerState::Stopped => {}
|
||||
PlayerState::Stopped => {
|
||||
// Restart playback from current playlist position
|
||||
if !state.playlist.is_empty() {
|
||||
state.current_file = Some(state.playlist[state.playlist_index].clone());
|
||||
state.player_state = PlayerState::Playing;
|
||||
if let Some(ref path) = state.current_file {
|
||||
player.play(path)?;
|
||||
tracing::info!("Restarting playback: {:?}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(KeyCode::Left, _) => {
|
||||
|
||||
Reference in New Issue
Block a user