summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config/mod.rs29
-rw-r--r--src/repl/init.rs2
2 files changed, 26 insertions, 5 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 47fbece..8e5157f 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -58,8 +58,8 @@ pub struct Config {
pub light_theme: bool,
/// Automatically copy the last output to the clipboard
pub auto_copy: bool,
- /// Use vi keybindings, overriding the default Emacs keybindings
- pub vi_keybindings: bool,
+ /// REPL keybindings, possible values: emacs (default), vi
+ pub keybindings: Keybindings,
/// Setup LLM platforms
pub clients: Vec<ClientConfig>,
/// Predefined roles
@@ -86,7 +86,7 @@ impl Default for Config {
conversation_first: false,
light_theme: false,
auto_copy: false,
- vi_keybindings: false,
+ keybindings: Default::default(),
roles: vec![],
clients: vec![ClientConfig::OpenAI(OpenAIConfig::default())],
role: None,
@@ -321,7 +321,7 @@ impl Config {
("conversation_first", self.conversation_first.to_string()),
("light_theme", self.light_theme.to_string()),
("dry_run", self.dry_run.to_string()),
- ("vi_keybindings", self.vi_keybindings.to_string()),
+ ("keybindings", self.keybindings.stringify().into()),
];
let mut output = String::new();
for (name, value) in items {
@@ -497,6 +497,27 @@ impl Config {
}
}
+#[derive(Debug, Clone, Deserialize, Default)]
+pub enum Keybindings {
+ #[serde(rename = "emacs")]
+ #[default]
+ Emacs,
+ #[serde(rename = "vi")]
+ Vi,
+}
+
+impl Keybindings {
+ pub fn is_vi(&self) -> bool {
+ matches!(self, Keybindings::Vi)
+ }
+ pub fn stringify(&self) -> &str {
+ match self {
+ Keybindings::Emacs => "emacs",
+ Keybindings::Vi => "vi",
+ }
+ }
+}
+
fn create_config_file(config_path: &Path) -> Result<()> {
let ans = Confirm::new("No config file, create a new one?")
.with_default(true)
diff --git a/src/repl/init.rs b/src/repl/init.rs
index 9cef4e5..60fce00 100644
--- a/src/repl/init.rs
+++ b/src/repl/init.rs
@@ -29,7 +29,7 @@ impl Repl {
let highlighter = ReplHighlighter::new(config.clone(), commands);
let history = Self::create_history()?;
let menu = Self::create_menu();
- let edit_mode: Box<dyn EditMode> = if config.read().vi_keybindings {
+ let edit_mode: Box<dyn EditMode> = if config.read().keybindings.is_vi() {
let mut normal_keybindings = default_vi_normal_keybindings();
let mut insert_keybindings = default_vi_insert_keybindings();
Self::extra_keybindings(&mut normal_keybindings);