Refactor Force16Colors and ForceDriver according to requirements

- Created new public Driver class in Terminal.Gui.Drivers namespace to hold Force16Colors static property
- Removed Force16Colors from Application and IApplication
- Modified DriverImpl to read Force16Colors at construction time and store in instance field
- Added GetForce16Colors() method to IDriver interface
- Made ForceDriver get-only on IApplication (setter remains on Application static class)
- Updated all references to use Driver.Force16Colors instead of Application.Force16Colors
- Updated Output classes (FakeOutput, NetOutput, UnixOutput) to use Driver.Force16Colors
- Updated ApplicationImpl to reset Driver.Force16Colors instead of Application.Force16Colors
- Fixed tests to use Application.ForceDriver setter instead of IApplication.ForceDriver

Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-05 04:48:24 +00:00
parent f69082ab90
commit f1394366b7
20 changed files with 92 additions and 79 deletions

View File

@@ -186,11 +186,11 @@ public class ColorPickers : Scenario
{
X = Pos.Right (cbSupportsTrueColor) + 1,
Y = Pos.Top (lblDriverName),
CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
CheckedState = Terminal.Gui.Drivers.Driver.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
Enabled = canTrueColor,
Text = "Force16Colors"
};
cbUseTrueColor.CheckedStateChanging += (_, evt) => { Application.Force16Colors = evt.Result == CheckState.Checked; };
cbUseTrueColor.CheckedStateChanging += (_, evt) => { Terminal.Gui.Drivers.Driver.Force16Colors = evt.Result == CheckState.Checked; };
app.Add (lblDriverName, cbSupportsTrueColor, cbUseTrueColor);
// Set default colors.

View File

@@ -122,11 +122,11 @@ public class Images : Scenario
{
X = Pos.Right (cbSupportsTrueColor) + 2,
Y = 0,
CheckedState = !Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
CheckedState = !Terminal.Gui.Drivers.Driver.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
Enabled = canTrueColor,
Text = "Use true color"
};
cbUseTrueColor.CheckedStateChanging += (_, evt) => Application.Force16Colors = evt.Result == CheckState.UnChecked;
cbUseTrueColor.CheckedStateChanging += (_, evt) => Terminal.Gui.Drivers.Driver.Force16Colors = evt.Result == CheckState.UnChecked;
_win.Add (cbUseTrueColor);
var btnOpenImage = new Button { X = Pos.Right (cbUseTrueColor) + 2, Y = 0, Text = "Open Image" };

View File

@@ -133,14 +133,14 @@ public class LineDrawing : Scenario
var d = new Dialog
{
Title = title,
Width = Application.Force16Colors ? 35 : Dim.Auto (DimAutoStyle.Auto, Dim.Percent (80), Dim.Percent (90)),
Width = Terminal.Gui.Drivers.Driver.Force16Colors ? 35 : Dim.Auto (DimAutoStyle.Auto, Dim.Percent (80), Dim.Percent (90)),
Height = 10
};
var btnOk = new Button
{
X = Pos.Center () - 5,
Y = Application.Force16Colors ? 6 : 4,
Y = Terminal.Gui.Drivers.Driver.Force16Colors ? 6 : 4,
Text = "Ok",
Width = Dim.Auto (),
IsDefault = true
@@ -174,7 +174,7 @@ public class LineDrawing : Scenario
d.AddButton (btnCancel);
View cp;
if (Application.Force16Colors)
if (Terminal.Gui.Drivers.Driver.Force16Colors)
{
cp = new ColorPicker16
{
@@ -197,7 +197,7 @@ public class LineDrawing : Scenario
Application.Run (d);
d.Dispose ();
newColor = Application.Force16Colors ? ((ColorPicker16)cp).SelectedColor : ((ColorPicker)cp).SelectedColor;
newColor = Terminal.Gui.Drivers.Driver.Force16Colors ? ((ColorPicker16)cp).SelectedColor : ((ColorPicker)cp).SelectedColor;
return accept;
}

View File

@@ -176,7 +176,7 @@ public class UICatalogRunnable : Runnable
_force16ColorsMenuItemCb = new ()
{
Title = "Force _16 Colors",
CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
CheckedState = Terminal.Gui.Drivers.Driver.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
// Best practice for CheckBoxes in menus is to disable focus and highlight states
CanFocus = false,
HighlightStates = MouseState.None
@@ -184,7 +184,7 @@ public class UICatalogRunnable : Runnable
_force16ColorsMenuItemCb.CheckedStateChanging += (sender, args) =>
{
if (Application.Force16Colors
if (Terminal.Gui.Drivers.Driver.Force16Colors
&& args.Result == CheckState.UnChecked
&& !Application.Driver!.SupportsTrueColor)
{
@@ -194,7 +194,7 @@ public class UICatalogRunnable : Runnable
_force16ColorsMenuItemCb.CheckedStateChanged += (sender, args) =>
{
Application.Force16Colors = args.Value == CheckState.Checked;
Terminal.Gui.Drivers.Driver.Force16Colors = args.Value == CheckState.Checked;
_force16ColorsShortcutCb!.CheckedState = args.Value;
Application.LayoutAndDraw ();
@@ -646,13 +646,13 @@ public class UICatalogRunnable : Runnable
_force16ColorsShortcutCb = new ()
{
Title = "16 color mode",
CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
CheckedState = Terminal.Gui.Drivers.Driver.Force16Colors ? CheckState.Checked : CheckState.UnChecked,
CanFocus = false
};
_force16ColorsShortcutCb.CheckedStateChanging += (sender, args) =>
{
if (Application.Force16Colors
if (Terminal.Gui.Drivers.Driver.Force16Colors
&& args.Result == CheckState.UnChecked
&& !Application.Driver!.SupportsTrueColor)
{
@@ -663,7 +663,7 @@ public class UICatalogRunnable : Runnable
_force16ColorsShortcutCb.CheckedStateChanged += (sender, args) =>
{
Application.Force16Colors = args.Value == CheckState.Checked;
Terminal.Gui.Drivers.Driver.Force16Colors = args.Value == CheckState.Checked;
_force16ColorsMenuItemCb!.CheckedState = args.Value;
Application.LayoutAndDraw ();
};
@@ -714,7 +714,7 @@ public class UICatalogRunnable : Runnable
}
_disableMouseCb!.CheckedState = Application.IsMouseDisabled ? CheckState.Checked : CheckState.UnChecked;
_force16ColorsShortcutCb!.CheckedState = Application.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
_force16ColorsShortcutCb!.CheckedState = Terminal.Gui.Drivers.Driver.Force16Colors ? CheckState.Checked : CheckState.UnChecked;
Application.TopRunnableView?.SetNeedsDraw ();
}