Skip to content
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
18 changes: 18 additions & 0 deletions TUI.Test/SpectreConsoleProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,22 @@ public void WriteAtClipsTextOverflowingTheRightEdge()

Assert.AreEqual("\u001b[3;8Habc", output.ToString());
}

/// <summary>
/// Tests that showing or hiding the cursor writes the DECTCEM sequence to the injected console
/// and does not move the cursor (ktsu-dev/TUI#153).
/// </summary>
/// <param name="visible">Whether the cursor is shown.</param>
/// <param name="expected">The sequence expected in the captured output.</param>
[TestMethod]
[DataRow(false, "\u001b[?25l")]
[DataRow(true, "\u001b[?25h")]
public void SetCursorVisibilityWritesToTheInjectedConsoleWithoutMovingTheCursor(bool visible, string expected)
{
(SpectreConsoleProvider provider, StringWriter output) = CreateProvider();

provider.SetCursorVisibility(visible);

Assert.AreEqual(expected, output.ToString());
}
}
10 changes: 5 additions & 5 deletions TUI/Services/SpectreConsoleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public async Task<InputResult> ReadInputAsync()
}

/// <inheritdoc />
public void SetCursorVisibility(bool visible)
{
_console.Cursor.SetPosition(Console.CursorLeft + 1, Console.CursorTop + 1);
Console.CursorVisible = visible;
}
/// <remarks>
/// Writes to the injected console rather than <see cref="Console"/>, and leaves the cursor where
/// it is (ktsu-dev/TUI#153).
/// </remarks>
public void SetCursorVisibility(bool visible) => _console.Cursor.Show(visible);

/// <inheritdoc />
public void SetCursorPosition(Position position)
Expand Down
Loading