Skip to content

Commit 45aed26

Browse files
committed
Add edit mode option
Adds a config option `edit-mode` to control the rustyline edit mode. Supports `"emacs"`, and `"vi"`. Defaults to `"emacs"`. Fixes #365.
1 parent 7e17ca0 commit 45aed26

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

book/src/cli-customization.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ prompt = ">>> "
5959
# only in interactive mode.
6060
pretty-print = "auto"
6161

62+
# Controls the edit mode. Can be "emacs", or "vi".
63+
edit-mode = "emacs"
64+
6265
[exchange-rates]
6366
# When and if to load exchange rates from the European Central Bank for
6467
# currency conversions. Can be "on-startup" to always fetch exchange rates

numbat-cli/src/config.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ pub enum ColorMode {
4949
Auto,
5050
}
5151

52+
#[derive(Serialize, Deserialize, PartialEq, Eq, Default, Debug, Clone, Copy, ValueEnum)]
53+
#[serde(rename_all = "kebab-case")]
54+
pub enum EditMode {
55+
#[default]
56+
Emacs,
57+
Vi,
58+
}
59+
5260
#[derive(Serialize, Deserialize)]
5361
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
5462
pub struct Config {
5563
pub intro_banner: IntroBanner,
5664
pub prompt: CompactString,
5765
pub pretty_print: PrettyPrintMode,
5866
pub color: ColorMode,
67+
pub edit_mode: EditMode,
5968

6069
#[serde(skip)]
6170
pub enter_repl: bool,
@@ -75,6 +84,7 @@ impl Default for Config {
7584
intro_banner: IntroBanner::default(),
7685
pretty_print: PrettyPrintMode::Auto,
7786
color: ColorMode::default(),
87+
edit_mode: EditMode::default(),
7888
load_prelude: true,
7989
load_user_init: true,
8090
exchange_rates: Default::default(),

numbat-cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod highlighter;
66
use ansi_formatter::ansi_format;
77
use colored::control::SHOULD_COLORIZE;
88
use completer::NumbatCompleter;
9-
use config::{ColorMode, Config, ExchangeRateFetchingPolicy, IntroBanner, PrettyPrintMode};
9+
use config::{ColorMode, Config, EditMode, ExchangeRateFetchingPolicy, IntroBanner, PrettyPrintMode};
1010
use highlighter::NumbatHighlighter;
1111

1212
use itertools::Itertools;
@@ -299,6 +299,10 @@ impl Cli {
299299
let history_path = self.get_history_path()?;
300300

301301
let mut rl = Editor::<NumbatHelper, DefaultHistory>::new()?;
302+
rl.set_edit_mode(match self.config.edit_mode {
303+
EditMode::Emacs => rustyline::EditMode::Emacs,
304+
EditMode::Vi => rustyline::EditMode::Vi,
305+
});
302306
rl.set_max_history_size(1000)
303307
.context("Error while configuring history size")?;
304308
rl.set_completion_type(rustyline::CompletionType::List);

0 commit comments

Comments
 (0)