From 82e28d1a4ff9ab6d6e460793ca44370a9f97e0a3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 26 Oct 2025 21:42:16 +0000
Subject: [PATCH] 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>
---
Terminal.Gui/Drivers/ConsoleDriver.cs | 26 ++++---------------
Terminal.Gui/Drivers/ConsoleDriverFacade.cs | 12 ++-------
Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs | 15 +++++------
Terminal.Gui/Drivers/IConsoleDriver.cs | 4 +--
4 files changed, 16 insertions(+), 41 deletions(-)
diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs
index 81bb460fc..e1db1616e 100644
--- a/Terminal.Gui/Drivers/ConsoleDriver.cs
+++ b/Terminal.Gui/Drivers/ConsoleDriver.cs
@@ -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?
/// Gets the location and size of the terminal screen.
- 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; }
/// The number of columns visible in the terminal.
- public virtual int Cols
- {
- get => _cols;
- set
- {
- _cols = value;
- ClearContents ();
- }
- }
+ public virtual int Cols => _cols;
///
/// 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; }
/// The number of rows visible in the terminal.
- public virtual int Rows
- {
- get => _rows;
- set
- {
- _rows = value;
- ClearContents ();
- }
- }
+ public virtual int Rows => _rows;
/// The topmost row in the terminal.
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;
///
/// The that will be used for the next or
diff --git a/Terminal.Gui/Drivers/ConsoleDriverFacade.cs b/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
index 36a80ba62..f2b7eb846 100644
--- a/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
+++ b/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
@@ -113,11 +113,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
public int Col => _outputBuffer.Col;
/// The number of columns visible in the terminal.
- public int Cols
- {
- get => _outputBuffer.Cols;
- set => _outputBuffer.Cols = value;
- }
+ public int Cols => _outputBuffer.Cols;
///
/// The contents of the application output. The driver outputs this buffer to the terminal.
@@ -143,11 +139,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
public int Row => _outputBuffer.Row;
/// The number of rows visible in the terminal.
- public int Rows
- {
- get => _outputBuffer.Rows;
- set => _outputBuffer.Rows = value;
- }
+ public int Rows => _outputBuffer.Rows;
/// The topmost row in the terminal.
public int Top
diff --git a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
index 9026a71bf..f3df3cb79 100644
--- a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
+++ b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
@@ -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 ();
diff --git a/Terminal.Gui/Drivers/IConsoleDriver.cs b/Terminal.Gui/Drivers/IConsoleDriver.cs
index ee01f6d21..5ab198f70 100644
--- a/Terminal.Gui/Drivers/IConsoleDriver.cs
+++ b/Terminal.Gui/Drivers/IConsoleDriver.cs
@@ -29,7 +29,7 @@ public interface IConsoleDriver
int Col { get; }
/// The number of columns visible in the terminal.
- int Cols { get; set; }
+ int Cols { get; }
// BUGBUG: This should not be publicly settable.
///
@@ -48,7 +48,7 @@ public interface IConsoleDriver
int Row { get; }
/// The number of rows visible in the terminal.
- int Rows { get; set; }
+ int Rows { get; }
/// The topmost row in the terminal.
int Top { get; set; }