Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a library page #24

Merged
merged 11 commits into from
Oct 31, 2021
77 changes: 37 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
- [Docker](#docker)
- [Examples](#examples)
- [Demo](#demo)
- [Playlist](#playlist)
- [Artist](#artist)
- [Album](#album)
- [Search](#search)
- [Commands](#commands)
- [Actions](#actions)
- [Search Page](#search-page)
Expand Down Expand Up @@ -152,42 +148,43 @@ To open a command shortcut help popup when running the application, press `?` or

List of supported commands:

| Command | Description | Default shortcuts |
| --------------------------- | ----------------------------------------------------- | ------------------ |
| `NextTrack` | next track | `n` |
| `PreviousTrack` | previous track | `p` |
| `ResumePause` | resume/pause based on the current playback | `space` |
| `PlayRandom` | play a random track in the current context | `.` |
| `Repeat` | cycle the repeat mode | `C-r` |
| `Shuffle` | toggle the shuffle mode | `C-s` |
| `VolumeUp` | increase playback volume by 5% | `+` |
| `VolumeDown` | decrease playback volume by 5% | `-` |
| `Quit` | quit the application | `C-c`, `q` |
| `OpenCommandHelp` | open a command help popup | `?`, `C-h` |
| `ClosePopup` | close a popup | `esc` |
| `SelectNextOrScrollDown` | select the next item in a list/table or scroll down | `j`, `C-j`, `down` |
| `SelectPreviousOrScrollUp` | select the previous item in a list/table or scroll up | `k`, `C-k`, `up` |
| `ChooseSelected` | choose the selected item | `enter` |
| `RefreshPlayback` | manually refresh the current playback | `r` |
| `ShowActionsOnSelectedItem` | show actions on a selected item | `g a`, `C-space` |
| `ShowActionsOnCurrentTrack` | show actions on the currently playing track | `a` |
| `FocusNextWindow` | focus the next focusable window (if any) | `tab` |
| `FocusPreviousWindow` | focus the previous focusable window (if any) | `backtab` |
| `SwitchTheme` | open a popup for switching theme | `T` |
| `SwitchDevice` | open a popup for switching device | `D` |
| `SearchContext` | open a popup for searching the current context | `/` |
| `BrowseUserPlaylists` | open a popup for browsing user's playlists | `u p` |
| `BrowseUserFollowedArtists` | open a popup for browsing user's followed artists | `u a` |
| `BrowseUserSavedAlbums` | open a popup for browsing user's saved albums | `u A` |
| `BrowsePlayingContext` | browse the current playing context | `g space` |
| `SearchPage` | go to the search page | `g s` |
| `PreviousPage` | go to the previous page | `backspace`, `C-p` |
| `SortTrackByTitle` | sort the track table (if any) by track's title | `s t` |
| `SortTrackByArtists` | sort the track table (if any) by track's artists | `s a` |
| `SortTrackByAlbum` | sort the track table (if any) by track's album | `s A` |
| `SortTrackByDuration` | sort the track table (if any) by track's duration | `s d` |
| `SortTrackByAddedDate` | sort the track table (if any) by track's added date | `s D` |
| `ReverseOrder` | reverse the order of the track table (if any) | `s r` |
| Command | Description | Default shortcuts |
| --------------------------- | ----------------------------------------------------------- | ------------------ |
| `NextTrack` | next track | `n` |
| `PreviousTrack` | previous track | `p` |
| `ResumePause` | resume/pause based on the current playback | `space` |
| `PlayRandom` | play a random track in the current context | `.` |
| `Repeat` | cycle the repeat mode | `C-r` |
| `Shuffle` | toggle the shuffle mode | `C-s` |
| `VolumeUp` | increase playback volume by 5% | `+` |
| `VolumeDown` | decrease playback volume by 5% | `-` |
| `Quit` | quit the application | `C-c`, `q` |
| `OpenCommandHelp` | open a command help popup | `?`, `C-h` |
| `ClosePopup` | close a popup | `esc` |
| `SelectNextOrScrollDown` | select the next item in a list/table or scroll down | `j`, `C-j`, `down` |
| `SelectPreviousOrScrollUp` | select the previous item in a list/table or scroll up | `k`, `C-k`, `up` |
| `ChooseSelected` | choose the selected item | `enter` |
| `RefreshPlayback` | manually refresh the current playback | `r` |
| `ShowActionsOnSelectedItem` | open a popup showing actions on a selected item | `g a`, `C-space` |
| `ShowActionsOnCurrentTrack` | open a popup showing actions on the currently playing track | `a` |
| `FocusNextWindow` | focus the next focusable window (if any) | `tab` |
| `FocusPreviousWindow` | focus the previous focusable window (if any) | `backtab` |
| `SwitchTheme` | open a popup for switching theme | `T` |
| `SwitchDevice` | open a popup for switching device | `D` |
| `Search` | open a popup for searching in the current page | `/` |
| `BrowseUserPlaylists` | open a popup for browsing user's playlists | `u p` |
| `BrowseUserFollowedArtists` | open a popup for browsing user's followed artists | `u a` |
| `BrowseUserSavedAlbums` | open a popup for browsing user's saved albums | `u A` |
| `BrowsePlayingContext` | browse the current playing context | `g space` |
| `LibraryPage` | go the user library page | `g l` |
| `SearchPage` | go to the search page | `g s` |
| `PreviousPage` | go to the previous page | `backspace`, `C-p` |
| `SortTrackByTitle` | sort the track table (if any) by track's title | `s t` |
| `SortTrackByArtists` | sort the track table (if any) by track's artists | `s a` |
| `SortTrackByAlbum` | sort the track table (if any) by track's album | `s A` |
| `SortTrackByDuration` | sort the track table (if any) by track's duration | `s d` |
| `SortTrackByAddedDate` | sort the track table (if any) by track's added date | `s D` |
| `ReverseOrder` | reverse the order of the track table (if any) | `s r` |

To add new shortcuts or modify the default shortcuts, please refer to the [keymaps section](https://github.com/aome510/spotify-player/blob/master/doc/config.md#keymaps) in the configuration documentation.

Expand Down
12 changes: 6 additions & 6 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ To define application's component styles, user needs to specify **all** the belo
- `playback_album`
- `playback_metadata`
- `playback_progress_bar`
- `current_active`
- `context_desc`
- `context_tracks_table_header`
- `current_playing`
- `page_desc`
- `table_header`

A field in the component styles is a `Style` struct which has three optional fields: `fg`, `bg` and `modifiers`. `fg` and `bg` can be either a palette's color (string in pascal case) or a custom RGB color using the following format: `fg = { Rgb { r = 0, g = 0, b = 0} }`. `modifiers` can only be either `Italic` or `Bold`.

Expand All @@ -127,9 +127,9 @@ playback_track = { fg = "Cyan", modifiers = ["Bold"] }
playback_album = { fg = "Yellow" }
playback_metadata = { fg = "BrightBlack" }
playback_progress_bar = { fg = "SelectionBackground", bg = "Green", modifiers = ["Italic"] }
current_active = { fg = "Green", modifiers = ["Bold"] }
context_desc = { fg = "Cyan", modifiers = ["Bold"] }
context_tracks_table_header = { fg = "Blue" }
current_playing = { fg = "Green", modifiers = ["Bold"] }
page_desc = { fg = "Cyan", modifiers = ["Bold"] }
table_header = { fg = "Blue" }
```

## Keymaps
Expand Down
6 changes: 3 additions & 3 deletions examples/theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ playback_track = { fg = "Cyan", modifiers = ["Bold"] }
playback_album = { fg = "Yellow" }
playback_metadata = { fg = "BrightBlack" }
playback_progress_bar = { fg = "SelectionBackground", bg = "Green", modifiers = ["Italic"] }
current_active = { fg = "Green", modifiers = ["Bold"] }
context_desc = { fg = "Cyan", modifiers = ["Bold"] }
context_tracks_table_header = { fg = "Blue" }
current_playing = { fg = "Green", modifiers = ["Bold"] }
page_desc = { fg = "Cyan", modifiers = ["Bold"] }
table_header = { fg = "Blue" }

[[themes]]
name = "solarized_dark"
Expand Down
6 changes: 3 additions & 3 deletions scripts/theme_parse
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ playback_track = {{ fg = "Cyan", modifiers = ["Bold"] }}
playback_album = {{ fg = "Yellow" }}
playback_metadata = {{ fg = "BrightBlack" }}
playback_progress_bar = {{ fg = "SelectionBackground", bg = "Green", modifiers = ["Italic"] }}
current_active = {{ fg = "Green", modifiers = ["Bold"] }}
context_desc = {{ fg = "Cyan", modifiers = ["Bold"] }}
context_tracks_table_header = {{ fg = "Blue" }}
current_playing = {{ fg = "Green", modifiers = ["Bold"] }}
page_desc = {{ fg = "Cyan", modifiers = ["Bold"] }}
table_header = {{ fg = "Blue" }}
'''
)
16 changes: 10 additions & 6 deletions spotify_player/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum Command {

SwitchTheme,
SwitchDevice,
SearchContext,
Search,

ShowActionsOnSelectedItem,
ShowActionsOnCurrentTrack,
Expand All @@ -38,6 +38,7 @@ pub enum Command {

BrowsePlayingContext,

LibraryPage,
SearchPage,
PreviousPage,

Expand Down Expand Up @@ -68,8 +69,8 @@ impl Command {
Self::PlayRandom => "play a random track in the current context",
Self::Repeat => "cycle the repeat mode",
Self::Shuffle => "toggle the shuffle mode",
Self::VolumeUp => "increase playback volume",
Self::VolumeDown => "decrease playback volume",
Self::VolumeUp => "increase playback volume by 5%",
Self::VolumeDown => "decrease playback volume by 5%",
Self::Quit => "quit the application",
Self::OpenCommandHelp => "open a command help popup",
Self::ClosePopup => "close a popup",
Expand All @@ -79,17 +80,20 @@ impl Command {
}
Self::ChooseSelected => "choose the selected item and act on it",
Self::RefreshPlayback => "manually refresh the current playback",
Self::ShowActionsOnSelectedItem => "show actions on a selected item",
Self::ShowActionsOnCurrentTrack => "show actions on the currently playing track",
Self::ShowActionsOnSelectedItem => "open a popup showing actions on a selected item",
Self::ShowActionsOnCurrentTrack => {
"open a popup showing actions on the currently playing track"
}
Self::FocusNextWindow => "focus the next focusable window (if any)",
Self::FocusPreviousWindow => "focus the previous focusable window (if any)",
Self::SwitchTheme => "open a popup for switching theme",
Self::SwitchDevice => "open a popup for switching device",
Self::SearchContext => "open a popup for searching the current context",
Self::Search => "open a popup for searching in the current page",
Self::BrowseUserPlaylists => "open a popup for browsing user's playlists",
Self::BrowseUserFollowedArtists => "open a popup for browsing user's followed artists",
Self::BrowseUserSavedAlbums => "open a popup for browsing user's saved albums",
Self::BrowsePlayingContext => "browse the current playing context",
Self::LibraryPage => "go to the user libary page",
Self::SearchPage => "go to the search page",
Self::PreviousPage => "go to the previous page",
Self::SortTrackByTitle => "sort the track table (if any) by track's title",
Expand Down
6 changes: 5 additions & 1 deletion spotify_player/src/config/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Default for KeymapConfig {
},
Keymap {
key_sequence: "/".into(),
command: Command::SearchContext,
command: Command::Search,
},
Keymap {
key_sequence: "C-space".into(),
Expand Down Expand Up @@ -111,6 +111,10 @@ impl Default for KeymapConfig {
key_sequence: "g space".into(),
command: Command::BrowsePlayingContext,
},
Keymap {
key_sequence: "g l".into(),
command: Command::LibraryPage,
},
Keymap {
key_sequence: "g s".into(),
command: Command::SearchPage,
Expand Down
18 changes: 9 additions & 9 deletions spotify_player/src/config/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub struct ComponentStyle {
pub playback_metadata: Style,
pub playback_progress_bar: Style,

pub current_active: Style,
pub current_playing: Style,

pub context_desc: Style,
pub context_tracks_table_header: Style,
pub page_desc: Style,
pub table_header: Style,
}

#[derive(Default, Clone, Debug, Deserialize)]
Expand Down Expand Up @@ -188,9 +188,9 @@ impl Theme {
playback_album,
playback_metadata,
playback_progress_bar,
current_active,
context_desc,
context_tracks_table_header
current_playing,
page_desc,
table_header
);
}

Expand Down Expand Up @@ -447,14 +447,14 @@ impl Default for ComponentStyle {
.bg(StyleColor::Green)
.modifiers(vec![StyleModifier::Italic]),

current_active: Style::default()
current_playing: Style::default()
.fg(StyleColor::Green)
.modifiers(vec![StyleModifier::Bold]),

context_desc: Style::default()
page_desc: Style::default()
.fg(StyleColor::Cyan)
.modifiers(vec![StyleModifier::Bold]),
context_tracks_table_header: Style::default().fg(StyleColor::Blue),
table_header: Style::default().fg(StyleColor::Blue),
}
}
}
7 changes: 7 additions & 0 deletions spotify_player/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ fn handle_key_event(
None => {
// no popup
match ui.current_page() {
PageState::Library => {
drop(ui);
window::handle_key_sequence_for_library_window(&key_sequence, send, state)?
}
PageState::Recommendations(..) => {
drop(ui);
window::handle_key_sequence_for_recommendation_window(
Expand Down Expand Up @@ -241,6 +245,9 @@ fn handle_global_command(
send.send(ClientRequest::GetUserSavedAlbums)?;
ui.popup = Some(PopupState::UserSavedAlbumList(new_list_state()));
}
Command::LibraryPage => {
ui.create_new_page(PageState::Library);
}
Command::SearchPage => {
ui.create_new_page(PageState::Searching {
input: "".to_owned(),
Expand Down
6 changes: 5 additions & 1 deletion spotify_player/src/event/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ fn handle_key_sequence_for_search_popup(
Ok(true)
}
_ => match ui.current_page() {
PageState::Library => {
drop(ui);
window::handle_key_sequence_for_library_window(key_sequence, send, state)
}
PageState::Recommendations(..) => {
drop(ui);
window::handle_key_sequence_for_recommendation_window(key_sequence, send, state)
Expand All @@ -255,7 +259,7 @@ fn handle_key_sequence_for_search_popup(
drop(ui);
window::handle_key_sequence_for_context_window(key_sequence, send, state)
}
_ => Ok(false),
PageState::Searching { .. } => Ok(false),
},
},
None => Ok(false),
Expand Down
Loading