Skip to content

Commit

Permalink
feat(client): add config option keys.scroll_exits (#1744)
Browse files Browse the repository at this point in the history
* feat(client): add config option keys.scroll_exits

If the config option is set the `false`, using the up/down key won't
exit the TUI when scrolled past the first/last entry.

Example:

```
[keys]
scroll_exits = false
```

The default is `true`, which is the current behavior.

* Update atuin/src/command/client/search/interactive.rs

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>

* refactor: add option to config.toml

---------

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
  • Loading branch information
tessus and akinomyoga committed Feb 21, 2024
1 parent 3d82ada commit 56b971a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions atuin-client/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,7 @@ enter_accept = true

## Set commands that will be completely ignored from stats
#ignored_commands = ["cd", "ls", "vi"]

[keys]
# Defaults to true. If disabled, using the up/down key won't exit the TUI when scrolled past the first/last entry.
# scroll_exits = false
9 changes: 9 additions & 0 deletions atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ pub struct Sync {
pub records: bool,
}

#[derive(Clone, Debug, Deserialize, Default)]
pub struct Keys {
pub scroll_exits: bool,
}

#[derive(Clone, Debug, Deserialize)]
pub struct Settings {
pub dialect: Dialect,
Expand Down Expand Up @@ -360,6 +365,9 @@ pub struct Settings {
#[serde(default)]
pub sync: Sync,

#[serde(default)]
pub keys: Keys,

// This is automatically loaded when settings is created. Do not set in
// config! Keep secrets and settings apart.
#[serde(skip)]
Expand Down Expand Up @@ -588,6 +596,7 @@ impl Settings {
// New users will get the new default, that is more similar to what they are used to.
.set_default("enter_accept", false)?
.set_default("sync.records", false)?
.set_default("keys.scroll_exits", true)?
.set_default("keymap_mode", "emacs")?
.set_default("keymap_mode_shell", "auto")?
.set_default("keymap_cursor", HashMap::<String, String>::new())?
Expand Down
2 changes: 1 addition & 1 deletion atuin/src/command/client/search/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl State {
is_down: bool,
) -> InputAction {
if is_down {
if enable_exit && self.results_state.selected() == 0 {
if settings.keys.scroll_exits && enable_exit && self.results_state.selected() == 0 {
return Self::handle_key_exit(settings);
}
self.scroll_down(1);
Expand Down

0 comments on commit 56b971a

Please sign in to comment.