mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-29 17:28:01 +01:00
Revert GetWindowSize and add SetWindowSize
This commit is contained in:
@@ -23,9 +23,15 @@ public interface IConsoleOutput : IDisposable
|
||||
/// Returns the current size of the console window in rows/columns (i.e.
|
||||
/// of characters not pixels).
|
||||
/// </summary>
|
||||
/// <param name="lastSize"></param>
|
||||
/// <returns></returns>
|
||||
public Size GetWindowSize (Size? lastSize = null);
|
||||
public Size GetWindowSize ();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the current size of the console window in rows/columns
|
||||
/// </summary>
|
||||
/// <param name="newSize"></param>
|
||||
/// /// <returns></returns>
|
||||
public Size SetWindowSize (Size newSize);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the console cursor (the blinking underscore) to be hidden,
|
||||
|
||||
@@ -202,7 +202,7 @@ public class NetOutput : IConsoleOutput
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Size GetWindowSize (Size? lastSize = null)
|
||||
public Size GetWindowSize ()
|
||||
{
|
||||
if (ConsoleDriver.RunningUnitTests)
|
||||
{
|
||||
@@ -213,6 +213,12 @@ public class NetOutput : IConsoleOutput
|
||||
return new (Console.WindowWidth, Console.WindowHeight);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Size SetWindowSize (Size newSize)
|
||||
{
|
||||
return newSize;
|
||||
}
|
||||
|
||||
private void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
|
||||
{
|
||||
SetCursorPositionImpl (lastCol, row);
|
||||
|
||||
@@ -25,14 +25,21 @@ internal class WindowSizeMonitor : IWindowSizeMonitor
|
||||
return false;
|
||||
}
|
||||
|
||||
Size size = _consoleOut.GetWindowSize (_lastSize);
|
||||
Size size = _consoleOut.GetWindowSize ();
|
||||
|
||||
if (size != _lastSize)
|
||||
{
|
||||
Logging.Logger.LogInformation ($"Console size changes from '{_lastSize}' to {size}");
|
||||
_outputBuffer.SetWindowSize (size.Width, size.Height);
|
||||
_lastSize = size;
|
||||
SizeChanging?.Invoke (this, new (size));
|
||||
Size newSize = size;
|
||||
|
||||
if (_consoleOut.GetType().Name == "WindowsOutput")
|
||||
{
|
||||
newSize = _consoleOut.SetWindowSize (size);
|
||||
}
|
||||
|
||||
_outputBuffer.SetWindowSize (newSize.Width, newSize.Height);
|
||||
_lastSize = newSize;
|
||||
SizeChanging?.Invoke (this, new (newSize));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ internal partial class WindowsOutput : IConsoleOutput
|
||||
return result;
|
||||
}
|
||||
|
||||
public Size GetWindowSize (Size? lastSize = null)
|
||||
public Size GetWindowSize ()
|
||||
{
|
||||
var csbi = new WindowsConsole.CONSOLE_SCREEN_BUFFER_INFOEX ();
|
||||
csbi.cbSize = (uint)Marshal.SizeOf (csbi);
|
||||
@@ -481,17 +481,19 @@ internal partial class WindowsOutput : IConsoleOutput
|
||||
csbi.srWindow.Right - csbi.srWindow.Left + 1,
|
||||
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
|
||||
|
||||
if (lastSize is { } && sz != lastSize)
|
||||
{
|
||||
Size newSize = SetConsoleWindow ((short)sz.Width, (short)sz.Height);
|
||||
return sz;
|
||||
}
|
||||
|
||||
if (sz != newSize)
|
||||
{
|
||||
return newSize;
|
||||
}
|
||||
public Size SetWindowSize (Size newSize)
|
||||
{
|
||||
Size resSize = SetConsoleWindow ((short)newSize.Width, (short)newSize.Height);
|
||||
|
||||
if (resSize != newSize)
|
||||
{
|
||||
return resSize;
|
||||
}
|
||||
|
||||
return sz;
|
||||
return newSize;
|
||||
}
|
||||
|
||||
private Size SetConsoleWindow (short cols, short rows)
|
||||
|
||||
@@ -17,7 +17,10 @@ internal class FakeOutput : IConsoleOutput
|
||||
public void Write (IOutputBuffer buffer) { LastBuffer = buffer; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Size GetWindowSize (Size? lastSize = null) { return Size; }
|
||||
public Size GetWindowSize () { return Size; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public Size SetWindowSize (Size newSize) { return newSize; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void SetCursorVisibility (CursorVisibility visibility) { }
|
||||
|
||||
@@ -19,7 +19,7 @@ public class WindowSizeMonitorTests
|
||||
|
||||
});
|
||||
|
||||
consoleOutput.Setup (m => m.GetWindowSize (null))
|
||||
consoleOutput.Setup (m => m.GetWindowSize ())
|
||||
.Returns (queue.Dequeue);
|
||||
|
||||
var outputBuffer = Mock.Of<IOutputBuffer> ();
|
||||
@@ -52,7 +52,7 @@ public class WindowSizeMonitorTests
|
||||
new Size (30, 20),
|
||||
});
|
||||
|
||||
consoleOutput.Setup (m => m.GetWindowSize (null))
|
||||
consoleOutput.Setup (m => m.GetWindowSize ())
|
||||
.Returns (queue.Dequeue);
|
||||
|
||||
var outputBuffer = Mock.Of<IOutputBuffer> ();
|
||||
|
||||
Reference in New Issue
Block a user