2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . Diagnostics . CodeAnalysis ;
5
- using System . Diagnostics . Tracing ;
6
5
using System . Linq ;
7
6
using System . Management . Automation ;
8
7
using System . Management . Automation . Language ;
9
8
using System . Text ;
10
- using System . Threading ;
11
9
12
10
namespace PSConsoleUtilities
13
11
{
@@ -66,8 +64,8 @@ public class PSConsoleReadLine
66
64
{
67
65
private static readonly PSConsoleReadLine _singleton ;
68
66
69
- private readonly ReadlineEventSource _log ;
70
- private readonly ReadlineEventListener _logListener ;
67
+ private bool _captureKeys ;
68
+ private readonly Queue < ConsoleKeyInfo > _savedKeys ;
71
69
private readonly HistoryQueue < string > _demoStrings ;
72
70
private bool _demoMode ;
73
71
private int _demoWindowLineCount ;
@@ -201,7 +199,11 @@ private static ConsoleKeyInfo ReadKey()
201
199
var key = _singleton . _queuedKeys . Count > 0
202
200
? _singleton . _queuedKeys . Dequeue ( )
203
201
: Console . ReadKey ( true ) ;
204
- _singleton . _log . Key ( key . KeyChar , key . Key , key . Modifiers ) ;
202
+ if ( _singleton . _captureKeys )
203
+ {
204
+ _singleton . _savedKeys . Enqueue ( key ) ;
205
+
206
+ }
205
207
return key ;
206
208
}
207
209
@@ -434,8 +436,8 @@ static PSConsoleReadLine()
434
436
435
437
private PSConsoleReadLine ( )
436
438
{
437
- _log = new ReadlineEventSource ( ) ;
438
- _logListener = new ReadlineEventListener ( ) ;
439
+ _captureKeys = false ;
440
+ _savedKeys = new Queue < ConsoleKeyInfo > ( ) ;
439
441
_demoStrings = new HistoryQueue < string > ( 100 ) ;
440
442
_demoMode = false ;
441
443
@@ -2122,18 +2124,18 @@ private void RenderDemoWindow(int windowStart)
2122
2124
setChar ( windowStart + i + 2 * _bufferWidth , ( char ) 9472 ) ;
2123
2125
}
2124
2126
2125
- string eventString ;
2126
- while ( _logListener . TryGetEvent ( out eventString ) )
2127
+ while ( _savedKeys . Count > 0 )
2127
2128
{
2128
- _demoStrings . Enqueue ( eventString ) ;
2129
+ var key = _savedKeys . Dequeue ( ) ;
2130
+ _demoStrings . Enqueue ( key . ToGestureString ( ) ) ;
2129
2131
}
2130
2132
2131
2133
int charsToDisplay = _bufferWidth - 2 - ( 2 * extraSpace ) ;
2132
2134
i = windowStart + _bufferWidth + 1 + extraSpace ;
2133
2135
bool first = true ;
2134
2136
for ( int j = _demoStrings . Count ; j > 0 ; j -- )
2135
2137
{
2136
- eventString = _demoStrings [ j - 1 ] ;
2138
+ string eventString = _demoStrings [ j - 1 ] ;
2137
2139
if ( ( eventString . Length + ( first ? 0 : 1 ) ) > charsToDisplay )
2138
2140
break ;
2139
2141
@@ -2190,7 +2192,7 @@ private void ClearDemoWindow()
2190
2192
public static void EnableDemoMode ( ConsoleKeyInfo ? key = null , object arg = null )
2191
2193
{
2192
2194
const int windowLineCount = 4 ; // 1 blank line, 2 border lines, 1 line of info
2193
- _singleton . _logListener . EnableEvents ( _singleton . _log , EventLevel . LogAlways ) ;
2195
+ _singleton . _captureKeys = true ;
2194
2196
_singleton . _demoMode = true ;
2195
2197
_singleton . _demoWindowLineCount = windowLineCount ;
2196
2198
var newBuffer = new CHAR_INFO [ _singleton . _consoleBuffer . Length + ( windowLineCount * _singleton . _bufferWidth ) ] ;
@@ -2205,12 +2207,8 @@ public static void EnableDemoMode(ConsoleKeyInfo? key = null, object arg = null)
2205
2207
/// </summary>
2206
2208
public static void DisableDemoMode ( ConsoleKeyInfo ? key = null , object arg = null )
2207
2209
{
2208
- _singleton . _logListener . DisableEvents ( _singleton . _log ) ;
2209
- string eventString ;
2210
- // Drain the queued events
2211
- while ( _singleton . _logListener . TryGetEvent ( out eventString ) )
2212
- {
2213
- }
2210
+ _singleton . _savedKeys . Clear ( ) ;
2211
+ _singleton . _captureKeys = false ;
2214
2212
_singleton . _demoMode = false ;
2215
2213
_singleton . _demoStrings . Clear ( ) ;
2216
2214
_singleton . _demoWindowLineCount = 0 ;
0 commit comments