Skip to content

Commit

Permalink
Remove EnableConsoleScrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Jul 26, 2023
1 parent a8a33fb commit 7ef51ba
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 333 deletions.
8 changes: 3 additions & 5 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ internal class CursesDriver : ConsoleDriver {
public override int Rows => Curses.Lines;
public override int Left => 0;
public override int Top => 0;
[Obsolete ("This API is deprecated", false)]
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
[Obsolete ("This API is deprecated", false)]
public override bool HeightAsBuffer { get; set; }
public override IClipboard Clipboard { get => clipboard; }

CursorVisibility? initialCursorVisibility = null;
Expand Down
56 changes: 18 additions & 38 deletions Terminal.Gui/ConsoleDrivers/FakeDriver/FakeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ 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;
[Obsolete ("This API is deprecated", false)]
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
[Obsolete ("This API is deprecated", false)]
public override bool HeightAsBuffer { get; set; }
private IClipboard clipboard = null;
public override IClipboard Clipboard => clipboard;

Expand Down Expand Up @@ -537,31 +535,24 @@ public void SetBufferSize (int width, int height)
FakeConsole.SetBufferSize (width, height);
cols = width;
rows = height;
if (!EnableConsoleScrolling) {
SetWindowSize (width, height);
}
SetWindowSize (width, height);
ProcessResize ();
}

