From e36aed010f8f1068f014639ea97af292119c9ada Mon Sep 17 00:00:00 2001 From: mierak <47547062+mierak@users.noreply.github.com> Date: Mon, 28 Oct 2024 18:04:09 +0100 Subject: [PATCH] feat: global info for currently playing song (#112) * feat: global info for currently playing song * fix tests --- CHANGELOG.md | 2 ++ assets/example_config.ron | 1 + docs/src/content/docs/configuration/keybinds.mdx | 1 + src/config/keys/actions.rs | 4 ++++ src/config/keys/mod.rs | 1 + src/ui/mod.rs | 14 ++++++++++++-- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cad8d3b..948890e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,12 +12,14 @@ All notable changes to this project will be documented in this file. - Update/rescan CLI commands to refresh MPD's database - Support MPD password via config, env vars and CLI - ShowInfo action to queue pane. Displays metadata of the song under cursor in a modal popup. +- ShowCurrentSongInfo global action. Displays metadata of the song currently playing song in a modal popup. ### Changed - Removed left/right arrows as default keybinds for next/previous tab. You can still put these back by editing your config. - Filtering is now incremental - Up/Down actions do not wrap around anymore. You can get the previous behavior back with the `wrap_navigation` config option +- Allow seeking while paused ### Fixed diff --git a/assets/example_config.ron b/assets/example_config.ron index 10131f7..7c276ea 100644 --- a/assets/example_config.ron +++ b/assets/example_config.ron @@ -42,6 +42,7 @@ "z": ToggleRepeat, "b": SeekBack, "~": ShowHelp, + "I": ShowCurrentSongInfo, "O": ShowOutputs, }, navigation: { diff --git a/docs/src/content/docs/configuration/keybinds.mdx b/docs/src/content/docs/configuration/keybinds.mdx index 4b386fd..7f551c7 100644 --- a/docs/src/content/docs/configuration/keybinds.mdx +++ b/docs/src/content/docs/configuration/keybinds.mdx @@ -69,6 +69,7 @@ between different tabs and exiting rmpc. | `:` | CommandMode | Enter command mode. Commands that can be used are the same as in the CLI | | | ExternalCommand | Special keybind that allows you to bind external commands to a key. Check [ExternalCommand](#externalcommand) for more info. | | `q` | ShowHelp | Show keybinds modal | +| `I` | ShowCurrentSongInfo | Show metadata of the currently playing song in a modal popup | | `O` | ShowOutputs | Show MPD outputs config modal | | `z` | ToggleRepeat | Toggle repeat | | `c` | ToggleSingle | Whether to stop playing after single track or repeat track/playlist when repeat is on | diff --git a/src/config/keys/actions.rs b/src/config/keys/actions.rs index a20b447..ce6bf83 100644 --- a/src/config/keys/actions.rs +++ b/src/config/keys/actions.rs @@ -11,6 +11,7 @@ use super::ToDescription; pub enum GlobalAction { Quit, ShowHelp, + ShowCurrentSongInfo, ShowOutputs, NextTrack, PreviousTrack, @@ -42,6 +43,7 @@ pub enum GlobalAction { pub enum GlobalActionFile { Quit, ShowHelp, + ShowCurrentSongInfo, ShowOutputs, NextTrack, PreviousTrack, @@ -80,6 +82,7 @@ impl From for GlobalAction { match value { GlobalActionFile::Quit => GlobalAction::Quit, GlobalActionFile::ShowOutputs => GlobalAction::ShowOutputs, + GlobalActionFile::ShowCurrentSongInfo => GlobalAction::ShowCurrentSongInfo, GlobalActionFile::CommandMode => GlobalAction::CommandMode, GlobalActionFile::Command { command, description } => GlobalAction::Command { command: command.leak(), @@ -124,6 +127,7 @@ impl ToDescription for GlobalAction { match self { GlobalAction::Quit => "Exit rmpc", GlobalAction::ShowOutputs => "Show MPD outputs config", + GlobalAction::ShowCurrentSongInfo => "Show metadata of the currently playing song in a modal popup", GlobalAction::ToggleRepeat => "Toggle repeat", GlobalAction::ToggleSingle => { "Whether to stop playing after single track or repeat track/playlist when repeat is on" diff --git a/src/config/keys/mod.rs b/src/config/keys/mod.rs index eb2ff14..da7375c 100644 --- a/src/config/keys/mod.rs +++ b/src/config/keys/mod.rs @@ -73,6 +73,7 @@ impl Default for KeyConfigFile { (Key { key: K::Char('q'), modifiers: M::NONE }, G::Quit), (Key { key: K::Char(':'), modifiers: M::NONE }, G::CommandMode), (Key { key: K::Char('~'), modifiers: M::NONE }, G::ShowHelp), + (Key { key: K::Char('I'), modifiers: M::SHIFT }, G::ShowCurrentSongInfo), (Key { key: K::Char('O'), modifiers: M::SHIFT }, G::ShowOutputs), (Key { key: K::Char('>'), modifiers: M::NONE }, G::NextTrack), (Key { key: K::Char('<'), modifiers: M::NONE }, G::PreviousTrack), diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 5a0c182..de0f02f 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -8,7 +8,7 @@ use crossterm::{ }; use enum_map::{enum_map, Enum, EnumMap}; use itertools::Itertools; -use modals::{keybinds::KeybindsModal, outputs::OutputsModal}; +use modals::{keybinds::KeybindsModal, outputs::OutputsModal, song_info::SongInfoModal}; use panes::{PaneContainer, Panes}; use ratatui::{ layout::Rect, @@ -36,7 +36,7 @@ use crate::{ mpd_client::{FilterKind, MpdClient, ValueChange}, }, utils::{ - macros::{status_error, try_ret}, + macros::{status_error, status_info, try_ret}, mouse_event::{MouseEvent, MouseEventKind}, }, }; @@ -486,6 +486,16 @@ impl<'ui> Ui<'ui> { self.on_event(UiEvent::ModalOpened, context, client)?; return Ok(KeyHandleResult::RenderRequested); } + GlobalAction::ShowCurrentSongInfo => { + if let Some(current_song) = context.get_current_song(client)? { + self.modals.push(Box::new(SongInfoModal::new(current_song))); + self.on_event(UiEvent::ModalOpened, context, client)?; + return Ok(KeyHandleResult::RenderRequested); + } + + status_info!("No song is currently playing"); + return Ok(KeyHandleResult::SkipRender); + } } Ok(KeyHandleResult::SkipRender) } else {