|
@@ -14,7 +14,8 @@ namespace Terminal.Gui;
|
|
/// This is the Curses driver for the gui.cs/Terminal framework.
|
|
/// This is the Curses driver for the gui.cs/Terminal framework.
|
|
/// </summary>
|
|
/// </summary>
|
|
internal class CursesDriver : ConsoleDriver {
|
|
internal class CursesDriver : ConsoleDriver {
|
|
-
|
|
|
|
|
|
+ bool _runningUnitTests = false;
|
|
|
|
+
|
|
public override int Cols => Curses.Cols;
|
|
public override int Cols => Curses.Cols;
|
|
public override int Rows => Curses.Lines;
|
|
public override int Rows => Curses.Lines;
|
|
|
|
|
|
@@ -29,6 +30,10 @@ internal class CursesDriver : ConsoleDriver {
|
|
{
|
|
{
|
|
base.Move (col, row);
|
|
base.Move (col, row);
|
|
|
|
|
|
|
|
+ if (_runningUnitTests) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (IsValidLocation (col, row)) {
|
|
if (IsValidLocation (col, row)) {
|
|
Curses.move (row, col);
|
|
Curses.move (row, col);
|
|
} else {
|
|
} else {
|
|
@@ -52,7 +57,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
|
|
|
|
private void ProcessWinChange ()
|
|
private void ProcessWinChange ()
|
|
{
|
|
{
|
|
- if (Curses.CheckWinChange ()) {
|
|
|
|
|
|
+ if (!_runningUnitTests && Curses.CheckWinChange ()) {
|
|
ClearContents ();
|
|
ClearContents ();
|
|
TerminalResized?.Invoke ();
|
|
TerminalResized?.Invoke ();
|
|
}
|
|
}
|
|
@@ -86,7 +91,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public override Attribute MakeColor (Color fore, Color back)
|
|
public override Attribute MakeColor (Color fore, Color back)
|
|
{
|
|
{
|
|
- if (_window != null) {
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
return MakeColor (ColorToCursesColorNumber (fore), ColorToCursesColorNumber (back));
|
|
return MakeColor (ColorToCursesColorNumber (fore), ColorToCursesColorNumber (back));
|
|
} else {
|
|
} else {
|
|
return new Attribute (
|
|
return new Attribute (
|
|
@@ -193,7 +198,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
{
|
|
{
|
|
EnsureCursorVisibility ();
|
|
EnsureCursorVisibility ();
|
|
|
|
|
|
- if (Col >= 0 && Col < Cols && Row >= 0 && Row < Rows) {
|
|
|
|
|
|
+ if (!_runningUnitTests && Col >= 0 && Col < Cols && Row >= 0 && Row < Rows) {
|
|
Curses.move (Row, Col);
|
|
Curses.move (Row, Col);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -203,7 +208,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
StopReportingMouseMoves ();
|
|
StopReportingMouseMoves ();
|
|
SetCursorVisibility (CursorVisibility.Default);
|
|
SetCursorVisibility (CursorVisibility.Default);
|
|
|
|
|
|
- if (_window == null) {
|
|
|
|
|
|
+ if (_runningUnitTests) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// throws away any typeahead that has been typed by
|
|
// throws away any typeahead that has been typed by
|
|
@@ -225,6 +230,10 @@ internal class CursesDriver : ConsoleDriver {
|
|
if (Contents [row, col].IsDirty == false) {
|
|
if (Contents [row, col].IsDirty == false) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ if (_runningUnitTests) {
|
|
|
|
+ // In unit tests, we don't want to actually write to the screen.
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
Curses.attrset (Contents [row, col].Attribute.GetValueOrDefault ().Value);
|
|
Curses.attrset (Contents [row, col].Attribute.GetValueOrDefault ().Value);
|
|
|
|
|
|
var rune = Contents [row, col].Runes [0];
|
|
var rune = Contents [row, col].Runes [0];
|
|
@@ -247,7 +256,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (_window != null) {
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
Curses.move (Row, Col);
|
|
Curses.move (Row, Col);
|
|
_window.wrefresh ();
|
|
_window.wrefresh ();
|
|
}
|
|
}
|
|
@@ -589,8 +598,10 @@ internal class CursesDriver : ConsoleDriver {
|
|
|
|
|
|
public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
|
|
public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
|
|
{
|
|
{
|
|
- // Note: Curses doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
|
|
|
|
- Curses.timeout (0);
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
|
|
+ // Note: Curses doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
|
|
|
|
+ Curses.timeout (0);
|
|
|
|
+ }
|
|
this._keyHandler = keyHandler;
|
|
this._keyHandler = keyHandler;
|
|
this._keyDownHandler = keyDownHandler;
|
|
this._keyDownHandler = keyDownHandler;
|
|
this._keyUpHandler = keyUpHandler;
|
|
this._keyUpHandler = keyUpHandler;
|
|
@@ -608,19 +619,16 @@ internal class CursesDriver : ConsoleDriver {
|
|
|
|
|
|
public override void Init (Action terminalResized)
|
|
public override void Init (Action terminalResized)
|
|
{
|
|
{
|
|
- if (_window != null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
try {
|
|
try {
|
|
_window = Curses.initscr ();
|
|
_window = Curses.initscr ();
|
|
Curses.set_escdelay (10);
|
|
Curses.set_escdelay (10);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
_window = null;
|
|
_window = null;
|
|
|
|
+ _runningUnitTests = true;
|
|
Debug.WriteLine ($"Curses failed to initialize. Assuming Unit Tests. The exception is: {e.Message}");
|
|
Debug.WriteLine ($"Curses failed to initialize. Assuming Unit Tests. The exception is: {e.Message}");
|
|
}
|
|
}
|
|
|
|
|
|
- if (_window != null) {
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
// Ensures that all procedures are performed at some previous closing.
|
|
// Ensures that all procedures are performed at some previous closing.
|
|
Curses.doupdate ();
|
|
Curses.doupdate ();
|
|
|
|
|
|
@@ -674,7 +682,7 @@ internal class CursesDriver : ConsoleDriver {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (_window != null) {
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
Curses.CheckWinChange ();
|
|
Curses.CheckWinChange ();
|
|
ClearContents ();
|
|
ClearContents ();
|
|
Curses.refresh ();
|
|
Curses.refresh ();
|
|
@@ -699,20 +707,26 @@ internal class CursesDriver : ConsoleDriver {
|
|
public override void Suspend ()
|
|
public override void Suspend ()
|
|
{
|
|
{
|
|
StopReportingMouseMoves ();
|
|
StopReportingMouseMoves ();
|
|
- Platform.Suspend ();
|
|
|
|
- Curses.Window.Standard.redrawwin ();
|
|
|
|
- Curses.refresh ();
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
|
|
+ Platform.Suspend ();
|
|
|
|
+ Curses.Window.Standard.redrawwin ();
|
|
|
|
+ Curses.refresh ();
|
|
|
|
+ }
|
|
StartReportingMouseMoves ();
|
|
StartReportingMouseMoves ();
|
|
}
|
|
}
|
|
|
|
|
|
public void StartReportingMouseMoves ()
|
|
public void StartReportingMouseMoves ()
|
|
{
|
|
{
|
|
- Console.Out.Write (EscSeqUtils.CSI_EnableMouseEvents);
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
|
|
+ Console.Out.Write (EscSeqUtils.CSI_EnableMouseEvents);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
public void StopReportingMouseMoves ()
|
|
public void StopReportingMouseMoves ()
|
|
{
|
|
{
|
|
- Console.Out.Write (EscSeqUtils.CSI_DisableMouseEvents);
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
|
|
+ Console.Out.Write (EscSeqUtils.CSI_DisableMouseEvents);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
/// <inheritdoc/>
|
|
@@ -735,7 +749,9 @@ internal class CursesDriver : ConsoleDriver {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- Curses.curs_set (((int)visibility >> 16) & 0x000000FF);
|
|
|
|
|
|
+ if (!_runningUnitTests) {
|
|
|
|
+ Curses.curs_set (((int)visibility >> 16) & 0x000000FF);
|
|
|
|
+ }
|
|
|
|
|
|
if (visibility != CursorVisibility.Invisible) {
|
|
if (visibility != CursorVisibility.Invisible) {
|
|
Console.Out.Write (EscSeqUtils.CSI_SetCursorStyle ((EscSeqUtils.DECSCUSR_Style)(((int)visibility >> 24) & 0xFF)));
|
|
Console.Out.Write (EscSeqUtils.CSI_SetCursorStyle ((EscSeqUtils.DECSCUSR_Style)(((int)visibility >> 24) & 0xFF)));
|