Fixed netdriver running in unit tests

This commit is contained in:
Tigger Kindel
2023-08-12 08:08:47 -06:00
committed by Tig
parent b71d533901
commit 3dc19c9243
3 changed files with 20 additions and 14 deletions

View File

@@ -572,14 +572,16 @@ internal class NetDriver : ConsoleDriver {
}
StopReportingMouseMoves ();
Console.ResetColor ();
//Disable alternative screen buffer.
Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndActivateAltBufferWithBackscroll);
if (!_runningUnitTests) {
Console.ResetColor ();
//Set cursor key to cursor.
Console.Out.Write (EscSeqUtils.CSI_ShowCursor);
//Disable alternative screen buffer.
Console.Out.Write (EscSeqUtils.CSI_RestoreCursorAndActivateAltBufferWithBackscroll);
//Set cursor key to cursor.
Console.Out.Write (EscSeqUtils.CSI_ShowCursor);
}
Console.Out.Close ();
}
@@ -608,13 +610,13 @@ internal class NetDriver : ConsoleDriver {
TerminalResized = terminalResized;
//Enable alternative screen buffer.
Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
//Set cursor key to application.
Console.Out.Write (EscSeqUtils.CSI_HideCursor);
try {
//Enable alternative screen buffer.
Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
//Set cursor key to application.
Console.Out.Write (EscSeqUtils.CSI_HideCursor);
Console.TreatControlCAsInput = true;
Cols = Console.WindowWidth;
Rows = Console.WindowHeight;

View File

@@ -834,7 +834,7 @@ internal class WindowsDriver : ConsoleDriver {
Cols = e.Width;
Rows = e.Height;
if (WinConsole != null) {
if (!_runningUnitTests) {
var newSize = WinConsole.SetConsoleWindow (
(short)Math.Max (w, 16), (short)Math.Max (e.Height, 0));
@@ -1447,6 +1447,8 @@ internal class WindowsDriver : ConsoleDriver {
return base.IsRuneSupported (rune) && rune.IsBmp;
}
bool _runningUnitTests = false;
public override void Init (Action terminalResized)
{
TerminalResized = terminalResized;
@@ -1472,7 +1474,9 @@ internal class WindowsDriver : ConsoleDriver {
Console.Out.Write (EscSeqUtils.CSI_SaveCursorAndActivateAltBufferNoBackscroll);
}
} catch (Win32Exception e) {
// Likely running unit tests. Set WinConsole to null so we can test it elsewhere.
// We are being run in an environment that does not support a console
// such as a unit test, or a pipe.
_runningUnitTests = true;
Debug.WriteLine ($"Likely running unit tests. Setting WinConsole to null so we can test it elsewhere. Exception: {e}");
WinConsole = null;
}

View File

@@ -16,7 +16,7 @@ namespace Terminal.Gui.DriverTests {
{
var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
Application.Init (driver);
// driver.Init (() => { });
Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);