Skip to content

Fixes #4053. v2 WindowsDriver and v2win doesn't show any scenario in the UICatalog with cmd or conhost #4055

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

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion Terminal.Gui/ConsoleDrivers/V2/ConsoleDriverFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public int Top
/// <see langword="false"/>, indicating that the <see cref="ConsoleDriver"/> cannot support TrueColor.
/// </para>
/// </remarks>
public bool Force16Colors { get; set; }
public bool Force16Colors
{
get => Application.Force16Colors || !SupportsTrueColor;
set => Application.Force16Colors = value || !SupportsTrueColor;
}

/// <summary>
/// The <see cref="Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/>
Expand Down
8 changes: 8 additions & 0 deletions Terminal.Gui/ConsoleDrivers/V2/MainLoopCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class MainLoopCoordinator<T> : IMainLoopCoordinator
private ConsoleDriverFacade<T> _facade;
private Task _inputTask;
private readonly ITimedEvents _timedEvents;
private readonly bool _isWindowsTerminal;

private readonly SemaphoreSlim _startupSemaphore = new (0, 1);

Expand Down Expand Up @@ -60,6 +61,7 @@ IMainLoop<T> loop
_inputProcessor = inputProcessor;
_outputFactory = outputFactory;
_loop = loop;
_isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") is { } || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null;
}

/// <summary>
Expand Down Expand Up @@ -159,6 +161,12 @@ private void BuildFacadeIfPossible ()
_output,
_loop.AnsiRequestScheduler,
_loop.WindowSizeMonitor);

if (!_isWindowsTerminal)
{
Application.Force16Colors = _facade.Force16Colors = true;
}

Application.Driver = _facade;

_startupSemaphore.Release ();
Expand Down
26 changes: 21 additions & 5 deletions Terminal.Gui/ConsoleDrivers/V2/WindowsOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private enum DesiredAccess : uint
[DllImport ("kernel32.dll")]
private static extern bool SetConsoleCursorPosition (nint hConsoleOutput, Coord dwCursorPosition);

[DllImport ("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCursorInfo (nint hConsoleOutput, [In] ref ConsoleCursorInfo lpConsoleCursorInfo);

private readonly nint _screenBuffer;

public WindowsOutput ()
Expand Down Expand Up @@ -170,7 +173,7 @@ public void Write (IOutputBuffer buffer)
outputBuffer,
bufferCoords,
damageRegion,
false))
Application.Driver!.Force16Colors))
{
int err = Marshal.GetLastWin32Error ();

Expand Down Expand Up @@ -304,10 +307,23 @@ public Size GetWindowSize ()
/// <inheritdoc/>
public void SetCursorVisibility (CursorVisibility visibility)
{
string cursorVisibilitySequence = visibility != CursorVisibility.Invisible
? EscSeqUtils.CSI_ShowCursor
: EscSeqUtils.CSI_HideCursor;
Write (cursorVisibilitySequence);
if (Application.Driver!.Force16Colors)
{
var info = new ConsoleCursorInfo
{
dwSize = (uint)visibility & 0x00FF,
bVisible = ((uint)visibility & 0xFF00) != 0
};

SetConsoleCursorInfo (_screenBuffer, ref info);
}
else
{
string cursorVisibilitySequence = visibility != CursorVisibility.Invisible
? EscSeqUtils.CSI_ShowCursor
: EscSeqUtils.CSI_HideCursor;
Write (cursorVisibilitySequence);
}
}

private Point _lastCursorPosition;
Expand Down
Loading
Loading