@@ -55,6 +55,9 @@ is very useful.
5555. PARAMETER InitialSelection
5656Set initial selections if multi-select mode. This is an array of indecies.
5757
58+ . PARAMETER Callback
59+ A function/scriptblock which is called every 10 milliseconds while the menu is shown
60+
5861. INPUTS
5962
6063None. You cannot pipe objects to Show-Menu.
@@ -88,7 +91,8 @@ function Show-Menu {
8891 [Switch ]$MultiSelect ,
8992 [ConsoleColor ] $ItemFocusColor = [ConsoleColor ]::Green,
9093 [ScriptBlock ] $MenuItemFormatter = { Param ($M ) Format-MenuItemDefault $M },
91- [Array ] $InitialSelection = @ ()
94+ [Array ] $InitialSelection = @ (),
95+ [ScriptBlock ] $Callback = $null
9296 )
9397
9498 Test-HostSupported
@@ -127,8 +131,11 @@ function Show-Menu {
127131 Break
128132 }
129133
130- $CurrentPress = Read-VKey
131- $VKeyCode = $CurrentPress.VirtualKeyCode
134+ $VKeyCode = $null
135+ if ([Console ]::KeyAvailable) {
136+ $CurrentPress = Read-VKey
137+ $VKeyCode = $CurrentPress.VirtualKeyCode
138+ }
132139
133140 If (Test-KeySpace $VKeyCode ) {
134141 $CurrentSelection = Toggle- Selection $Position $CurrentSelection
@@ -140,6 +147,12 @@ function Show-Menu {
140147 [System.Console ]::SetCursorPosition(0 , [Console ]::CursorTop - $MenuHeight )
141148 & $WriteMenu
142149 }
150+
151+ if ($Callback ) {
152+ & $Callback
153+ }
154+
155+ Start-Sleep - Milliseconds 10
143156 }
144157 }
145158 finally {
0 commit comments