mirror of
https://github.com/starship/starship.git
synced 2025-03-12 22:41:29 +01:00
add keymap support
This commit is contained in:
parent
7585505de1
commit
9741d4d0aa
@ -447,7 +447,7 @@ look at [this example](#with-custom-error-shape).
|
||||
|
||||
::: warning
|
||||
|
||||
`vicmd_symbol` is only supported in fish and zsh.
|
||||
`vicmd_symbol` is only supported in cmd, fish and zsh.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -32,6 +32,7 @@ function custom_prompt:filter(prompt)
|
||||
.." --status="..os.geterrorlevel()
|
||||
.." --cmd-duration="..math.floor(curr_duration*1000)
|
||||
.." --terminal-width="..console.getwidth()
|
||||
.." --keymap="..rl.getvariable('keymap')
|
||||
):read("*a")
|
||||
end
|
||||
|
||||
@ -40,6 +41,7 @@ function custom_prompt:rightfilter(prompt)
|
||||
.." --status="..os.geterrorlevel()
|
||||
.." --cmd-duration="..math.floor(curr_duration*1000)
|
||||
.." --terminal-width="..console.getwidth()
|
||||
.." --keymap="..rl.getvariable('keymap')
|
||||
):read("*a")
|
||||
end
|
||||
|
||||
|
@ -27,7 +27,7 @@ fn main() {
|
||||
.long("pipestatus")
|
||||
.value_name("PIPESTATUS")
|
||||
.help("Status codes from a command pipeline")
|
||||
.long_help("Bash and Zsh supports returning codes for each process in a pipeline.")
|
||||
.long_help("Bash, Fish and Zsh support returning codes for each process in a pipeline.")
|
||||
.multiple(true);
|
||||
|
||||
let terminal_width_arg = Arg::with_name("terminal_width")
|
||||
@ -72,8 +72,7 @@ fn main() {
|
||||
.short("k")
|
||||
.long("keymap")
|
||||
.value_name("KEYMAP")
|
||||
// fish/zsh only
|
||||
.help("The keymap of fish/zsh")
|
||||
.help("The keymap of cmd/fish/zsh")
|
||||
.takes_value(true);
|
||||
|
||||
let jobs_arg = Arg::with_name("jobs")
|
||||
|
@ -32,7 +32,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
// We do some environment detection in src/init.rs to translate.
|
||||
// The result: in non-vi fish, keymap is always reported as "insert"
|
||||
let mode = match (&context.shell, keymap) {
|
||||
(Shell::Fish, "default") | (Shell::Zsh, "vicmd") => ShellEditMode::Normal,
|
||||
(Shell::Fish, "default") | (Shell::Zsh, "vicmd") | (Shell::Cmd, "vi") => {
|
||||
ShellEditMode::Normal
|
||||
}
|
||||
_ => ASSUMED_MODE,
|
||||
};
|
||||
|
||||
@ -193,4 +195,36 @@ mod test {
|
||||
.collect();
|
||||
assert_eq!(expected_other, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cmd_keymap() {
|
||||
let expected_vicmd = Some(format!("{} ", Color::Green.bold().paint("❮")));
|
||||
let expected_specified = Some(format!("{} ", Color::Green.bold().paint("V")));
|
||||
let expected_other = Some(format!("{} ", Color::Green.bold().paint("❯")));
|
||||
|
||||
// cmd keymap is vi
|
||||
let actual = ModuleRenderer::new("character")
|
||||
.shell(Shell::Cmd)
|
||||
.keymap("vi")
|
||||
.collect();
|
||||
assert_eq!(expected_vicmd, actual);
|
||||
|
||||
// specified vicmd character
|
||||
let actual = ModuleRenderer::new("character")
|
||||
.config(toml::toml! {
|
||||
[character]
|
||||
vicmd_symbol = "[V](bold green)"
|
||||
})
|
||||
.shell(Shell::Cmd)
|
||||
.keymap("vi")
|
||||
.collect();
|
||||
assert_eq!(expected_specified, actual);
|
||||
|
||||
// cmd keymap is other
|
||||
let actual = ModuleRenderer::new("character")
|
||||
.shell(Shell::Cmd)
|
||||
.keymap("visual")
|
||||
.collect();
|
||||
assert_eq!(expected_other, actual);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user