Skip to content

Commit

Permalink
feat: change tabs with h, l and arrow keys (#12)
Browse files Browse the repository at this point in the history
* chore: Release

* feat: switch tabs with "l", "r", right arrow and left arrow

* feat: add keys to global keys popup
  • Loading branch information
aidanaden authored Jun 20, 2024
1 parent 7f44ef2 commit cc066f2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rm-main/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustmission"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
description = "TUI for Transmission daemon"
repository = "https://github.com/intuis/rustmission"
Expand Down
4 changes: 4 additions & 0 deletions rm-main/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub(crate) enum Action {
Render,
Up,
Down,
Left,
Right,
ScrollDownPage,
ScrollUpPage,
Home,
Expand Down Expand Up @@ -95,6 +97,8 @@ fn keycode_to_action(key: KeyCode) -> Option<Action> {
KeyCode::PageDown => Some(A::ScrollDownPage),
KeyCode::Char('j') | KeyCode::Down => Some(A::Down),
KeyCode::Char('k') | KeyCode::Up => Some(A::Up),
KeyCode::Char('h') | KeyCode::Left => Some(A::Left),
KeyCode::Char('l') | KeyCode::Right => Some(A::Right),
KeyCode::Char('?') | KeyCode::F(1) => Some(A::ShowHelp),
KeyCode::Char('s') => Some(A::ShowStats),
KeyCode::Char('f') => Some(A::ShowFiles),
Expand Down
17 changes: 14 additions & 3 deletions rm-main/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,23 @@ impl Component for TabComponent {
}

fn handle_actions(&mut self, action: Action) -> Option<Action> {
if let Action::ChangeTab(tab) = action {
match tab {
match action {
Action::ChangeTab(tab) => match tab {
1 => self.current_tab = CurrentTab::Torrents,
2 => self.current_tab = CurrentTab::Search,
_ => (),
}
},
// left only works on right-most tab (search)
Action::Left => match self.current_tab {
CurrentTab::Search => self.current_tab = CurrentTab::Torrents,
_ => (),
},
// right only works on left-most tab (torrents)
Action::Right => match self.current_tab {
CurrentTab::Torrents => self.current_tab = CurrentTab::Search,
_ => (),
},
_ => (),
}
None
}
Expand Down
6 changes: 4 additions & 2 deletions rm-main/src/ui/global_popups/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ impl Component for HelpPopup {
add_line!(lines, "ESC", "close a popup / task");
add_line!(lines, "1", "switch to torrents tab");
add_line!(lines, "2", "switch to search tab");
add_line!(lines, "h / ←", "switch to tab left of current tab");
add_line!(lines, "l / →", "switch to tab right of current tab");
add_line!(lines, "j / ↓", "move down");
add_line!(lines, "k / ↑", "move up");
add_line!(lines, "/", "search or filter");
add_line!(lines, "TAB", "switch focus");
add_line!(lines, "Enter", "confirm");
add_line!(lines, "CTRL-d", "scroll page down");
add_line!(lines, "CTRL-u", "scroll page up");
add_line!(lines, "Home", "scroll to the beginning");
add_line!(lines, "End", "scroll to the end");
add_line!(lines, "j / ↓", "move down");
add_line!(lines, "k / ↑", "move up");

lines.push(
Line::from(vec![Span::styled(
Expand Down
2 changes: 1 addition & 1 deletion rm-main/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Component for MainWindow {
_ if self.global_popup_manager.needs_action() => {
self.global_popup_manager.handle_actions(action)
}
A::ChangeTab(_) => {
A::ChangeTab(_) | A::Left | A::Right => {
self.tabs.handle_actions(action);
Some(A::Render)
}
Expand Down

0 comments on commit cc066f2

Please sign in to comment.