Skip to content

Commit

Permalink
Merge pull request #8 from BDisp/fixes_2261_scroll_buffer_cleared_on_…
Browse files Browse the repository at this point in the history
…exit-fix

Improves HeightAsBuffer although currently only works on Windows.
  • Loading branch information
tig authored Jan 22, 2023
2 parents 1560267 + 7c832e8 commit 47b3acf
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 202 deletions.
7 changes: 6 additions & 1 deletion Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ internal class CursesDriver : ConsoleDriver {
public override int Rows => Curses.Lines;
public override int Left => 0;
public override int Top => 0;
public override bool HeightAsBuffer { get; set; }
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
public override IClipboard Clipboard { get => clipboard; }

CursorVisibility? initialCursorVisibility = null;
Expand Down
17 changes: 11 additions & 6 deletions Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsN
UseFakeClipboard = useFakeClipboard;
FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;

// double check usage is correct
Debug.Assert (useFakeClipboard == false && fakeClipboardAlwaysThrowsNotSupportedException == false);
Debug.Assert (useFakeClipboard == false && fakeClipboardIsSupportedAlwaysTrue == false);
Expand All @@ -48,7 +48,12 @@ public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsN
// Only handling left here because not all terminals has a horizontal scroll bar.
public override int Left => 0;
public override int Top => 0;
public override bool HeightAsBuffer { get; set; }
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
private IClipboard clipboard = null;
public override IClipboard Clipboard => clipboard;

Expand Down Expand Up @@ -521,7 +526,7 @@ public void SetBufferSize (int width, int height)
FakeConsole.SetBufferSize (width, height);
cols = width;
rows = height;
if (!HeightAsBuffer) {
if (!EnableConsoleScrolling) {
SetWindowSize (width, height);
}
ProcessResize ();
Expand All @@ -530,7 +535,7 @@ public void SetBufferSize (int width, int height)
public void SetWindowSize (int width, int height)
{
FakeConsole.SetWindowSize (width, height);
if (!HeightAsBuffer) {
if (!EnableConsoleScrolling) {
if (width != cols || height != rows) {
SetBufferSize (width, height);
cols = width;
Expand All @@ -542,7 +547,7 @@ public void SetWindowSize (int width, int height)

public void SetWindowPosition (int left, int top)
{
if (HeightAsBuffer) {
if (EnableConsoleScrolling) {
this.left = Math.Max (Math.Min (left, Cols - FakeConsole.WindowWidth), 0);
this.top = Math.Max (Math.Min (top, Rows - FakeConsole.WindowHeight), 0);
} else if (this.left > 0 || this.top > 0) {
Expand All @@ -561,7 +566,7 @@ void ProcessResize ()

public override void ResizeScreen ()
{
if (!HeightAsBuffer) {
if (!EnableConsoleScrolling) {
if (FakeConsole.WindowHeight > 0) {
// Can raise an exception while is still resizing.
try {
Expand Down
Loading

0 comments on commit 47b3acf

Please sign in to comment.