mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
Fixes #4057 - MASSIVE! Fully implements ColorScheme->Scheme + VisualRole + Colors.->SchemeManager. (#4062)
* touching publish.yml * ColorScheme->Scheme * ColorScheme->Scheme 2 * Prototype of GetAttributeForRole * Badly broke CM * Further Badly broke CM * Refactored CM big-time. View still broken * All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Actually: All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Bug fixes. DeepMemberWiseClone cleanup * Further cleanup of Scope<T>, ConfigProperty, etc. * Made ConfigManager thread safe. * WIP: Broken * WIP: new deep clone impl * WIP: new deep clone impl is done. Now fixing CM * WIP: - config.md - Working on AOT clean up - Core CM is broken; but known. * WIP * Merged. Removed CM from Application.Init * WIP * More WIP; Less broke * All CM unit tests pass... Not sure if it actually works though * All unit tests pass... Themes are broken though in UI Cat * CM Ready for review? * Fixed failures due to TextStyles PR * Working on Scheme/Attribute * Working on Scheme/Attribute 2 * Working on Scheme/Attribute 3 * Working on Scheme/Attribute 4 * Working on Scheme/Attribute 5 * Working on Scheme/Attribute 6 * Added test to show how awful memory usage is * Improved schema. Updated config.json * Nade Scope<T> concurrentdictionary and added test to prove * Made Themes ConcrurrentDictionary. Added bunches of tests * Code cleanup * Code cleanup 2 * Code cleanup 3 * Tweaking Scheme * ClearJsonErrors * ClearJsonErrors2 * Updated Attribute API * It all (mostly) works! * Skip odd unit test * Messed with Themes * Theme tweaks * Code reorg. New .md stuff * Fixed Enabled. Added mock driver * Fixed a bunch of View.Enabled related issues * Scheme -> Get/SetScheme() * Cleanup * Cleanup2 * Broke something * Fixed everything * Made CM.Enable better * Text Style Scenario * Added comments * Fixed UI Catalog Theme Changing * Fixed more dynamic CM update stuff * Warning cleanup * New Default Theme * fixed unit test * Refactoring Scheme and Attribute to fix inheritance * more unit tests * ConfigProperty is not updating schemes correctly * All unit tests pass. Code cleanup * All unit tests pass. Code cleanup2 * Fixed unit tests * Upgraded TextField and TextView * Fixed TextView !Enabled bug * More updates to TextView. More unit tests for SchemeManager * Upgraded CharMap * API docs * Fixe HexView API * upgrade HexView * Fixed shortcut KeyView * Fixed more bugs. Added new themes * updated themes * upgraded Border * Fixed themes memory usage...mostly * Fixed themes memory usage...mostly2 * Fixed themes memory usage...2 * Fixed themes memory usage...3 * Added new colors * Fixed GetHardCodedConfig bug * Added Themes Scenario - WIP * Added Themes Scenario * Tweaked Themes Scenario * Code cleanup * Fixed json schmea * updated deepdives * updated deepdives * Tweaked Themes Scenario * Made Schemes a concurrent dict * Test cleanup * Thread safe ConfigProperty tests * trying to make things more thread safe * more trying to make things more thread safe * Fixing bugs in shadowview * Fixing bugs in shadowview 2 * Refactored GetViewsUnderMouse to GetViewsUnderLocation etc... * Fixed dupe unit tests? * Added better description of layout and coordiantes to deep dive * Added better description of layout and coordiantes to deep dive * Modified tests that call v2.AddTimeout; they were returning true which means restart the timer! This was causing mac/linux unit test failures. I think * Fixed auto scheme. Broke TextView/TextField selection * Realized Attribute.IsExplicitlySet is stupid; just use nullable * Fixed Attribute. Simplified. MOre theme testing * Updated themes again * GetViewsUnderMouse to GetViewsUnderLocation broke TransparentMouse. * Fixing mouseunder bugs * rewriting... * All working again. Shadows are now slick as snot. GetViewsUnderLocation is rewritten to actually work and be readable. Tons more low-level unit tests. Margin is now actually ViewportSettings.Transparent. * Code cleanup * Code cleanup * Code cleanup of color apis * Fixed Hover/Highlight * Update Examples/UICatalog/Scenarios/AllViewsTester.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/Clipping.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed race condition? * reverted * Simplified Attribute API by removing events from SetAttributeForRole * Removed recursion from GetViewsAtLocation * Removed unneeded code * Code clean up. Fixed Scheme bug. * reverted temporary disable * Adjusted scheme algo * Upgraded TextValidateField * Fixed TextValidate bugs * Tweaks * Frameview rounded border by default * API doc cleanup * Readme fix * Addressed tznind feeback * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true 2 * cleanup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,14 +1,53 @@
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
// Alias Console to MockConsole so we don't accidentally use Console
|
||||
|
||||
namespace Terminal.Gui.DrawingTests;
|
||||
|
||||
public class AttributeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Attribute_Is_Value_Type ()
|
||||
public void Constructor_ParsesNamedColorsAndStyle ()
|
||||
{
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Attribute).IsValueType);
|
||||
var attr = new Attribute ("Red", "Black", "Bold,Underline");
|
||||
Assert.Equal (Color.Parse ("Red"), attr.Foreground);
|
||||
Assert.Equal (Color.Parse ("Black"), attr.Background);
|
||||
Assert.True (attr.Style.HasFlag (TextStyle.Bold));
|
||||
Assert.True (attr.Style.HasFlag (TextStyle.Underline));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_ParsesHexColors ()
|
||||
{
|
||||
var attr = new Attribute ("#FF0000", "#000000", "Italic");
|
||||
Assert.Equal (Color.Parse ("#FF0000"), attr.Foreground);
|
||||
Assert.Equal (Color.Parse ("#000000"), attr.Background);
|
||||
Assert.Equal (TextStyle.Italic, attr.Style);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_ParsesRgbColors ()
|
||||
{
|
||||
var attr = new Attribute ("rgb(0,255,0)", "rgb(0,0,255)", "Faint");
|
||||
Assert.Equal (Color.Parse ("rgb(0,255,0)"), attr.Foreground);
|
||||
Assert.Equal (Color.Parse ("rgb(0,0,255)"), attr.Background);
|
||||
Assert.Equal (TextStyle.Faint, attr.Style);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_DefaultsToNoneStyle_WhenStyleIsNullOrEmpty ()
|
||||
{
|
||||
var attr1 = new Attribute ("White", "Black");
|
||||
var attr2 = new Attribute ("White", "Black", null);
|
||||
var attr3 = new Attribute ("White", "Black", "");
|
||||
Assert.Equal (TextStyle.None, attr1.Style);
|
||||
Assert.Equal (TextStyle.None, attr2.Style);
|
||||
Assert.Equal (TextStyle.None, attr3.Style);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_DefaultsToNoneStyle_WhenStyleIsInvalid ()
|
||||
{
|
||||
var attr = new Attribute ("White", "Black", "NotAStyle");
|
||||
Assert.Equal (TextStyle.None, attr.Style);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -21,7 +60,7 @@ public class AttributeTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
Assert.Equal (new (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -46,7 +85,7 @@ public class AttributeTests
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
@@ -57,8 +96,8 @@ public class AttributeTests
|
||||
var attribute = new Attribute (ColorName16.Blue);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Blue), attribute.Background);
|
||||
Assert.Equal (new (Color.Blue), attribute.Foreground);
|
||||
Assert.Equal (new (Color.Blue), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -71,31 +110,31 @@ public class AttributeTests
|
||||
var attr = new Attribute ();
|
||||
|
||||
Assert.Equal (-1, attr.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attr.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attr.Background);
|
||||
Assert.Equal (new (Color.White), attr.Foreground);
|
||||
Assert.Equal (new (Color.Black), attr.Background);
|
||||
|
||||
// Test foreground, background
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
fg = new (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
bg = new (Color.Blue);
|
||||
|
||||
attr = new Attribute (fg, bg);
|
||||
attr = new (fg, bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (bg, attr.Background);
|
||||
|
||||
attr = new Attribute (fg);
|
||||
attr = new (fg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
Assert.Equal (fg, attr.Foreground);
|
||||
Assert.Equal (fg, attr.Background);
|
||||
|
||||
attr = new Attribute (bg);
|
||||
attr = new (bg);
|
||||
|
||||
//Assert.True (attr.Initialized);
|
||||
//Assert.True (attr.HasValidColors);
|
||||
@@ -114,8 +153,19 @@ public class AttributeTests
|
||||
// Assert
|
||||
//Assert.False (attribute.Initialized);
|
||||
Assert.Equal (-1, attribute.PlatformColor);
|
||||
Assert.Equal (new Color (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new Color (Color.Black), attribute.Background);
|
||||
Assert.Equal (new (Color.White), attribute.Foreground);
|
||||
Assert.Equal (new (Color.Black), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_IncludesStyle ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Black, TextStyle.Bold);
|
||||
var attr2 = new Attribute (Color.Red, Color.Black, TextStyle.Bold);
|
||||
var attr3 = new Attribute (Color.Red, Color.Black, TextStyle.Underline);
|
||||
|
||||
Assert.Equal (attr1, attr2);
|
||||
Assert.NotEqual (attr1, attr3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -160,6 +210,16 @@ public class AttributeTests
|
||||
Assert.True (attr2.Equals (attr1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCode_ConsistentWithEquals ()
|
||||
{
|
||||
var attr1 = new Attribute (Color.Red, Color.Black, TextStyle.Bold);
|
||||
var attr2 = new Attribute (Color.Red, Color.Black, TextStyle.Bold);
|
||||
|
||||
Assert.Equal (attr1, attr2);
|
||||
Assert.Equal (attr1.GetHashCode (), attr2.GetHashCode ());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Implicit_Assign ()
|
||||
{
|
||||
@@ -170,13 +230,13 @@ public class AttributeTests
|
||||
|
||||
var value = 42;
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
fg = new (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
bg = new (Color.Blue);
|
||||
|
||||
// Test conversion to int
|
||||
attr = new Attribute (value, fg, bg);
|
||||
attr = new (value, fg, bg);
|
||||
int value_implicit = attr.PlatformColor;
|
||||
Assert.Equal (value, value_implicit);
|
||||
|
||||
@@ -207,6 +267,22 @@ public class AttributeTests
|
||||
Assert.True (attribute1 != attribute2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Is_Value_Type ()
|
||||
{
|
||||
// prove that Color is a value type
|
||||
Assert.True (typeof (Attribute).IsValueType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void List_RoundTrip_EqualityHolds ()
|
||||
{
|
||||
List<Attribute> list1 = [new (Color.Red, Color.Black, TextStyle.Bold)];
|
||||
List<Attribute> list2 = new (list1);
|
||||
|
||||
Assert.Equal (list1, list2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Make_Creates ()
|
||||
{
|
||||
@@ -214,10 +290,10 @@ public class AttributeTests
|
||||
driver.Init ();
|
||||
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
fg = new (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
bg = new (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
|
||||
@@ -232,10 +308,10 @@ public class AttributeTests
|
||||
public void Make_Creates_NoDriver ()
|
||||
{
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
fg = new (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
bg = new (Color.Blue);
|
||||
|
||||
var attr = new Attribute (fg, bg);
|
||||
|
||||
@@ -248,10 +324,10 @@ public class AttributeTests
|
||||
public void Make_SetsNotInitialized_NoDriver ()
|
||||
{
|
||||
var fg = new Color ();
|
||||
fg = new Color (Color.Red);
|
||||
fg = new (Color.Red);
|
||||
|
||||
var bg = new Color ();
|
||||
bg = new Color (Color.Blue);
|
||||
bg = new (Color.Blue);
|
||||
|
||||
var a = new Attribute (fg, bg);
|
||||
|
||||
@@ -285,7 +361,7 @@ public class AttributeTests
|
||||
|
||||
// Assert
|
||||
Assert.Equal (foregroundColor, attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
Assert.Equal (new (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -299,7 +375,7 @@ public class AttributeTests
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColor);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (backgroundColor, attribute.Background);
|
||||
}
|
||||
|
||||
@@ -314,8 +390,8 @@ public class AttributeTests
|
||||
var attribute = new Attribute (foregroundColorName, backgroundColorName);
|
||||
|
||||
// Assert
|
||||
Assert.Equal (new Color (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new Color (backgroundColorName), attribute.Background);
|
||||
Assert.Equal (new (foregroundColorName), attribute.Foreground);
|
||||
Assert.Equal (new (backgroundColorName), attribute.Background);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -339,12 +415,12 @@ public class AttributeTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_ShouldReturnFormattedStringWithForegroundAndBackground ()
|
||||
public void ToString_Formats_Correctly ()
|
||||
{
|
||||
// Arrange
|
||||
var foregroundColor = new Color (0, 0, 255);
|
||||
var backgroundColor = new Color (255, 255, 255);
|
||||
var expectedString = $"[{foregroundColor},{backgroundColor}]";
|
||||
var expectedString = $"[{foregroundColor},{backgroundColor},None]";
|
||||
|
||||
// Act
|
||||
var attribute = new Attribute (foregroundColor, backgroundColor);
|
||||
@@ -353,4 +429,29 @@ public class AttributeTests
|
||||
// Assert
|
||||
Assert.Equal (expectedString, attributeString);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData (TextStyle.Bold, "Bold")]
|
||||
[InlineData (TextStyle.Bold | TextStyle.Underline, "Bold, Underline")]
|
||||
[InlineData (TextStyle.None, "None")]
|
||||
public void ToString_IncludesStyle (TextStyle style, string expectedStyleString)
|
||||
{
|
||||
var attr = new Attribute (Color.Red, Color.Black, style);
|
||||
var result = attr.ToString ();
|
||||
|
||||
Assert.Contains (expectedStyleString, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_ShouldFailComparison_IfDifferentInstancesSameContent ()
|
||||
{
|
||||
var original = new Attribute (Color.White, Color.White);
|
||||
var clone = new Attribute (Color.White, Color.White);
|
||||
|
||||
// These print the same
|
||||
Assert.Equal (original.ToString (), clone.ToString ());
|
||||
|
||||
// But this will fail if anything differs under the hood
|
||||
Assert.Equal (original, clone); // Should pass — record struct
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user