From 4e7af1c920bd5f4b75d1260b4c3c0657b0bfc94c Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sat, 18 Apr 2020 21:57:41 +0200 Subject: [PATCH] add command/binding to jump to currently playing track fixes #181 --- README.md | 1 + src/command.rs | 4 ++++ src/commands.rs | 4 ++++ src/queue.rs | 6 +++++- src/ui/queue.rs | 7 ++++++- 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a1c1e3d..ba7c81a 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ have them configurable. * `F3`: Library * `d` deletes the currently selected playlist * Tracks and playlists can be played using `Return` and queued using `Space` +* `.` will move to the currently playing track in the queue. * `s` will save, `d` will remove the currently selected track to/from your library * `o` will open a detail view or context menu for the selected item diff --git a/src/command.rs b/src/command.rs index 7b1fb23..85c4372 100644 --- a/src/command.rs +++ b/src/command.rs @@ -26,6 +26,7 @@ pub enum MoveMode { Down, Left, Right, + Playing, } #[derive(Display, Clone, Serialize, Deserialize, Debug)] @@ -144,8 +145,10 @@ impl fmt::Display for Command { MoveMode::Down => "bottom", MoveMode::Left => "leftmost", MoveMode::Right => "rightmost", + _ => "", } ), + Command::Move(MoveMode::Playing, _) => "move playing".to_string(), Command::Move(mode, MoveAmount::Integer(amount)) => format!("move {} {}", mode, amount), Command::Shift(mode, amount) => format!("shift {} {}", mode, amount.unwrap_or(1)), Command::Search(term) => format!("search {}", term), @@ -235,6 +238,7 @@ pub fn parse(input: &str) -> Option { "bottom" => Some(Command::Move(MoveMode::Down, MoveAmount::Extreme)), "leftmost" => Some(Command::Move(MoveMode::Left, MoveAmount::Extreme)), "rightmost" => Some(Command::Move(MoveMode::Right, MoveAmount::Extreme)), + "playing" => Some(Command::Move(MoveMode::Playing, MoveAmount::default())), _ => None, }) }; diff --git a/src/commands.rs b/src/commands.rs index 71ebf22..deb25f0 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -265,6 +265,10 @@ impl CommandManager { kb.insert("A".into(), Command::Goto(GotoMode::Artist)); kb.insert("Up".into(), Command::Move(MoveMode::Up, Default::default())); + kb.insert( + ".".into(), + Command::Move(MoveMode::Playing, Default::default()), + ); kb.insert( "Down".into(), Command::Move(MoveMode::Down, Default::default()), diff --git a/src/queue.rs b/src/queue.rs index 38b3ad2..c072b29 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -83,12 +83,16 @@ impl Queue { } pub fn get_current(&self) -> Option { - match *self.current_track.read().unwrap() { + match self.get_current_index() { Some(index) => Some(self.queue.read().unwrap()[index].clone()), None => None, } } + pub fn get_current_index(&self) -> Option { + *self.current_track.read().unwrap() + } + pub fn append(&self, track: &Track) { let mut random_order = self.random_order.write().unwrap(); if let Some(order) = random_order.as_mut() { diff --git a/src/ui/queue.rs b/src/ui/queue.rs index 9506626..49307a7 100644 --- a/src/ui/queue.rs +++ b/src/ui/queue.rs @@ -6,7 +6,7 @@ use cursive::Cursive; use std::cmp::min; use std::sync::Arc; -use crate::command::{Command, ShiftMode}; +use crate::command::{Command, MoveMode, ShiftMode}; use crate::commands::CommandResult; use crate::library::Library; use crate::queue::Queue; @@ -132,6 +132,11 @@ impl ViewExt for QueueView { s.add_layer(dialog); return Ok(CommandResult::Consumed(None)); } + Command::Move(MoveMode::Playing, _) => { + if let Some(playing) = self.queue.get_current_index() { + self.list.move_focus_to(playing); + } + } _ => {} }