add configuration of maximum history size (#563)

This commit is contained in:
Darren Schroeder 2021-12-23 13:59:00 -06:00 committed by GitHub
parent 5c83f4d405
commit ba1ff4cf6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -52,6 +52,7 @@ pub struct Config {
pub use_ansi_coloring: bool,
pub env_conversions: HashMap<String, EnvConversion>,
pub edit_mode: String,
pub max_history_size: i64,
}
impl Default for Config {
@ -69,6 +70,7 @@ impl Default for Config {
use_ansi_coloring: true,
env_conversions: HashMap::new(), // TODO: Add default conversoins
edit_mode: "emacs".into(),
max_history_size: 1000,
}
}
}
@ -181,6 +183,9 @@ impl Value {
"edit_mode" => {
config.edit_mode = value.as_string()?;
}
"max_history_size" => {
config.max_history_size = value.as_i64()?;
}
_ => {}
}
}

View File

@ -364,7 +364,10 @@ fn main() -> Result<()> {
),
))
.with_history(Box::new(
FileBackedHistory::with_file(1000, history_path.clone())
FileBackedHistory::with_file(
config.max_history_size as usize,
history_path.clone(),
)
.into_diagnostic()?,
))
.into_diagnostic()?