Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change config.vi_keybindings to config.keybindings #158

Merged
merged 2 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ highlight: true # Set false to turn highlight
conversation_first: false # If set true, start a conversation immediately upon repl
light_theme: false # If set true, use light theme
auto_copy: false # Automatically copy the last output to the clipboard
vi_keybindings: false # If set ture, switch repl keybindings from emacs to vi
keybindings: emacs # REPL keybindings, possible values: emacs (default), vi

clients: # Setup LLM platforms

Expand Down
29 changes: 25 additions & 4 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/repl/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down