diff options
| author | Helmut K. C. Tessarek <tessarek@evermeet.cx> | 2024-05-01 05:51:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-01 10:51:22 +0100 |
| commit | 831dd783ed41b3922ac3be8e4a849ce99c5ca272 (patch) | |
| tree | f4013341c5ba9549d8f341ba07eaa72f7a8363d9 /crates/atuin-client | |
| parent | chore(deps): flake.lock: Update (#1992) (diff) | |
| download | atuin-831dd783ed41b3922ac3be8e4a849ce99c5ca272.zip | |
refactor: preview_auto to use enum and different option (#1991)
* refactor: preview_auto to use enum and different option
* fix: typo
Diffstat (limited to 'crates/atuin-client')
| -rw-r--r-- | crates/atuin-client/config.toml | 14 | ||||
| -rw-r--r-- | crates/atuin-client/src/settings.rs | 32 |
2 files changed, 37 insertions, 9 deletions
diff --git a/crates/atuin-client/config.toml b/crates/atuin-client/config.toml index 415fd441..e9415851 100644 --- a/crates/atuin-client/config.toml +++ b/crates/atuin-client/config.toml @@ -71,12 +71,7 @@ ## enable or disable showing a preview of the selected command ## useful when the command is longer than the terminal width and is cut off -# show_preview = false - -## enable or disable automatic preview. It shows a preview, if the command is -## longer than the width of the terminal. It respects max_preview_height. -## (default: true) -# show_preview_auto = true +# show_preview = true ## what to do when the escape key is pressed when searching ## possible values: return-original, return-query @@ -208,3 +203,10 @@ enter_accept = true # This ensures that sync v2 is enabled for new installs only # In a later release it will become the default across the board records = true + +[preview] +## which preview strategy to use to calculate the preview height (respects max_preview_height). +## possible values: auto, static +## auto: length of the selected command. +## static: length of the longest command stored in the history. +# strategy = auto diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs index 0497fb64..675fb307 100644 --- a/crates/atuin-client/src/settings.rs +++ b/crates/atuin-client/src/settings.rs @@ -338,6 +338,31 @@ pub struct Keys { } #[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Preview { + pub strategy: PreviewStrategy, +} + +impl Default for Preview { + fn default() -> Self { + Self { + strategy: PreviewStrategy::Auto, + } + } +} + +// The preview height strategy also takes max_preview_height into account. +#[derive(Clone, Debug, Deserialize, Copy, PartialEq, Eq, ValueEnum, Serialize)] +pub enum PreviewStrategy { + // Preview height is calculated for the length of the selected command. + #[serde(rename = "auto")] + Auto, + + // Preview height is calculated for the length of the longest command stored in the history. + #[serde(rename = "static")] + Static, +} + +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Settings { pub dialect: Dialect, pub timezone: Timezone, @@ -358,7 +383,6 @@ pub struct Settings { pub inline_height: u16, pub invert: bool, pub show_preview: bool, - pub show_preview_auto: bool, pub max_preview_height: u16, pub show_help: bool, pub show_tabs: bool, @@ -399,6 +423,9 @@ pub struct Settings { pub keys: Keys, #[serde(default)] + pub preview: Preview, + + #[serde(default)] pub dotfiles: dotfiles::Settings, // This is automatically loaded when settings is created. Do not set in @@ -615,8 +642,7 @@ impl Settings { .set_default("filter_mode", "global")? .set_default("style", "auto")? .set_default("inline_height", 0)? - .set_default("show_preview", false)? - .set_default("show_preview_auto", true)? + .set_default("show_preview", true)? .set_default("max_preview_height", 4)? .set_default("show_help", true)? .set_default("show_tabs", true)? |
