2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
- using System . Runtime . InteropServices ;
6
5
using System . Threading ;
7
6
8
7
namespace Microsoft . PowerShell . EditorServices . Services . PowerShell . Console
@@ -21,66 +20,6 @@ internal static class ConsoleProxy
21
20
alt : false ,
22
21
control : false ) ;
23
22
24
- private static readonly IConsoleOperations s_consoleProxy ;
25
-
26
- [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Performance" , "CA1810:Initialize reference type static fields inline" , Justification = "Platform specific initialization" ) ]
27
- static ConsoleProxy ( )
28
- {
29
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
30
- {
31
- s_consoleProxy = new WindowsConsoleOperations ( ) ;
32
- return ;
33
- }
34
-
35
- s_consoleProxy = new UnixConsoleOperations ( ) ;
36
- }
37
-
38
- /// <summary>
39
- /// Obtains the next character or function key pressed by the user asynchronously.
40
- /// Does not block when other console API's are called.
41
- /// </summary>
42
- /// <param name="intercept">
43
- /// Determines whether to display the pressed key in the console window. <see langword="true" />
44
- /// to not display the pressed key; otherwise, <see langword="false" />.
45
- /// </param>
46
- /// <param name="cancellationToken">The CancellationToken to observe.</param>
47
- /// <returns>
48
- /// An object that describes the <see cref="ConsoleKey" /> constant and Unicode character, if any,
49
- /// that correspond to the pressed console key. The <see cref="ConsoleKeyInfo" /> object also
50
- /// describes, in a bitwise combination of <see cref="ConsoleModifiers" /> values, whether
51
- /// one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.
52
- /// </returns>
53
- public static ConsoleKeyInfo ReadKey ( bool intercept , CancellationToken cancellationToken ) =>
54
- s_consoleProxy . ReadKey ( intercept , cancellationToken ) ;
55
-
56
- /// <summary>
57
- /// Obtains the horizontal position of the console cursor. TODO: Is this still necessary?
58
- /// </summary>
59
- /// <returns>The horizontal position of the console cursor.</returns>
60
- public static int GetCursorLeft ( ) => s_consoleProxy . GetCursorLeft ( ) ;
61
-
62
- /// <summary>
63
- /// Obtains the horizontal position of the console cursor. TODO: Is this still necessary?
64
- /// </summary>
65
- /// <param name="cancellationToken">The <see cref="CancellationToken" /> to observe.</param>
66
- /// <returns>The horizontal position of the console cursor.</returns>
67
- public static int GetCursorLeft ( CancellationToken cancellationToken ) =>
68
- s_consoleProxy . GetCursorLeft ( cancellationToken ) ;
69
-
70
- /// <summary>
71
- /// Obtains the vertical position of the console cursor. TODO: Is this still necessary?
72
- /// </summary>
73
- /// <returns>The vertical position of the console cursor.</returns>
74
- public static int GetCursorTop ( ) => s_consoleProxy . GetCursorTop ( ) ;
75
-
76
- /// <summary>
77
- /// Obtains the vertical position of the console cursor. TODO: Is this still necessary?
78
- /// </summary>
79
- /// <param name="cancellationToken">The <see cref="CancellationToken" /> to observe.</param>
80
- /// <returns>The vertical position of the console cursor.</returns>
81
- public static int GetCursorTop ( CancellationToken cancellationToken ) =>
82
- s_consoleProxy . GetCursorTop ( cancellationToken ) ;
83
-
84
23
/// <summary>
85
24
/// This method is sent to PSReadLine as a workaround for issues with the System.Console
86
25
/// implementation. Functionally it is the same as System.Console.ReadKey,
@@ -101,14 +40,8 @@ public static int GetCursorTop(CancellationToken cancellationToken) =>
101
40
/// </returns>
102
41
internal static ConsoleKeyInfo SafeReadKey ( bool intercept , CancellationToken cancellationToken )
103
42
{
104
- try
105
- {
106
- return s_consoleProxy . ReadKey ( intercept , cancellationToken ) ;
107
- }
108
- catch ( OperationCanceledException )
109
- {
110
- return s_nullKeyInfo ;
111
- }
43
+ ConsoleKeyInfo key = System . Console . ReadKey ( intercept ) ;
44
+ return cancellationToken . IsCancellationRequested ? s_nullKeyInfo : key ;
112
45
}
113
46
}
114
47
}
0 commit comments