mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 16:33:37 +01:00
vi mode (#561)
This commit is contained in:
parent
c33104c4ae
commit
f3c175562d
@ -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()?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
13
src/main.rs
13
src/main.rs
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user