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

change default keybindings #116

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .config/rainfrog_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ mouse_mode = true
"q" = "AbortQuery"
"<Alt-1>" = "FocusMenu"
"<Alt-2>" = "FocusEditor"
"<Alt-3>" = "FocusHistory"
"<Alt-4>" = "FocusData"
"<Alt-3>" = "FocusData"
"<Alt-4>" = "FocusHistory"
"<Ctrl-k>" = "FocusMenu"
"<Ctrl-j>" = "FocusEditor"
"<Ctrl-h>" = "FocusHistory"
"<Ctrl-g>" = "FocusData"
"<Ctrl-h>" = "FocusData"
"<Ctrl-g>" = "FocusHistory"
"<Tab>" = "CycleFocusForwards"
"<Backtab>" = "CycleFocusBackwards"

Expand All @@ -20,25 +20,25 @@ mouse_mode = true
"<F5>" = "SubmitEditorQuery"
"<Alt-1>" = "FocusMenu"
"<Alt-2>" = "FocusEditor"
"<Alt-3>" = "FocusHistory"
"<Alt-4>" = "FocusData"
"<Alt-3>" = "FocusData"
"<Alt-4>" = "FocusHistory"
"<Ctrl-k>" = "FocusMenu"
"<Ctrl-j>" = "FocusEditor"
"<Ctrl-h>" = "FocusHistory"
"<Ctrl-g>" = "FocusData"
"<Ctrl-h>" = "FocusData"
"<Ctrl-g>" = "FocusHistory"
"<Backtab>" = "CycleFocusBackwards"

[keybindings.History]
"<Ctrl-c>" = "Quit"
"q" = "AbortQuery"
"<Alt-1>" = "FocusMenu"
"<Alt-2>" = "FocusEditor"
"<Alt-3>" = "FocusHistory"
"<Alt-4>" = "FocusData"
"<Alt-3>" = "FocusData"
"<Alt-4>" = "FocusHistory"
"<Ctrl-k>" = "FocusMenu"
"<Ctrl-j>" = "FocusEditor"
"<Ctrl-h>" = "FocusHistory"
"<Ctrl-g>" = "FocusData"
"<Ctrl-h>" = "FocusData"
"<Ctrl-g>" = "FocusHistory"
"<Tab>" = "CycleFocusForwards"
"<Backtab>" = "CycleFocusBackwards"

