Skip to content

Commit 982b294

Browse files
davidsmatlaksdwheeler
authored andcommitted
issue 4848 (#4850)
1 parent 08e64e0 commit 982b294

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

reference/7/PSReadLine/Set-PSReadlineOption.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Set-PSReadLineOption [-EditMode <EditMode>] [-ContinuationPrompt <String>] [-His
2626
[-BellStyle <BellStyle>] [-CompletionQueryItems <Int32>] [-WordDelimiters <String>]
2727
[-HistorySearchCaseSensitive] [-HistorySaveStyle <HistorySaveStyle>] [-HistorySavePath <String>]
2828
[-AnsiEscapeTimeout <Int32>] [-PromptText <String>] [-ViModeIndicator <ViModeStyle>]
29-
[-Colors <Hashtable>] [<CommonParameters>]
29+
[-ViModeChangeHandler <ScriptBlock>] [-Colors <Hashtable>] [<CommonParameters>]
3030
```
3131

3232
## DESCRIPTION
@@ -116,6 +116,29 @@ Set-PSReadLineOption -Colors @{
116116
}
117117
```
118118

119+
### Example 6: Use ViModeChangeHandler to display Vi mode changes
120+
121+
This example emits a cursor change VT escape in response to a **Vi** mode change.
122+
123+
```powershell
124+
function OnViModeChange {
125+
if ($args[0] -eq 'Command') {
126+
# Set the cursor to a blinking block.
127+
Write-Host -NoNewLine "`e[1 q"
128+
} else {
129+
# Set the cursor to a blinking line.
130+
Write-Host -NoNewLine "`e[5 q"
131+
}
132+
}
133+
Set-PSReadLineOption -ViModeIndicator Script -ViModeChangeHandler $Function:OnViModeChange
134+
```
135+
136+
The **OnViModeChange** function sets the cursor options for the **Vi** modes: insert and command.
137+
**ViModeChangeHandler** uses the `Function:` provider to reference **OnViModeChange** as a script
138+
block object.
139+
140+
For more information, see [about_Providers](/powershell/module/microsoft.powershell.core/about/about_providers).
141+
119142
## PARAMETERS
120143

121144
### -AddToHistoryHandler
@@ -570,6 +593,23 @@ Accept pipeline input: False
570593
Accept wildcard characters: False
571594
```
572595

596+
### -ViModeChangeHandler
597+
598+
When the **ViModeIndicator** is set to `Script`, the script block provided will be invoked every
599+
time the mode changes. The script block is provided one argument of type `ViMode`.
600+
601+
```yaml
602+
Type: ScriptBlock
603+
Parameter Sets: (All)
604+
Aliases:
605+
606+
Required: False
607+
Position: Named
608+
Default value:
609+
Accept pipeline input: False
610+
Accept wildcard characters: False
611+
```
612+
573613
### -ViModeIndicator
574614

575615
This option sets the visual indication for the current **Vi** mode. Either insert mode or command
@@ -580,6 +620,7 @@ The valid values are as follows:
580620
- **None**: There's no indication.
581621
- **Prompt**: The prompt changes color.
582622
- **Cursor**: The cursor changes size.
623+
- **Script**: User-specified text is printed.
583624

584625
```yaml
585626
Type: ViModeStyle

0 commit comments

Comments
 (0)