From 831dd783ed41b3922ac3be8e4a849ce99c5ca272 Mon Sep 17 00:00:00 2001 From: "Helmut K. C. Tessarek" Date: Wed, 1 May 2024 05:51:22 -0400 Subject: refactor: preview_auto to use enum and different option (#1991) * refactor: preview_auto to use enum and different option * fix: typo --- crates/atuin-client/src/settings.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'crates/atuin-client/src') 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 @@ -337,6 +337,31 @@ pub struct Keys { pub scroll_exits: bool, } +#[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, @@ -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, @@ -398,6 +422,9 @@ pub struct Settings { #[serde(default)] pub keys: Keys, + #[serde(default)] + pub preview: Preview, + #[serde(default)] pub dotfiles: dotfiles::Settings, @@ -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)? -- cgit v1.3.1