22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . Diagnostics . CodeAnalysis ;
5- using System . Diagnostics . Tracing ;
65using System . Linq ;
76using System . Management . Automation ;
87using System . Management . Automation . Language ;
98using System . Text ;
10- using System . Threading ;
119
1210namespace PSConsoleUtilities
1311{
@@ -66,8 +64,8 @@ public class PSConsoleReadLine
6664 {
6765 private static readonly PSConsoleReadLine _singleton ;
6866
69- private readonly ReadlineEventSource _log ;
70- private readonly ReadlineEventListener _logListener ;
67+ private bool _captureKeys ;
68+ private readonly Queue < ConsoleKeyInfo > _savedKeys ;
7169 private readonly HistoryQueue < string > _demoStrings ;
7270 private bool _demoMode ;
7371 private int _demoWindowLineCount ;
@@ -201,7 +199,11 @@ private static ConsoleKeyInfo ReadKey()
201199 var key = _singleton . _queuedKeys . Count > 0
202200 ? _singleton . _queuedKeys . Dequeue ( )
203201 : 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+ }
205207 return key ;
206208 }
207209
@@ -434,8 +436,8 @@ static PSConsoleReadLine()
434436
435437 private PSConsoleReadLine ( )
436438 {
437- _log = new ReadlineEventSource ( ) ;
438- _logListener = new ReadlineEventListener ( ) ;
439+ _captureKeys = false ;
440+ _savedKeys = new Queue < ConsoleKeyInfo > ( ) ;
439441 _demoStrings = new HistoryQueue < string > ( 100 ) ;
440442 _demoMode = false ;
441443
@@ -2122,18 +2124,18 @@ private void RenderDemoWindow(int windowStart)
21222124 setChar ( windowStart + i + 2 * _bufferWidth , ( char ) 9472 ) ;
21232125 }
21242126
2125- string eventString ;
2126- while ( _logListener . TryGetEvent ( out eventString ) )
2127+ while ( _savedKeys . Count > 0 )
21272128 {
2128- _demoStrings . Enqueue ( eventString ) ;
2129+ var key = _savedKeys . Dequeue ( ) ;
2130+ _demoStrings . Enqueue ( key . ToGestureString ( ) ) ;
21292131 }
21302132
21312133 int charsToDisplay = _bufferWidth - 2 - ( 2 * extraSpace ) ;
21322134 i = windowStart + _bufferWidth + 1 + extraSpace ;
21332135 bool first = true ;
21342136 for ( int j = _demoStrings . Count ; j > 0 ; j -- )
21352137 {
2136- eventString = _demoStrings [ j - 1 ] ;
2138+ string eventString = _demoStrings [ j - 1 ] ;
21372139 if ( ( eventString . Length + ( first ? 0 : 1 ) ) > charsToDisplay )
21382140 break ;
21392141
@@ -2190,7 +2192,7 @@ private void ClearDemoWindow()
21902192 public static void EnableDemoMode ( ConsoleKeyInfo ? key = null , object arg = null )
21912193 {
21922194 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 ;
21942196 _singleton . _demoMode = true ;
21952197 _singleton . _demoWindowLineCount = windowLineCount ;
21962198 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)
22052207 /// </summary>
22062208 public static void DisableDemoMode ( ConsoleKeyInfo ? key = null , object arg = null )
22072209 {
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 ;
22142212 _singleton . _demoMode = false ;
22152213 _singleton . _demoStrings . Clear ( ) ;
22162214 _singleton . _demoWindowLineCount = 0 ;
0 commit comments