Skip to content

Commit a2cdea2

Browse files
committed
Remove .Net 4.5 dependency by removing EventSource.
1 parent 54a0863 commit a2cdea2

File tree

3 files changed

+18
-93
lines changed

3 files changed

+18
-93
lines changed

PSReadLine/PSReadLine.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>PSReadLine</RootNamespace>
1111
<AssemblyName>PSReadLine</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14-
<TargetFrameworkProfile>
15-
</TargetFrameworkProfile>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
1615
</PropertyGroup>
1716
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1817
<DebugSymbols>true</DebugSymbols>
@@ -62,7 +61,6 @@
6261
<DependentUpon>PSReadLineResources.resx</DependentUpon>
6362
</Compile>
6463
<Compile Include="ReadLine.cs" />
65-
<Compile Include="ReadlineETW.cs" />
6664
</ItemGroup>
6765
<ItemGroup>
6866
<Folder Include="Properties\" />

PSReadLine/ReadLine.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Diagnostics.CodeAnalysis;
5-
using System.Diagnostics.Tracing;
65
using System.Linq;
76
using System.Management.Automation;
87
using System.Management.Automation.Language;
98
using System.Text;
10-
using System.Threading;
119

1210
namespace 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;

PSReadLine/ReadlineETW.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)