Skip to content

Commit f98e460

Browse files
BDisptig
andauthored
Fixes #4053. v2 WindowsDriver and v2win doesn't show any scenario in the UICatalog with cmd or conhost (#4055)
* Fix WindowsDriver to work with non-WindowsTerminal * Fix unit test failure * Fix v2win to work with non-WindowsTerminal * Force16Colors isn't being setting in v2win driver on changing. --------- Co-authored-by: Tig <tig@users.noreply.github.com>
1 parent ece4fee commit f98e460

File tree

6 files changed

+169
-131
lines changed

6 files changed

+169
-131
lines changed

Terminal.Gui/ConsoleDrivers/V2/ConsoleDriverFacade.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ public int Top
141141
/// <see langword="false"/>, indicating that the <see cref="ConsoleDriver"/> cannot support TrueColor.
142142
/// </para>
143143
/// </remarks>
144-
public bool Force16Colors { get; set; }
144+
public bool Force16Colors
145+
{
146+
get => Application.Force16Colors || !SupportsTrueColor;
147+
set => Application.Force16Colors = value || !SupportsTrueColor;
148+
}
145149

146150
/// <summary>
147151
/// The <see cref="Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/>

Terminal.Gui/ConsoleDrivers/V2/MainLoopCoordinator.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal class MainLoopCoordinator<T> : IMainLoopCoordinator
2525
private ConsoleDriverFacade<T> _facade;
2626
private Task _inputTask;
2727
private readonly ITimedEvents _timedEvents;
28+
private readonly bool _isWindowsTerminal;
2829

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

@@ -60,6 +61,7 @@ IMainLoop<T> loop
6061
_inputProcessor = inputProcessor;
6162
_outputFactory = outputFactory;
6263
_loop = loop;
64+
_isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") is { } || Environment.GetEnvironmentVariable ("VSAPPIDNAME") != null;
6365
}
6466

6567
/// <summary>
@@ -159,6 +161,12 @@ private void BuildFacadeIfPossible ()
159161
_output,
160162
_loop.AnsiRequestScheduler,
161163
_loop.WindowSizeMonitor);
164+
165+
if (!_isWindowsTerminal)
166+
{
167+
Application.Force16Colors = _facade.Force16Colors = true;
168+
}
169+
162170
Application.Driver = _facade;
163171

164172
_startupSemaphore.Release ();

Terminal.Gui/ConsoleDrivers/V2/WindowsOutput.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ private enum DesiredAccess : uint
5656
[DllImport ("kernel32.dll")]
5757
private static extern bool SetConsoleCursorPosition (nint hConsoleOutput, Coord dwCursorPosition);
5858

59+
[DllImport ("kernel32.dll", SetLastError = true)]
60+
private static extern bool SetConsoleCursorInfo (nint hConsoleOutput, [In] ref ConsoleCursorInfo lpConsoleCursorInfo);
61+
5962
private readonly nint _screenBuffer;
6063

6164
public WindowsOutput ()
@@ -170,7 +173,7 @@ public void Write (IOutputBuffer buffer)
170173
outputBuffer,
171174
bufferCoords,
172175
damageRegion,
173-
false))
176+
Application.Driver!.Force16Colors))
174177
{
175178
int err = Marshal.GetLastWin32Error ();
176179

@@ -304,10 +307,23 @@ public Size GetWindowSize ()
304307
/// <inheritdoc/>
305308
public void SetCursorVisibility (CursorVisibility visibility)
306309
{
307-
string cursorVisibilitySequence = visibility != CursorVisibility.Invisible
308-
? EscSeqUtils.CSI_ShowCursor
309-
: EscSeqUtils.CSI_HideCursor;
310-
Write (cursorVisibilitySequence);
310+
if (Application.Driver!.Force16Colors)
311+
{
312+
var info = new ConsoleCursorInfo
313+
{
314+
dwSize = (uint)visibility & 0x00FF,
315+
bVisible = ((uint)visibility & 0xFF00) != 0
316+
};
317+
318+
SetConsoleCursorInfo (_screenBuffer, ref info);
319+
}
320+
else
321+
{
322+
string cursorVisibilitySequence = visibility != CursorVisibility.Invisible
323+
? EscSeqUtils.CSI_ShowCursor
324+
: EscSeqUtils.CSI_HideCursor;
325+
Write (cursorVisibilitySequence);
326+
}
311327
}
312328

313329
private Point _lastCursorPosition;

0 commit comments

Comments
 (0)