This commit is contained in:
Fernando Herrera 2021-12-23 09:31:16 +00:00 committed by GitHub
parent c33104c4ae
commit f3c175562d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -51,6 +51,7 @@ pub struct Config {
pub filesize_format: String,
pub use_ansi_coloring: bool,
pub env_conversions: HashMap<String, EnvConversion>,
pub edit_mode: String,
}
impl Default for Config {
@ -67,6 +68,7 @@ impl Default for Config {
filesize_format: "auto".into(),
use_ansi_coloring: true,
env_conversions: HashMap::new(), // TODO: Add default conversoins
edit_mode: "emacs".into(),
}
}
}
@ -176,6 +178,9 @@ impl Value {
config.env_conversions = env_conversions;
}
"edit_mode" => {
config.edit_mode = value.as_string()?;
}
_ => {}
}
}

View File

@ -16,7 +16,7 @@ use nu_protocol::{
Config, PipelineData, ShellError, Span, Value, CONFIG_VARIABLE_ID,
};
use reedline::{
Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt,
Completer, CompletionActionHandler, DefaultHinter, DefaultPrompt, LineBuffer, Prompt, Vi,
};
use std::{
io::Write,
@ -354,7 +354,7 @@ fn main() -> Result<()> {
//FIXME: if config.use_ansi_coloring is false then we should
// turn off the hinter but I don't see any way to do that yet.
let mut line_editor = if let Some(history_path) = history_path.clone() {
let line_editor = if let Some(history_path) = history_path.clone() {
let history = std::fs::read_to_string(&history_path);
if history.is_ok() {
line_editor
@ -375,6 +375,15 @@ fn main() -> Result<()> {
line_editor
};
// The line editor default mode is emacs mode. For the moment we only
// need to check for vi mode
let mut line_editor = if config.edit_mode == "vi" {
let edit_mode = Box::new(Vi::default());
line_editor.with_edit_mode(edit_mode)
} else {
line_editor
};
let prompt = update_prompt(
PROMPT_COMMAND,
&engine_state,