-
Notifications
You must be signed in to change notification settings - Fork 234
Added a -UseHostReadKey switch to instruct LegacyReadLine to use the … #1748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,7 +17,7 @@ public enum ConsoleReplKind | |||
/// <summary>Use a REPL with the legacy readline implementation. This is generally used when PSReadLine is unavailable.</summary> | ||||
LegacyReadLine = 1, | ||||
/// <summary>Use a REPL with the PSReadLine module for console interaction.</summary> | ||||
PSReadLine = 2, | ||||
PSReadLine = 2 | ||||
} | ||||
|
||||
/// <summary> | ||||
|
@@ -39,13 +39,15 @@ public EditorServicesConfig( | |||
PSHost psHost, | ||||
string sessionDetailsPath, | ||||
string bundledModulePath, | ||||
string logPath) | ||||
string logPath, | ||||
bool useHostReadKey) | ||||
{ | ||||
HostInfo = hostInfo; | ||||
PSHost = psHost; | ||||
SessionDetailsPath = sessionDetailsPath; | ||||
BundledModulePath = bundledModulePath; | ||||
LogPath = logPath; | ||||
UseHostReadKey = useHostReadKey; | ||||
} | ||||
|
||||
/// <summary> | ||||
|
@@ -72,6 +74,7 @@ public EditorServicesConfig( | |||
/// The path to use for logging for Editor Services. | ||||
/// </summary> | ||||
public string LogPath { get; } | ||||
public bool UseHostReadKey { get; } | ||||
|
||||
/// <summary> | ||||
/// Names of or paths to any additional modules to load on startup. | ||||
|
@@ -88,7 +91,7 @@ public EditorServicesConfig( | |||
/// (including none to disable the integrated console). | ||||
/// </summary> | ||||
public ConsoleReplKind ConsoleRepl { get; set; } = ConsoleReplKind.None; | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Extra whitespace |
||||
/// <summary> | ||||
/// The minimum log level to log events with. | ||||
/// </summary> | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ public PsesInternalHost( | |
_logger = loggerFactory.CreateLogger<PsesInternalHost>(); | ||
_languageServer = languageServer; | ||
_hostInfo = hostInfo; | ||
|
||
|
||
// Respect a user provided bundled module path. | ||
if (Directory.Exists(hostInfo.BundledModulePath)) | ||
|
@@ -136,6 +137,7 @@ public PsesInternalHost( | |
Version = hostInfo.Version; | ||
|
||
DebugContext = new PowerShellDebugContext(loggerFactory, this); | ||
|
||
UI = hostInfo.ConsoleReplEnabled | ||
? new EditorServicesConsolePSHostUserInterface(loggerFactory, hostInfo.PSHost.UI) | ||
: new NullPSHostUI(); | ||
|
@@ -1071,6 +1073,24 @@ private void OnCancelKeyPress(object sender, ConsoleCancelEventArgs args) | |
StopDebugContext(); | ||
} | ||
} | ||
/// <summary> | ||
/// This method is sent to PSReadLine as a workaround for issues with the System.Console | ||
/// implementation. Functionally it is the same as System.Console.ReadKey, | ||
/// with the exception that it will not lock the standard input stream. | ||
/// </summary> | ||
/// <param name="intercept"> | ||
/// Determines whether to display the pressed key in the console window. | ||
/// true to not display the pressed key; otherwise, false. | ||
/// </param> | ||
/// <param name="cancellationToken"> | ||
/// The <see cref="CancellationToken" /> that can be used to cancel the request. | ||
/// </param> | ||
/// <returns> | ||
/// An object that describes the ConsoleKey constant and Unicode character, if any, | ||
/// that correspond to the pressed console key. The ConsoleKeyInfo object also describes, | ||
/// in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt, | ||
/// or Ctrl modifier keys was pressed simultaneously with the console key. | ||
/// </returns> | ||
|
||
private ConsoleKeyInfo ReadKey(bool intercept) | ||
{ | ||
|
@@ -1094,13 +1114,24 @@ private ConsoleKeyInfo ReadKey(bool intercept) | |
// we can subscribe in the same way. | ||
DebugServer?.SendNotification("powerShell/sendKeyPress"); | ||
}); | ||
|
||
// PSReadLine doesn't tell us when CtrlC was sent. So instead we keep track of the last | ||
// key here. This isn't functionally required, but helps us determine when the prompt | ||
// needs a newline added | ||
// | ||
// TODO: We may want to allow users of PSES to override this method call. | ||
_lastKey = System.Console.ReadKey(intercept); | ||
if (!_hostInfo.UseHostReadKey) | ||
{ | ||
_lastKey = System.Console.ReadKey(intercept); | ||
} | ||
else | ||
{ | ||
KeyInfo keyInfo = _hostInfo.PSHost.UI.RawUI.ReadKey(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silly question: Could we just make the default |
||
_lastKey = new(keyInfo.Character, (ConsoleKey)keyInfo.Character, (keyInfo.ControlKeyState & ControlKeyStates.ShiftPressed) > 0, | ||
(keyInfo.ControlKeyState & (ControlKeyStates.RightAltPressed | ControlKeyStates.LeftAltPressed)) > 0, | ||
(keyInfo.ControlKeyState & (ControlKeyStates.RightCtrlPressed | ControlKeyStates.LeftCtrlPressed)) > 0); | ||
} | ||
|
||
return _lastKey.Value; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing comma is on purpose here