Skip to content

Commit 8535266

Browse files
committed
Migrate Terminal theme and tests added on main to Terminal.Gui 2.4.5
Rebasing onto main brought in the Terminal theme (#176) and its tests, which were written against Terminal.Gui 2.0: - TerminalTheme: ColorScheme -> Scheme; drop the local Attribute alias now provided by GlobalUsings. - ThemeManager: Application.Force16Colors no longer exists as a static; set the flag on Application.Driver only. - ThemeManagerTests: assert UseTerminalColors on the theme since the driver (which now owns Force16Colors) is null in headless tests. - ThemeSchemeTests: ThemeStyler.ApplyTo was dropped in favour of main's leaner surface (#177); test ApplyToFrame instead.
1 parent 0df8e36 commit 8535266

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

App/Themes/TerminalTheme.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Terminal.Gui;
2-
using Attribute = Terminal.Gui.Attribute;
32

43
namespace Opcilloscope.App.Themes;
54

@@ -82,10 +81,10 @@ public class TerminalTheme : AppTheme
8281

8382
// Override color schemes - focus highlight uses a DarkGray band since
8483
// panel-background shades are not available in the 16-color palette
85-
private ColorScheme? _mainColorScheme;
86-
private ColorScheme? _menuColorScheme;
84+
private Scheme? _mainColorScheme;
85+
private Scheme? _menuColorScheme;
8786

88-
public override ColorScheme MainColorScheme => _mainColorScheme ??= new()
87+
public override Scheme MainColorScheme => _mainColorScheme ??= new()
8988
{
9089
Normal = NormalAttr,
9190
Focus = new Attribute(ForegroundBright, new Color(ColorName16.DarkGray)),
@@ -94,7 +93,7 @@ public class TerminalTheme : AppTheme
9493
Disabled = new Attribute(StatusInactive, Background)
9594
};
9695

97-
public override ColorScheme MenuColorScheme => _menuColorScheme ??= new()
96+
public override Scheme MenuColorScheme => _menuColorScheme ??= new()
9897
{
9998
Normal = NormalAttr,
10099
Focus = new Attribute(Background, Foreground), // Inverted for menu focus

App/Themes/ThemeManager.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ public static void SetTheme(AppTheme theme)
8282
/// </summary>
8383
private static void ApplyTerminalColorMode(AppTheme theme)
8484
{
85-
Application.Force16Colors = theme.UseTerminalColors;
86-
87-
// The v2 facade driver caches its own flag rather than reading
88-
// Application.Force16Colors, so propagate explicitly when running
85+
// Terminal.Gui 2.4 removed the static Application.Force16Colors;
86+
// the flag now lives on the driver itself.
8987
if (Application.Driver is { } driver)
9088
{
9189
driver.Force16Colors = theme.UseTerminalColors;

Tests/Opcilloscope.Tests/App/ThemeManagerTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,25 @@ public void ThemeManager_SetThemeByName_WithInvalidName_DoesNothing()
123123
}
124124

125125
[Fact]
126-
public void ThemeManager_SetTerminalTheme_TogglesForce16Colors()
126+
public void ThemeManager_SetTerminalTheme_TogglesTerminalColorMode()
127127
{
128+
// Terminal.Gui 2.4 removed the static Application.Force16Colors; the flag now
129+
// lives on Application.Driver, which is null in headless tests. Assert on the
130+
// theme property that ThemeManager propagates to the driver when one exists.
128131
try
129132
{
130133
// Act - Terminal theme enables 16-color ANSI output
131134
ThemeManager.SetTheme("Terminal");
132135

133136
// Assert
134137
Assert.IsType<TerminalTheme>(ThemeManager.Current);
135-
Assert.True(Terminal.Gui.Application.Force16Colors);
138+
Assert.True(ThemeManager.Current.UseTerminalColors);
136139

137140
// Act - switching back restores 24-bit color output
138141
ThemeManager.SetTheme("Dark");
139142

140143
// Assert
141-
Assert.False(Terminal.Gui.Application.Force16Colors);
144+
Assert.False(ThemeManager.Current.UseTerminalColors);
142145
}
143146
finally
144147
{

Tests/Opcilloscope.Tests/Tui/ThemeSchemeTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public void ButtonScheme_IsADistinctScheme(AppTheme theme)
3838
}
3939

4040
[Fact]
41-
public void ThemeStyler_ApplyTo_SetsTheViewScheme()
41+
public void ThemeStyler_ApplyToFrame_SetsTheViewScheme()
4242
{
4343
var theme = new DarkTheme();
44-
var view = new View();
44+
var view = new FrameView();
4545

46-
ThemeStyler.ApplyTo(view, theme);
46+
ThemeStyler.ApplyToFrame(view, theme);
4747

4848
Scheme? applied = view.GetScheme();
4949
Assert.NotNull(applied);

0 commit comments

Comments
 (0)