Move prompt animation setting to config (#400)

This commit is contained in:
JT 2021-12-02 20:10:40 +13:00 committed by GitHub
parent ac2afab40b
commit 071066b6d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -2,6 +2,8 @@ use crate::{ShellError, Value};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
const ANIMATE_PROMPT_DEFAULT: bool = true;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config {
pub filesize_metric: bool,
@ -10,6 +12,7 @@ pub struct Config {
pub color_config: HashMap<String, String>,
pub use_grid_icons: bool,
pub footer_mode: FooterMode,
pub animate_prompt: bool,
}
impl Default for Config {
@ -21,6 +24,7 @@ impl Default for Config {
color_config: HashMap::new(),
use_grid_icons: false,
footer_mode: FooterMode::Never,
animate_prompt: ANIMATE_PROMPT_DEFAULT,
}
}
}
@ -77,6 +81,11 @@ impl Value {
},
};
}
"animate_prompt" => {
let val = value.as_bool()?;
config.animate_prompt = val;
}
_ => {}
}
}

View File

@ -230,20 +230,11 @@ fn main() -> Result<()> {
}
loop {
let config = stack.get_config()?;
//Reset the ctrl-c handler
ctrlc.store(false, Ordering::SeqCst);
const EQ_PROMPT_ANIMATE_DEFAULT: bool = true;
// Toggle prompt animation
let animate = match std::env::var("EQ_PROMPT_ANIMATE") {
Ok(ms_str) => match ms_str.as_str() {
"ON" | "1" => true,
"OFF" | "0" => false,
_ => EQ_PROMPT_ANIMATE_DEFAULT,
},
_ => EQ_PROMPT_ANIMATE_DEFAULT,
};
let line_editor = Reedline::create()
.into_diagnostic()?
.with_completion_action_handler(Box::new(FuzzyCompletion {
@ -252,7 +243,7 @@ fn main() -> Result<()> {
.with_highlighter(Box::new(NuHighlighter {
engine_state: engine_state.clone(),
}))
.with_animation(animate)
.with_animation(config.animate_prompt)
// .with_completion_action_handler(Box::new(
// ListCompletionHandler::default().with_completer(Box::new(completer)),
// ))