mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 03:27:30 +00:00
feat(pwsh): Support vi command mode indicator (#5049)
Support vi command mode in powershell
This commit is contained in:
parent
ed68fd6e3d
commit
318050976b
@ -141,6 +141,10 @@ $null = New-Module starship {
|
|||||||
|
|
||||||
$arguments += "--status=$($lastExitCodeForPrompt)"
|
$arguments += "--status=$($lastExitCodeForPrompt)"
|
||||||
|
|
||||||
|
if ([Microsoft.PowerShell.PSConsoleReadLine]::InViCommandMode()) {
|
||||||
|
$arguments += "--keymap=vi"
|
||||||
|
}
|
||||||
|
|
||||||
# Invoke Starship
|
# Invoke Starship
|
||||||
$promptText = if ($script:TransientPrompt) {
|
$promptText = if ($script:TransientPrompt) {
|
||||||
$script:TransientPrompt = $false
|
$script:TransientPrompt = $false
|
||||||
@ -206,6 +210,12 @@ $null = New-Module starship {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
|
Set-PSReadLineOption -ViModeIndicator script -ViModeChangeHandler {
|
||||||
|
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
Export-ModuleMember -Function @(
|
Export-ModuleMember -Function @(
|
||||||
"Enable-TransientPrompt"
|
"Enable-TransientPrompt"
|
||||||
"Disable-TransientPrompt"
|
"Disable-TransientPrompt"
|
||||||
|
@ -35,9 +35,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
// We do some environment detection in src/init.rs to translate.
|
// We do some environment detection in src/init.rs to translate.
|
||||||
// The result: in non-vi fish, keymap is always reported as "insert"
|
// The result: in non-vi fish, keymap is always reported as "insert"
|
||||||
let mode = match (&context.shell, keymap) {
|
let mode = match (&context.shell, keymap) {
|
||||||
(Shell::Fish, "default") | (Shell::Zsh, "vicmd") | (Shell::Cmd, "vi") => {
|
(Shell::Fish, "default")
|
||||||
ShellEditMode::Normal
|
| (Shell::Zsh, "vicmd")
|
||||||
}
|
| (Shell::Cmd | Shell::PowerShell, "vi") => ShellEditMode::Normal,
|
||||||
(Shell::Fish, "visual") => ShellEditMode::Visual,
|
(Shell::Fish, "visual") => ShellEditMode::Visual,
|
||||||
(Shell::Fish, "replace") => ShellEditMode::Replace,
|
(Shell::Fish, "replace") => ShellEditMode::Replace,
|
||||||
(Shell::Fish, "replace_one") => ShellEditMode::ReplaceOne,
|
(Shell::Fish, "replace_one") => ShellEditMode::ReplaceOne,
|
||||||
@ -260,4 +260,36 @@ mod test {
|
|||||||
.collect();
|
.collect();
|
||||||
assert_eq!(expected_other, actual);
|
assert_eq!(expected_other, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn powershell_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("❯")));
|
||||||
|
|
||||||
|
// powershell keymap is vi
|
||||||
|
let actual = ModuleRenderer::new("character")
|
||||||
|
.shell(Shell::PowerShell)
|
||||||
|
.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::PowerShell)
|
||||||
|
.keymap("vi")
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected_specified, actual);
|
||||||
|
|
||||||
|
// powershell keymap is other
|
||||||
|
let actual = ModuleRenderer::new("character")
|
||||||
|
.shell(Shell::PowerShell)
|
||||||
|
.keymap("visual")
|
||||||
|
.collect();
|
||||||
|
assert_eq!(expected_other, actual);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user