Make IConsoleDriver.Rows and Cols read-only - WIP

- Removed setters from IConsoleDriver.Rows and Cols
- Made ConsoleDriver._cols and _rows protected so FakeDriver can access them
- Updated FakeDriver to set _cols and _rows directly instead of using properties
- Updated ConsoleDriver properties to be read-only
- Updated ConsoleDriverFacade to have read-only Cols/Rows
- Screen now references _cols and _rows directly

Still need to fix test files that try to set Rows/Cols directly (14 errors remaining)

Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-10-26 21:42:16 +00:00
parent c4a73d71c7
commit 82e28d1a4f
4 changed files with 16 additions and 41 deletions

View File

@@ -58,7 +58,7 @@ public abstract class ConsoleDriver : IConsoleDriver
// QUESTION: When non-full screen apps are supported, will this represent the app size, or will that be in Application?
/// <summary>Gets the location and size of the terminal screen.</summary>
public Rectangle Screen => new (0, 0, Cols, Rows);
public Rectangle Screen => new (0, 0, _cols, _rows);
private Region? _clip;
@@ -94,15 +94,7 @@ public abstract class ConsoleDriver : IConsoleDriver
public int Col { get; private set; }
/// <summary>The number of columns visible in the terminal.</summary>
public virtual int Cols
{
get => _cols;
set
{
_cols = value;
ClearContents ();
}
}
public virtual int Cols => _cols;
/// <summary>
/// The contents of the application output. The driver outputs this buffer to the terminal when
@@ -158,15 +150,7 @@ public abstract class ConsoleDriver : IConsoleDriver
public int Row { get; private set; }
/// <summary>The number of rows visible in the terminal.</summary>
public virtual int Rows
{
get => _rows;
set
{
_rows = value;
ClearContents ();
}
}
public virtual int Rows => _rows;
/// <summary>The topmost row in the terminal.</summary>
public virtual int Top { get; set; } = 0;
@@ -580,8 +564,8 @@ public abstract class ConsoleDriver : IConsoleDriver
set => Application.Force16Colors = value || !SupportsTrueColor;
}
private int _cols;
private int _rows;
protected int _cols;
protected int _rows;
/// <summary>
/// The <see cref="Attribute"/> that will be used for the next <see cref="AddRune(Rune)"/> or <see cref="AddStr"/>

View File

@@ -113,11 +113,7 @@ internal class ConsoleDriverFacade<T> : IConsoleDriver, IConsoleDriverFacade
public int Col => _outputBuffer.Col;
/// <summary>The number of columns visible in the terminal.</summary>
public int Cols
{
get => _outputBuffer.Cols;
set => _outputBuffer.Cols = value;
}
public int Cols => _outputBuffer.Cols;
/// <summary>
/// The contents of the application output. The driver outputs this buffer to the terminal.
@@ -143,11 +139,7 @@ internal class ConsoleDriverFacade<T> : IConsoleDriver, IConsoleDriverFacade
public int Row => _outputBuffer.Row;
/// <summary>The number of rows visible in the terminal.</summary>
public int Rows
{
get => _outputBuffer.Rows;
set => _outputBuffer.Rows = value;
}
public int Rows => _outputBuffer.Rows;
/// <summary>The topmost row in the terminal.</summary>
public int Top

View File

@@ -51,8 +51,8 @@ public class FakeDriver : ConsoleDriver
// FakeDriver implies UnitTests
RunningUnitTests = true;
base.Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
base.Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
_cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
_rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
if (FakeBehaviors.UseFakeClipboard)
{
@@ -95,8 +95,8 @@ public class FakeDriver : ConsoleDriver
{
FakeConsole.MockKeyPresses.Clear ();
Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
_cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
_rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
FakeConsole.Clear ();
ResizeScreen ();
CurrentAttribute = new Attribute (Color.White, Color.Black);
@@ -387,8 +387,9 @@ public class FakeDriver : ConsoleDriver
public void SetBufferSize (int width, int height)
{
FakeConsole.SetBufferSize (width, height);
Cols = width;
Rows = height;
_cols = width;
_rows = height;
ClearContents ();
SetWindowSize (width, height);
ProcessResize ();
}
@@ -400,8 +401,6 @@ public class FakeDriver : ConsoleDriver
if (width != Cols || height != Rows)
{
SetBufferSize (width, height);
Cols = width;
Rows = height;
}
ProcessResize ();

View File

@@ -29,7 +29,7 @@ public interface IConsoleDriver
int Col { get; }
/// <summary>The number of columns visible in the terminal.</summary>
int Cols { get; set; }
int Cols { get; }
// BUGBUG: This should not be publicly settable.
/// <summary>
@@ -48,7 +48,7 @@ public interface IConsoleDriver
int Row { get; }
/// <summary>The number of rows visible in the terminal.</summary>
int Rows { get; set; }
int Rows { get; }
/// <summary>The topmost row in the terminal.</summary>
int Top { get; set; }