|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
| 3 | +using System.Management.Automation; |
3 | 4 | using System.Reflection; |
4 | 5 | using System.Threading; |
5 | 6 |
|
@@ -155,7 +156,7 @@ private void SetOptionsInternal(SetPSReadlineOption options) |
155 | 156 | } |
156 | 157 | } |
157 | 158 |
|
158 | | - private void SetKeyHandlerInternal(string[] keys, Action<ConsoleKeyInfo?, object> handler, string briefDescription, string longDescription) |
| 159 | + private void SetKeyHandlerInternal(string[] keys, Action<ConsoleKeyInfo?, object> handler, string briefDescription, string longDescription, ScriptBlock scriptBlock) |
159 | 160 | { |
160 | 161 | foreach (var key in keys) |
161 | 162 | { |
@@ -196,12 +197,22 @@ public static PSConsoleReadlineOptions GetOptions() |
196 | 197 | return _singleton._options; |
197 | 198 | } |
198 | 199 |
|
| 200 | + /// <summary> |
| 201 | + /// Helper function for the Set-PSReadlineKeyHandler cmdlet. |
| 202 | + /// </summary> |
| 203 | + public static void SetKeyHandler(string[] key, ScriptBlock scriptBlock, string briefDescription, string longDescription) |
| 204 | + { |
| 205 | + Action<ConsoleKeyInfo?, object> handler = |
| 206 | + (k, arg) => scriptBlock.Invoke(k, arg); |
| 207 | + _singleton.SetKeyHandlerInternal(key, handler, briefDescription, longDescription, scriptBlock); |
| 208 | + } |
| 209 | + |
199 | 210 | /// <summary> |
200 | 211 | /// Helper function for the Set-PSReadlineKeyHandler cmdlet. |
201 | 212 | /// </summary> |
202 | 213 | public static void SetKeyHandler(string[] key, Action<ConsoleKeyInfo?, object> handler, string briefDescription, string longDescription) |
203 | 214 | { |
204 | | - _singleton.SetKeyHandlerInternal(key, handler, briefDescription, longDescription); |
| 215 | + _singleton.SetKeyHandlerInternal(key, handler, briefDescription, longDescription, null); |
205 | 216 | } |
206 | 217 |
|
207 | 218 | /// <summary> |
|
0 commit comments