Expand All @@ -47,12 +47,12 @@ mouse_mode = true
"q" = "AbortQuery"
"<Alt-1>" = "FocusMenu"
"<Alt-2>" = "FocusEditor"
"<Alt-3>" = "FocusHistory"
"<Alt-4>" = "FocusData"
"<Alt-3>" = "FocusData"
"<Alt-4>" = "FocusHistory"
"<Ctrl-k>" = "FocusMenu"
"<Ctrl-j>" = "FocusEditor"
"<Ctrl-h>" = "FocusHistory"
"<Ctrl-g>" = "FocusData"
"<Ctrl-h>" = "FocusData"
"<Ctrl-g>" = "FocusHistory"
"<Tab>" = "CycleFocusForwards"
"<Backtab>" = "CycleFocusBackwards"

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ cargo install rainfrog --features termux --no-default-features
```

### nix

```sh
nix-env -iA nixos.rainfrog
```
Expand Down Expand Up @@ -220,8 +221,8 @@ are the default keybindings.
| `Ctrl+c` | quit program |
| `Alt+1`, `Ctrl+k` | change focus to menu |
| `Alt+2`, `Ctrl+j` | change focus to query editor |
| `Alt+3`, `Ctrl+h` | change focus to query history |
| `Alt+4`, `Ctrl+g` | change focus to results |
| `Alt+3`, `Ctrl+h` | change focus to results |
| `Alt+4`, `Ctrl+g` | change focus to query history |
| `Tab` | cycle focus forwards |
| `Shift+Tab` | cycle focus backwards |
| `q`, `Alt+q` in query editor | abort current query |
Expand Down Expand Up @@ -380,7 +381,7 @@ features
not currently support mouse events, and menu items cannot be selected using
the mouse

you can find other reported issues in the
you can find other reported issues in the
[issues tab](https://github.com/achristmascarl/rainfrog/issues)

## Contributing
Expand Down
18 changes: 11 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ where
self.state.focus = Focus::Editor;
self.last_focused_tab = Focus::Editor;
},
Action::FocusData => self.state.focus = Focus::Data,
Action::FocusHistory => {
self.state.focus = Focus::History;
self.last_focused_tab = Focus::History;
Expand All @@ -321,30 +322,33 @@ where
self.last_focused_tab = Focus::Editor;
},
Focus::Editor => {
self.state.focus = Focus::Data;
},
Focus::Data => {
self.state.focus = Focus::History;
self.last_focused_tab = Focus::History;
},
Focus::History => self.state.focus = Focus::Data,
Focus::Data => self.state.focus = Focus::Menu,
Focus::History => self.state.focus = Focus::Menu,
_ => {},
}
},
Action::CycleFocusBackwards => {
match self.state.focus {
Focus::History => {
self.state.focus = Focus::Data;
},
Focus::Data => {
self.state.focus = Focus::Editor;
self.last_focused_tab = Focus::Editor;
},
Focus::Data => {
Focus::Editor => self.state.focus = Focus::Menu,
Focus::Menu => {
self.state.focus = Focus::History;
self.last_focused_tab = Focus::History;
},
Focus::Menu => self.state.focus = Focus::Data,
Focus::Editor => self.state.focus = Focus::Menu,
_ => {},
}
},
Action::FocusData => self.state.focus = Focus::Data,
Action::LoadMenu => {
log::info!("LoadMenu");
if let Some(pool) = &self.pool {
Expand Down Expand Up @@ -552,7 +556,7 @@ where
}
}

let tabs = Tabs::new(vec![" 󰤏 query <alt+2>", "  history <alt+3>"])
let tabs = Tabs::new(vec![" 󰤏 query <alt+2>", "  history <alt+4>"])
.highlight_style(
Style::new()
.fg(if self.state.focus == Focus::Editor || self.state.focus == Focus::History {
Expand Down
19 changes: 10 additions & 9 deletions src/components/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ impl<'a, DB: Database> Component<DB> for Data<'a> {
} else if let DataState::Explain(text) = &self.data_state {
self.command_tx.clone().unwrap().send(Action::CopyData(text.to_string()))?;
self.scrollable.transition_selection_mode(Some(SelectionMode::Copied));
} else if let DataState::Error(err) = &self.data_state {
self.command_tx.clone().unwrap().send(Action::CopyData(err.to_string()))?;
self.scrollable.transition_selection_mode(Some(SelectionMode::Copied));
}
},
Input { key: Key::Esc, .. } => {
Expand Down Expand Up @@ -405,25 +408,23 @@ impl<'a, DB: Database> Component<DB> for Data<'a> {
let row = &rows[y];
let title_string = match self.scrollable.get_selection_mode() {
Some(SelectionMode::Row) => {
format!(" 󰆼 results <alt+4> (row {} of {})", y.saturating_add(1), rows.len())
format!(" 󰆼 results <alt+3> (row {} of {})", y.saturating_add(1), rows.len())
},
Some(SelectionMode::Cell) => {
format!(" 󰆼 results <alt+4> (row {} of {}) - {} ", y.saturating_add(1), rows.len(), row[x as usize].clone())
format!(" 󰆼 results <alt+3> (row {} of {}) - {} ", y.saturating_add(1), rows.len(), row[x as usize].clone())
},
Some(SelectionMode::Copied) => {
format!(" 󰆼 results <alt+4> ({} rows) - copied! ", rows.len())
format!(" 󰆼 results <alt+3> ({} rows) - copied! ", rows.len())
},
_ => format!(" 󰆼 results <alt+4> ({} rows)", rows.len()),
_ => format!(" 󰆼 results <alt+3> ({} rows)", rows.len()),
};
block = block.title(title_string);
} else if let DataState::Explain(_) = &self.data_state {
} else {
let title_string = match self.scrollable.get_selection_mode() {
Some(SelectionMode::Copied) => " 󰆼 results <alt+4> - copied! ",
_ => " 󰆼 results <alt+4>",
Some(SelectionMode::Copied) => " 󰆼 results <alt+3> - copied! ",
_ => " 󰆼 results <alt+3>",
};
block = block.title(title_string);
} else {
block = block.title(" 󰆼 results <alt+4>");
}

match &self.data_state {
Expand Down
4 changes: 2 additions & 2 deletions vhs/demo.tape
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Type "jjj"
Sleep 500ms
Enter
Sleep 1s
Ctrl+G
Ctrl+H
Sleep 2s
Type "v"
Sleep 2s
Expand Down Expand Up @@ -78,7 +78,7 @@ Alt+Enter
Sleep 2.5s
Type "N"
Sleep 1s
Ctrl+H
Ctrl+G
Sleep 2s
Type "jjj"
Sleep 1s
Expand Down