Skip to content

Commit

Permalink
Command: Add GotoStart and GotoEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoRiether committed Feb 10, 2024
1 parent 50a540d commit 1859087
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ keybindings:
j: SelectNext
k: SelectPrev
l: SelectRight
left: SelectLeft
down: SelectNext
up: SelectPrev
right: SelectRight
a: Add
u: QueueSong
C-q: QueueShown
p: PlayFromModal
E: OpenInEditor
'!': OpenHotkeyModal
C-f: Search
g: GotoStart
G: GotoEnd
```
You can override shortcuts in your config file, or remove some by binding them to `Nop` like so:
Expand Down
8 changes: 8 additions & 0 deletions tori/src/app/filtered_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ impl<St: Selectable> FilteredList<St> {
});
}

pub fn select_first(&mut self) {
self.state.select(self.items.first().copied());
}

pub fn select_last(&mut self) {
self.state.select(self.items.last().copied());
}

pub fn select(&mut self, i: Option<usize>) {
self.state.select(i);
}
Expand Down
6 changes: 4 additions & 2 deletions tori/src/default_config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
playlists_dir: this is a placeholder value, src/config.rs overrides it
visualizer_gradient:
- [46, 20, 66]
- [16, 30, 71]
- "#2e1442"
- "#101e47"
keybindings:
'?': OpenHelpModal
C-c: Quit
Expand Down Expand Up @@ -43,3 +43,5 @@ keybindings:
E: OpenInEditor
'!': OpenHotkeyModal
C-f: Search
g: GotoStart
G: GotoEnd
6 changes: 6 additions & 0 deletions tori/src/events/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ pub enum Command {
/// Filter/search the selected pane (playlists or songs).
/// The same as pressing '/'
Search,

/// Jump to the first item of the selected pane
GotoStart,

/// Jump to the last item of the selected pane
GotoEnd,
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion tori/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn songs_pane(
.borders(Borders::ALL)
.highlight_style(Style::default().bg(Color::Yellow).fg(Color::Black))
.highlight_symbol(" ◇")
.click_event(|i| Action::SelectSong(i));
.click_event(Action::SelectSong);
list.render(area, buf, l);
screen.shown_songs.state = list.get_state();
}
19 changes: 18 additions & 1 deletion tori/src/update/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
config::Config,
error::Result,
events::{channel::Tx, Action, Command},
player::Player,
state::{browse_screen::Focus, Screen, State}, config::Config,
state::{browse_screen::Focus, Screen, State},
};
use crossterm::event::{Event as TermEvent, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};

Expand Down Expand Up @@ -156,7 +157,23 @@ fn handle_command(state: &mut State<'_>, _tx: Tx, cmd: Command) -> Result<Option
PlayFromModal => todo!(),
OpenInEditor => todo!(),
Search => todo!(),

GotoStart => match &mut state.screen {
Screen::BrowseScreen(screen) => match &screen.focus {
Focus::Playlists => screen.shown_playlists.select_first(),
Focus::Songs => screen.shown_songs.select_first(),
Focus::PlaylistsFilter(_) | Focus::SongsFilter(_) => {}
},
},
GotoEnd => match &mut state.screen {
Screen::BrowseScreen(screen) => match &screen.focus {
Focus::Playlists => screen.shown_playlists.select_last(),
Focus::Songs => screen.shown_songs.select_last(),
Focus::PlaylistsFilter(_) | Focus::SongsFilter(_) => {}
},
},
}

Ok(None)
}

Expand Down

0 comments on commit 1859087

Please sign in to comment.