Skip to content

Commit

Permalink
feat: global info for currently playing song (#112)
Browse files Browse the repository at this point in the history
* feat: global info for currently playing song

* fix tests
  • Loading branch information
mierak authored Oct 28, 2024
1 parent eea07f1 commit e36aed0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions assets/example_config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"z": ToggleRepeat,
"b": SeekBack,
"~": ShowHelp,
"I": ShowCurrentSongInfo,
"O": ShowOutputs,
},
navigation: {
Expand Down
1 change: 1 addition & 0 deletions docs/src/content/docs/configuration/keybinds.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 4 additions & 0 deletions src/config/keys/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::ToDescription;
pub enum GlobalAction {
Quit,
ShowHelp,
ShowCurrentSongInfo,
ShowOutputs,
NextTrack,
PreviousTrack,
Expand Down Expand Up @@ -42,6 +43,7 @@ pub enum GlobalAction {
pub enum GlobalActionFile {
Quit,
ShowHelp,
ShowCurrentSongInfo,
ShowOutputs,
NextTrack,
PreviousTrack,
Expand Down Expand Up @@ -80,6 +82,7 @@ impl From<GlobalActionFile> 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(),
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/config/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 12 additions & 2 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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},
},
};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e36aed0

Please sign in to comment.