Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ internal sealed partial class ConsoleHost
internal const int ExitCodeInitFailure = 70; // Internal Software Error
internal const int ExitCodeBadCommandLineParameter = 64; // Command Line Usage Error
private const uint SPI_GETSCREENREADER = 0x0046;
#if UNIX
internal const string DECCKM_ON = "\x1b[?1h";
internal const string DECCKM_OFF = "\x1b[?1l";
#endif

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
Expand Down Expand Up @@ -254,6 +258,14 @@ internal static int Start(string bannerText, string helpText)
{
#if LEGACYTELEMETRY
TelemetryAPI.ReportExitTelemetry(s_theConsoleHost);
#endif
#if UNIX
if (s_theConsoleHost.IsInteractive && s_theConsoleHost.UI.SupportsVirtualTerminal)
{
// https://github.com/dotnet/runtime/issues/27626 leaves terminal in application mode
// for now, we explicitly emit DECRST 1 sequence
s_theConsoleHost.UI.Write(DECCKM_OFF);
}
#endif
s_theConsoleHost.Dispose();
}
Expand Down Expand Up @@ -2473,6 +2485,14 @@ internal void Run(bool inputLoopIsNested)
ui.Write(prompt);
}

#if UNIX
if (c.SupportsVirtualTerminal)
{
// enable DECCKM as .NET requires cursor keys to emit VT for Console class
c.Write(DECCKM_ON);
}
#endif

previousResponseWasEmpty = false;
// There could be a profile. So there could be a user defined custom readline command
line = ui.ReadLineWithTabCompletion(_exec);
Expand Down Expand Up @@ -2576,6 +2596,14 @@ e is RemoteException ||
}
else
{
#if UNIX
if (c.SupportsVirtualTerminal)
{
// disable DECCKM to standard mode as applications may not expect VT for cursor keys
c.Write(DECCKM_OFF);
}
#endif

if (_parent.IsRunningAsync && !_parent.IsNested)
{
_exec.ExecuteCommandAsync(line, out e, Executor.ExecutionOptions.AddOutputter | Executor.ExecutionOptions.AddToHistory);
Expand Down