Lift line editor construction out of loop (#5041)

Enables the use of some features on reedline

- Keeping the line when clearing the screen with `Ctrl-L`
- Using the internal cut buffer between lines
- Submitting external commands via keybinding and keeping the line

Additional effect:

Keep the history around and do basic syncs (performance improvement
minimal as session changes have to be read and written)

Additional change:

Give the option to defer writing/rereading the history file to the
closing of the session ($config.sync_history_on_enter)
This commit is contained in:
Stefan Holderbach
2022-03-31 23:25:48 +02:00
committed by GitHub
parent 6a6471b04b
commit 0986c61a5d
4 changed files with 63 additions and 41 deletions

View File

@ -29,6 +29,7 @@ pub struct Config {
pub partial_completions: bool,
pub edit_mode: String,
pub max_history_size: i64,
pub sync_history_on_enter: bool,
pub log_level: String,
pub menu_config: HashMap<String, Value>,
pub keybindings: Vec<ParsedKeybinding>,
@ -54,6 +55,7 @@ impl Default for Config {
partial_completions: true,
edit_mode: "emacs".into(),
max_history_size: 1000,
sync_history_on_enter: true,
log_level: String::new(),
menu_config: HashMap::new(),
history_config: HashMap::new(),
@ -199,6 +201,13 @@ impl Value {
eprintln!("$config.max_history_size is not an integer")
}
}
"sync_history_on_enter" => {
if let Ok(b) = value.as_bool() {
config.sync_history_on_enter = b;
} else {
eprintln!("$config.sync_history_on_enter is not a bool")
}
}
"log_level" => {
if let Ok(v) = value.as_string() {
config.log_level = v.to_lowercase();