Skip to content

Commit 43bddb1

Browse files
committed
Remove unneeded readline interface methods
1 parent b68c7ac commit 43bddb1

File tree

5 files changed

+15
-41
lines changed

5 files changed

+15
-41
lines changed

src/PowerShellEditorServices/Services/PowerShell/Console/IReadLine.cs

-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,5 @@ internal interface IReadLine
1212
string ReadLine(CancellationToken cancellationToken);
1313

1414
SecureString ReadSecureLine(CancellationToken cancellationToken);
15-
16-
bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyOverride);
17-
18-
bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler);
1915
}
2016
}

src/PowerShellEditorServices/Services/PowerShell/Console/LegacyReadLine.cs

+8-16
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ internal class LegacyReadLine : TerminalReadLine
2121

2222
private readonly Task[] _readKeyTasks;
2323

24-
private Func<bool, ConsoleKeyInfo> _readKeyFunc;
24+
private readonly Func<bool, ConsoleKeyInfo> _readKeyFunc;
2525

26-
private Action _onIdleAction;
26+
private readonly Action<CancellationToken> _onIdleAction;
2727

2828
public LegacyReadLine(
29-
PsesInternalHost psesHost)
29+
PsesInternalHost psesHost,
30+
Func<bool, ConsoleKeyInfo> readKeyFunc,
31+
Action<CancellationToken> onIdleAction)
3032
{
3133
_psesHost = psesHost;
3234
_readKeyTasks = new Task[2];
35+
_readKeyFunc = readKeyFunc;
36+
_onIdleAction = onIdleAction;
3337
}
3438

3539
public override string ReadLine(CancellationToken cancellationToken)
@@ -376,18 +380,6 @@ public override string ReadLine(CancellationToken cancellationToken)
376380
return null;
377381
}
378382

379-
public override bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler)
380-
{
381-
_onIdleAction = idleHandler;
382-
return true;
383-
}
384-
385-
public override bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyOverride)
386-
{
387-
_readKeyFunc = readKeyOverride;
388-
return true;
389-
}
390-
391383
protected override ConsoleKeyInfo ReadKey(CancellationToken cancellationToken)
392384
{
393385
cancellationToken.ThrowIfCancellationRequested();
@@ -421,7 +413,7 @@ private ConsoleKeyInfo ReadKeyWithIdleSupport(CancellationToken cancellationToke
421413

422414
// The idle timed out
423415
case 1:
424-
_onIdleAction();
416+
_onIdleAction(cancellationToken);
425417
_readKeyTasks[1] = Task.Delay(millisecondsDelay: 300, cancellationToken);
426418
continue;
427419
}

src/PowerShellEditorServices/Services/PowerShell/Console/PsrlReadLine.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ internal class PsrlReadLine : TerminalReadLine
2323
public PsrlReadLine(
2424
PSReadLineProxy psrlProxy,
2525
PsesInternalHost psesHost,
26-
EngineIntrinsics engineIntrinsics)
26+
EngineIntrinsics engineIntrinsics,
27+
Func<bool, ConsoleKeyInfo> readKeyFunc,
28+
Action<CancellationToken> onIdleAction)
2729
{
2830
_psrlProxy = psrlProxy;
2931
_psesHost = psesHost;
3032
_engineIntrinsics = engineIntrinsics;
33+
_psrlProxy.OverrideReadKey(readKeyFunc);
34+
_psrlProxy.OverrideIdleHandler(onIdleAction);
3135
}
3236

3337
#endregion
@@ -39,18 +43,6 @@ public override string ReadLine(CancellationToken cancellationToken)
3943
return _psesHost.InvokeDelegate<string>(representation: "ReadLine", new ExecutionOptions { MustRunInForeground = true }, InvokePSReadLine, cancellationToken);
4044
}
4145

42-
public override bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyFunc)
43-
{
44-
_psrlProxy.OverrideReadKey(readKeyFunc);
45-
return true;
46-
}
47-
48-
public override bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler)
49-
{
50-
_psrlProxy.OverrideIdleHandler(idleHandler);
51-
return true;
52-
}
53-
5446
protected override ConsoleKeyInfo ReadKey(CancellationToken cancellationToken)
5547
{
5648
return ConsoleProxy.ReadKey(intercept: true, cancellationToken);

src/PowerShellEditorServices/Services/PowerShell/Console/TerminalReadLine.cs

-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ internal abstract class TerminalReadLine : IReadLine
1414
{
1515
public abstract string ReadLine(CancellationToken cancellationToken);
1616

17-
public abstract bool TryOverrideIdleHandler(Action<CancellationToken> idleHandler);
18-
19-
public abstract bool TryOverrideReadKey(Func<bool, ConsoleKeyInfo> readKeyOverride);
20-
2117
protected abstract ConsoleKeyInfo ReadKey(CancellationToken cancellationToken);
2218

2319
public SecureString ReadSecureLine(CancellationToken cancellationToken)

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,9 @@ private static PowerShell CreatePowerShellForRunspace(Runspace runspace)
630630
// If we've been configured to use it, or if we can't load PSReadLine, use the legacy readline
631631
if (hostStartupInfo.UsesLegacyReadLine || !TryLoadPSReadLine(pwsh, engineIntrinsics, out IReadLine readLine))
632632
{
633-
readLine = new LegacyReadLine(this);
633+
readLine = new LegacyReadLine(this, ReadKey, OnPowerShellIdle);
634634
}
635635

636-
readLine.TryOverrideReadKey(ReadKey);
637-
readLine.TryOverrideIdleHandler(OnPowerShellIdle);
638636
readLineProvider.OverrideReadLine(readLine);
639637
System.Console.CancelKeyPress += OnCancelKeyPress;
640638
System.Console.InputEncoding = Encoding.UTF8;
@@ -833,7 +831,7 @@ private bool TryLoadPSReadLine(PowerShell pwsh, EngineIntrinsics engineIntrinsic
833831
try
834832
{
835833
var psrlProxy = PSReadLineProxy.LoadAndCreate(_loggerFactory, pwsh);
836-
psrlReadLine = new PsrlReadLine(psrlProxy, this, engineIntrinsics);
834+
psrlReadLine = new PsrlReadLine(psrlProxy, this, engineIntrinsics, ReadKey, OnPowerShellIdle);
837835
return true;
838836
}
839837
catch (Exception e)

0 commit comments

Comments
 (0)