public void SetWindowSize (int width, int height)
{
FakeConsole.SetWindowSize (width, height);
if (!EnableConsoleScrolling) {
if (width != cols || height != rows) {
SetBufferSize (width, height);
cols = width;
rows = height;
}
if (width != cols || height != rows) {
SetBufferSize (width, height);
cols = width;
rows = height;
}
ProcessResize ();
}

public void SetWindowPosition (int left, int top)
{
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) {
if (this.left > 0 || this.top > 0) {
this.left = 0;
this.top = 0;
}
Expand All @@ -577,29 +568,18 @@ void ProcessResize ()

public override void ResizeScreen ()
{
if (!EnableConsoleScrolling) {
if (FakeConsole.WindowHeight > 0) {
// Can raise an exception while is still resizing.
try {
#pragma warning disable CA1416
FakeConsole.CursorTop = 0;
FakeConsole.CursorLeft = 0;
FakeConsole.WindowTop = 0;
FakeConsole.WindowLeft = 0;
#pragma warning restore CA1416
} catch (System.IO.IOException) {
return;
} catch (ArgumentOutOfRangeException) {
return;
}
}
} else {
if (FakeConsole.WindowHeight > 0) {
// Can raise an exception while is still resizing.
try {
#pragma warning disable CA1416
FakeConsole.WindowLeft = Math.Max (Math.Min (left, Cols - FakeConsole.WindowWidth), 0);
FakeConsole.WindowTop = Math.Max (Math.Min (top, Rows - FakeConsole.WindowHeight), 0);
FakeConsole.CursorTop = 0;
FakeConsole.CursorLeft = 0;
FakeConsole.WindowTop = 0;
FakeConsole.WindowLeft = 0;
#pragma warning restore CA1416
} catch (Exception) {
} catch (System.IO.IOException) {
return;
} catch (ArgumentOutOfRangeException) {
return;
}
}
Expand Down
127 changes: 29 additions & 98 deletions Terminal.Gui/ConsoleDrivers/NetDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ internal class NetEvents {
ConsoleDriver consoleDriver;
volatile ConsoleKeyInfo [] cki = null;
static volatile bool isEscSeq;
int lastWindowHeight;
bool stopTasks;
#if PROCESS_REQUEST
bool neededProcessRequest;
Expand Down Expand Up @@ -251,21 +250,11 @@ void WaitWinChange ()

bool IsWinChanged (int winHeight, int winWidth, int buffHeight, int buffWidth)
{
if (!consoleDriver.EnableConsoleScrolling) {
if (winWidth != consoleDriver.Cols || winHeight != consoleDriver.Rows) {
var w = Math.Max (winWidth, 0);
var h = Math.Max (winHeight, 0);
GetWindowSizeEvent (new Size (w, h));
return true;
}
} else {
if (winWidth != consoleDriver.Cols || winHeight != lastWindowHeight
|| buffWidth != consoleDriver.Cols || buffHeight != consoleDriver.Rows) {

lastWindowHeight = Math.Max (winHeight, 0);
GetWindowSizeEvent (new Size (winWidth, lastWindowHeight));
return true;
}
if (winWidth != consoleDriver.Cols || winHeight != consoleDriver.Rows) {
var w = Math.Max (winWidth, 0);
var h = Math.Max (winHeight, 0);
GetWindowSizeEvent (new Size (w, h));
return true;
}
return false;
}
Expand Down Expand Up @@ -584,20 +573,15 @@ internal class NetDriver : ConsoleDriver {
public override int Rows => rows;
public override int Left => left;
public override int Top => top;
[Obsolete ("This API is deprecated", false)]
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}

[Obsolete ("This API is deprecated", false)]
public override bool HeightAsBuffer { get; set; }
public NetWinVTConsole NetWinConsole { get; }
public bool IsWinPlatform { get; }
public override IClipboard Clipboard { get; }
public override int [,,] Contents => contents;

int largestBufferHeight;

public NetDriver ()
{
var p = Environment.OSVersion.Platform;
Expand Down Expand Up @@ -752,14 +736,8 @@ public override void Init (Action terminalResized)

Console.TreatControlCAsInput = true;

if (EnableConsoleScrolling) {
largestBufferHeight = Console.BufferHeight;
} else {
largestBufferHeight = Console.WindowHeight;
}

cols = Console.WindowWidth;
rows = largestBufferHeight;
rows = Console.WindowHeight;

CurrentAttribute = MakeColor (Color.White, Color.Black);
InitalizeColorSchemes ();
Expand All @@ -775,54 +753,31 @@ public override void Init (Action terminalResized)

public override void ResizeScreen ()
{
if (!EnableConsoleScrolling) {
if (Console.WindowHeight > 0) {
// Not supported on Unix.
if (IsWinPlatform) {
// Can raise an exception while is still resizing.
try {
#pragma warning disable CA1416
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.WindowTop = 0;
Console.WindowLeft = 0;
if (Console.WindowHeight > Rows) {
Console.SetWindowSize (Cols, Rows);
}
Console.SetBufferSize (Cols, Rows);
#pragma warning restore CA1416
} catch (System.IO.IOException) {
setClip ();
} catch (ArgumentOutOfRangeException) {
setClip ();
}
} else {
Console.Out.Write ($"\x1b[8;{Rows};{Cols}t");
}
}
} else {
if (Console.WindowHeight > 0) {
// Not supported on Unix.
if (IsWinPlatform) {
if (Console.WindowHeight > 0) {
// Can raise an exception while is still resizing.
try {
// Can raise an exception while is still resizing.
try {
#pragma warning disable CA1416
Console.CursorTop = 0;
Console.CursorLeft = 0;
if (Console.WindowHeight > Rows) {
Console.SetWindowSize (Cols, Rows);
}
Console.SetBufferSize (Cols, Rows);
#pragma warning restore CA1416
} catch (System.IO.IOException) {
setClip ();
} catch (ArgumentOutOfRangeException) {
setClip ();
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.WindowTop = 0;
Console.WindowLeft = 0;
if (Console.WindowHeight > Rows) {
Console.SetWindowSize (Cols, Rows);
}
Console.SetBufferSize (Cols, Rows);
#pragma warning restore CA1416
} catch (System.IO.IOException) {
setClip ();
} catch (ArgumentOutOfRangeException) {
setClip ();
}
} else {
Console.Out.Write ($"\x1b[30;{Rows};{Cols}t");
Console.Out.Write ($"\x1b[8;{Rows};{Cols}t");
}
}

setClip ();

void setClip ()
Expand Down Expand Up @@ -864,9 +819,7 @@ public override void Refresh ()

public override void UpdateScreen ()
{
if (winChanging || Console.WindowHeight < 1 || contents.Length != Rows * Cols * 3
|| (!EnableConsoleScrolling && Rows != Console.WindowHeight)
|| (EnableConsoleScrolling && Rows != largestBufferHeight)) {
if (winChanging || Console.WindowHeight < 1 || contents.Length != Rows * Cols * 3 || Rows != Console.WindowHeight) {
return;
}

Expand Down Expand Up @@ -1021,23 +974,6 @@ bool SetCursorPosition (int col, int row)

private void SetWindowPosition (int col, int row)
{
if (IsWinPlatform && EnableConsoleScrolling) {
var winTop = Math.Max (Rows - Console.WindowHeight - row, 0);
winTop = Math.Min (winTop, Rows - Console.WindowHeight + 1);
winTop = Math.Max (winTop, 0);
if (winTop != Console.WindowTop) {
try {
if (!EnsureBufferSize ()) {
return;
}
#pragma warning disable CA1416
Console.SetWindowPosition (col, winTop);
#pragma warning restore CA1416
} catch (System.IO.IOException) {

} catch (System.ArgumentOutOfRangeException) { }
}
}
top = Console.WindowTop;
left = Console.WindowLeft;
}
Expand Down Expand Up @@ -1287,15 +1223,10 @@ void ProcessInput (NetEvents.InputResult inputEvent)
void ChangeWin (Size size)
{
winChanging = true;
if (!EnableConsoleScrolling) {
largestBufferHeight = Math.Max (size.Height, 0);
} else {
largestBufferHeight = Math.Max (size.Height, largestBufferHeight);
}
top = 0;
left = 0;
cols = size.Width;
rows = largestBufferHeight;
rows = Math.Max (size.Height, 0);
ResizeScreen ();
UpdateOffScreen ();
winChanging = false;
Expand Down
8 changes: 3 additions & 5 deletions Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,12 +714,10 @@ internal class WindowsDriver : ConsoleDriver {
public override int Rows => rows;
public override int Left => left;
public override int Top => top;
[Obsolete ("This API is deprecated", false)]
public override bool EnableConsoleScrolling { get; set; }
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public override bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
[Obsolete ("This API is deprecated", false)]
public override bool HeightAsBuffer { get; set; }
public override IClipboard Clipboard => clipboard;
public override int [,,] Contents => contents;

Expand Down
31 changes: 6 additions & 25 deletions Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ public static Toplevel MdiTop {
/// </summary>
public static View WantContinuousButtonPressedView { get; private set; }

private static bool? _enableConsoleScrolling;

/// <summary>
/// The current <see cref="ConsoleDriver.EnableConsoleScrolling"/> used in the terminal.
/// </summary>
Expand All @@ -128,32 +126,17 @@ public static Toplevel MdiTop {
/// In this case console scrolling is enabled and the contents (<see cref="ConsoleDriver.Rows"/> high) will scroll
/// as the console scrolls.
/// </para>
/// This API was previously named 'HeightAsBuffer` but was renamed to make its purpose more clear.
/// <para>This API is deprecated and has no impact when enabled.</para>
/// <para>This API was previously named 'HeightAsBuffer` but was renamed to make its purpose more clear.</para>
/// </remarks>
public static bool EnableConsoleScrolling {
get {
if (Driver == null) {
return _enableConsoleScrolling.HasValue && _enableConsoleScrolling.Value;
}
return Driver.EnableConsoleScrolling;
}
set {
_enableConsoleScrolling = value;
if (Driver == null) {
return;
}
Driver.EnableConsoleScrolling = value;
}
}
[Obsolete ("This API is deprecated and has no impact when enabled.", false)]
public static bool EnableConsoleScrolling { get; set; }

/// <summary>
/// This API is deprecated; use <see cref="EnableConsoleScrolling"/> instead.
/// </summary>
[Obsolete ("This API is deprecated; use EnableConsoleScrolling instead.", false)]
public static bool HeightAsBuffer {
get => EnableConsoleScrolling;
set => EnableConsoleScrolling = value;
}
[Obsolete ("This API is deprecated and has no impact when enabled.", false)]
public static bool HeightAsBuffer { get; set; }

static Key alternateForwardKey = Key.PageDown | Key.CtrlMask;

Expand Down Expand Up @@ -449,7 +432,6 @@ internal static void InternalInit (Func<Toplevel> topLevelFactory, ConsoleDriver
MainLoop = new MainLoop (mainLoopDriver);

try {
Driver.EnableConsoleScrolling = EnableConsoleScrolling;
Driver.Init (TerminalResized);
} catch (InvalidOperationException ex) {
// This is a case where the driver is unable to initialize the console.
Expand Down Expand Up @@ -1125,7 +1107,6 @@ static void ResetState ()
NotifyStopRunState = null;
_initialized = false;
mouseGrabView = null;
_enableConsoleScrolling = false;

// Reset synchronization context to allow the user to run async/await,
// as the main loop has been ended, the synchronization context from
Expand Down
Loading

0 comments on commit 7ef51ba

Please sign in to comment.