Skip to content

Commit

Permalink
Fixes #2930. Console.CursorLeft-- throw an exception with NetDriver o…
Browse files Browse the repository at this point in the history
…n Linux (v2). (#2931)

* Fixes #2930. Console.CursorLeft-- throw an exception with NetDriver on Linux (v2).

* Fix inverted parameters.

* Fixes #2666. With #2659 Cursor flickers on NetDriver

* Fix typo.

* Using the _cachedCursorVisibility field.
  • Loading branch information
BDisp authored Oct 25, 2023
1 parent 6851b42 commit 84cc3b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
5 changes: 1 addition & 4 deletions Terminal.Gui/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public static void Run (Toplevel view, Func<Exception, bool> errorHandler = null
#endif
resume = false;
var runState = Begin (view);
// If ExitRunLoopAfterFirstIteration is true then the user must dispose of the runToken
// If EndAfterFirstIteration is true then the user must dispose of the runToken
// by using NotifyStopRunState event.
RunLoop (runState);
if (!EndAfterFirstIteration) {
Expand Down Expand Up @@ -668,9 +668,6 @@ public static void RunIteration (ref RunState state, ref bool firstIteration)
} else if (Current.SuperView == null && Current?.Modal == true) {
Refresh ();
}
if (Driver.EnsureCursorVisibility ()) {
state.Toplevel.SetNeedsDisplay ();
}
}

firstIteration = false;
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public enum ClearScreenOptions {
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public static string CSI_SetCursorPosition (int x, int y) => $"{CSI}{y};{x}H";
public static string CSI_SetCursorPosition (int y, int x) => $"{CSI}{y};{x}H";


//ESC [ <y> ; <x> f - HVP Horizontal Vertical Position* Cursor moves to<x>; <y> coordinate within the viewport, where <x> is the column of the<y> line
Expand Down
34 changes: 17 additions & 17 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ public override void UpdateScreen ()
Attribute redrawAttr = new Attribute ();
var lastCol = -1;

//GetCursorVisibility (out CursorVisibility savedVisibitity);
//SetCursorVisibility (CursorVisibility.Invisible);
var savedVisibitity = _cachedCursorVisibility;
SetCursorVisibility (CursorVisibility.Invisible);

for (var row = top; row < rows; row++) {
if (Console.WindowHeight < 1) {
Expand Down Expand Up @@ -812,7 +812,7 @@ public override void UpdateScreen ()
output.Append (rune.ToString ());
if (rune.IsSurrogatePair () && rune.GetColumns () < 2) {
WriteToConsole (output, ref lastCol, row, ref outputWidth);
Console.CursorLeft--;
SetCursorPosition (col - 1, row);
}
Contents [row, col].IsDirty = false;
}
Expand All @@ -824,7 +824,7 @@ public override void UpdateScreen ()
}
SetCursorPosition (0, 0);

//SetCursorVisibility (savedVisibitity);
_cachedCursorVisibility = savedVisibitity;

void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
{
Expand Down Expand Up @@ -888,20 +888,20 @@ int MapColors (ConsoleColor color, bool isForeground = true)
#region Cursor Handling
bool SetCursorPosition (int col, int row)
{
//if (IsWinPlatform) {
// Could happens that the windows is still resizing and the col is bigger than Console.WindowWidth.
try {
Console.SetCursorPosition (col, row);
if (IsWinPlatform) {
// Could happens that the windows is still resizing and the col is bigger than Console.WindowWidth.
try {
Console.SetCursorPosition (col, row);
return true;
} catch (Exception) {
return false;
}
} else {
// + 1 is needed because non-Windows is based on 1 instead of 0 and
// Console.CursorTop/CursorLeft isn't reliable.
Console.Out.Write (EscSeqUtils.CSI_SetCursorPosition (row + 1, col + 1));
return true;
} catch (Exception) {
return false;
}
// BUGBUG: This breaks -usc on WSL; not sure why. But commenting out fixes.
//} else {
// // TODO: Explain why + 1 is needed (and why we do this for non-Windows).
// Console.Out.Write (EscSeqUtils.CSI_SetCursorPosition (row + 1, col + 1));
// return true;
//}
}

CursorVisibility? _cachedCursorVisibility;
Expand All @@ -926,7 +926,7 @@ public override bool SetCursorVisibility (CursorVisibility visibility)
{
_cachedCursorVisibility = visibility;
var isVisible = RunningUnitTests ? visibility == CursorVisibility.Default : Console.CursorVisible = visibility == CursorVisibility.Default;
//Console.Out.Write (isVisible ? EscSeqUtils.CSI_ShowCursor : EscSeqUtils.CSI_HideCursor);
Console.Out.Write (isVisible ? EscSeqUtils.CSI_ShowCursor : EscSeqUtils.CSI_HideCursor);
return isVisible;
}

Expand Down

0 comments on commit 84cc3b3

Please sign in to comment.