summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMat Jones <mat@mjones.network>2022-06-04 10:41:24 +0000
committerGitHub <noreply@github.com>2022-06-04 12:41:24 +0200
commit146976351ec804ab1594d5262a1e0dd2d2de4972 (patch)
tree68e0bd744b2cb4954ba372436d4d09bfd0108cf8 /src
parent1e2bc8477ebde8c77ddd066421978eee030454c9 (diff)
fix(fish): add proper vi mode detection for fish shell (#3839)
* add proper vi mode detection for fish shell * update tests * fix test * update config-schema.json * update docs * add warning about symbols only supported in fish
Diffstat (limited to 'src')
-rw-r--r--src/configs/character.rs6
-rw-r--r--src/modules/character.rs37
2 files changed, 41 insertions, 2 deletions
diff --git a/src/configs/character.rs b/src/configs/character.rs
index 91cef60c4..eb28f9cd1 100644
--- a/src/configs/character.rs
+++ b/src/configs/character.rs
@@ -8,6 +8,9 @@ pub struct CharacterConfig<'a> {
pub success_symbol: &'a str,
pub error_symbol: &'a str,
pub vicmd_symbol: &'a str,
+ pub vimcmd_visual_symbol: &'a str,
+ pub vimcmd_replace_symbol: &'a str,
+ pub vimcmd_replace_one_symbol: &'a str,
pub disabled: bool,
}
@@ -18,6 +21,9 @@ impl<'a> Default for CharacterConfig<'a> {
success_symbol: "[❯](bold green)",
error_symbol: "[❯](bold red)",
vicmd_symbol: "[❮](bold green)",
+ vimcmd_visual_symbol: "[❮](bold yellow)",
+ vimcmd_replace_symbol: "[❮](bold purple)",
+ vimcmd_replace_one_symbol: "[❮](bold purple)",
disabled: false,
}
}
diff --git a/src/modules/character.rs b/src/modules/character.rs
index e7b65e2ee..39c78b159 100644
--- a/src/modules/character.rs
+++ b/src/modules/character.rs
@@ -4,7 +4,7 @@ use crate::formatter::StringFormatter;
/// Creates a module for the prompt character
///
-/// The character segment prints an arrow character in a color dependant on the
+/// The character segment prints an arrow character in a color dependent on the
/// exit-code of the last executed command:
/// - If the exit-code was "0", it will be formatted with `success_symbol`
/// (green arrow by default)
@@ -13,6 +13,9 @@ use crate::formatter::StringFormatter;
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
enum ShellEditMode {
Normal,
+ Visual,
+ Replace,
+ ReplaceOne,
Insert,
}
const ASSUMED_MODE: ShellEditMode = ShellEditMode::Insert;
@@ -35,11 +38,17 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
(Shell::Fish, "default") | (Shell::Zsh, "vicmd") | (Shell::Cmd, "vi") => {
ShellEditMode::Normal
}
+ (Shell::Fish, "visual") => ShellEditMode::Visual,
+ (Shell::Fish, "replace") => ShellEditMode::Replace,
+ (Shell::Fish, "replace_one") => ShellEditMode::ReplaceOne,
_ => ASSUMED_MODE,
};
let symbol = match mode {
ShellEditMode::Normal => config.vicmd_symbol,
+ ShellEditMode::Visual => config.vimcmd_visual_symbol,
+ ShellEditMode::Replace => config.vimcmd_replace_symbol,
+ ShellEditMode::ReplaceOne => config.vimcmd_replace_one_symbol,
ShellEditMode::Insert => {
if exit_success {
config.success_symbol
@@ -168,6 +177,9 @@ mod test {
fn fish_keymap() {
let expected_vicmd = Some(format!("{} ", Color::Green.bold().paint("❮")));
let expected_specified = Some(format!("{} ", Color::Green.bold().paint("V")));
+ let expected_visual = Some(format!("{} ", Color::Yellow.bold().paint("❮")));
+ let expected_replace = Some(format!("{} ", Color::Purple.bold().paint("❮")));
+ let expected_replace_one = expected_replace.clone();
let expected_other = Some(format!("{} ", Color::Green.bold().paint("❯")));
// fish keymap is default
@@ -188,11 +200,32 @@ mod test {
.collect();
assert_eq!(expected_specified, actual);
- // fish keymap is other
+ // fish keymap is visual
let actual = ModuleRenderer::new("character")
.shell(Shell::Fish)
.keymap("visual")
.collect();
+ assert_eq!(expected_visual, actual);
+
+ // fish keymap is replace
+ let actual = ModuleRenderer::new("character")
+ .shell(Shell::Fish)
+ .keymap("replace")
+ .collect();
+ assert_eq!(expected_replace, actual);
+
+ // fish keymap is replace_one
+ let actual = ModuleRenderer::new("character")
+ .shell(Shell::Fish)
+ .keymap("replace_one")
+ .collect();
+ assert_eq!(expected_replace_one, actual);
+
+ // fish keymap is other
+ let actual = ModuleRenderer::new("character")
+ .shell(Shell::Fish)
+ .keymap("other")
+ .collect();
assert_eq!(expected_other, actual);
}