Repository: atuinsh/atuin (language: rust)

Issue:
Feature request: Make exit-on-down-arrow behavior optional
If I scroll to the bottom of the results list and press down, Atuin closes (as implemented in #659). This would make perfect sense if I was using the up-arrow binding to seed the search with what I already typed at the prompt, but I disabled Atuin's up-arrow binding in favor of the one built into my shell.

In my case, I've pressed CTRL+R and typed a search, then scrolled up and down in the list and accidentally exited Atuin and lost my search.

Could this behavior be made optional, or maybe not trigger based on what method was used to activate Atuin?


Discussion / hints:
Seeing this as well, it's frustrating having to continually close/re-open shells to work around it.

OS: 

```
$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=21.04
DISTRIB_CODENAME=hirsute
DISTRIB_DESCRIPTION="Ubuntu 21.04"
```

Terminal:

```
$ gnome-terminal --version
# GNOME Terminal 3.38.1 using VTE 0.62.3 +BIDI +GNUTLS +ICU +SYSTEMD
```

Bash:

```
$ bash --version
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
```

Config: using stock configuration

Fix patch:
diff --git a/atuin-client/config.toml b/atuin-client/config.toml
index 97c62881fd6..1475b359c29 100644
--- a/atuin-client/config.toml
+++ b/atuin-client/config.toml
@@ -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
diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs
index 763fde1b00a..ad2e45ecd61 100644
--- a/atuin-client/src/settings.rs
+++ b/atuin-client/src/settings.rs
@@ -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,
@@ -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)]
@@ -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())?
diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs
index 1c71a5b6b4b..1f3a2cff3e9 100644
--- a/atuin/src/command/client/search/interactive.rs
+++ b/atuin/src/command/client/search/interactive.rs
@@ -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);


Test patch: