Jelajahi Sumber

merge fixes_2296

Tig Kindel 2 tahun lalu
induk
melakukan
2f2a4b4a42

+ 4 - 1
Terminal.Gui/Core/ConsoleDriver.cs

@@ -167,7 +167,7 @@ namespace Terminal.Gui {
 	}
 	}
 
 
 	/// <summary>
 	/// <summary>
-	/// Attributes are used as elements that contain both a foreground and a background or platform specific features
+	/// Attributes are used as elements that contain both a foreground and a background or platform specific features.
 	/// </summary>
 	/// </summary>
 	/// <remarks>
 	/// <remarks>
 	///   <see cref="Attribute"/>s are needed to map colors to terminal capabilities that might lack colors. 
 	///   <see cref="Attribute"/>s are needed to map colors to terminal capabilities that might lack colors. 
@@ -1478,6 +1478,9 @@ namespace Terminal.Gui {
 				return;
 				return;
 			}
 			}
 
 
+
+			// Define the default color theme only if the user has not defined one.
+			
 			Colors.TopLevel.Normal = MakeColor (Color.BrightGreen, Color.Black);
 			Colors.TopLevel.Normal = MakeColor (Color.BrightGreen, Color.Black);
 			Colors.TopLevel.Focus = MakeColor (Color.White, Color.Cyan);
 			Colors.TopLevel.Focus = MakeColor (Color.White, Color.Cyan);
 			Colors.TopLevel.HotNormal = MakeColor (Color.Brown, Color.Black);
 			Colors.TopLevel.HotNormal = MakeColor (Color.Brown, Color.Black);

+ 79 - 3
UnitTests/Drivers/AttributeTests.cs

@@ -84,6 +84,47 @@ namespace Terminal.Gui.DriverTests {
 			Application.Shutdown ();
 			Application.Shutdown ();
 		}
 		}
 
 
+		[Fact]
+		public void Implicit_Assign_NoDriver ()
+		{
+
+			var attr = new Attribute ();
+
+			var fg = new Color ();
+			fg = Color.Red;
+
+			var bg = new Color ();
+			bg = Color.Blue;
+
+			// Test conversion to int
+			attr = new Attribute (fg, bg);
+			int value_implicit = (int)attr.Value;
+			Assert.False (attr.Initialized);
+
+			Assert.Equal (-1, value_implicit);
+			Assert.False (attr.Initialized);
+
+			// Test conversion from int
+			attr = -1;
+			Assert.Equal (-1, attr.Value);
+			Assert.False (attr.Initialized);
+
+		}
+
+		[Fact]
+		public void Make_SetsNotInitialized_NoDriver ()
+		{
+			var fg = new Color ();
+			fg = Color.Red;
+
+			var bg = new Color ();
+			bg = Color.Blue;
+
+			var a = Attribute.Make (fg, bg);
+
+			Assert.False (a.Initialized);
+		}
+
 		[Fact]
 		[Fact]
 		public void Make_Creates ()
 		public void Make_Creates ()
 		{
 		{
@@ -97,8 +138,8 @@ namespace Terminal.Gui.DriverTests {
 			var bg = new Color ();
 			var bg = new Color ();
 			bg = Color.Blue;
 			bg = Color.Blue;
 
 
-			var attr =  Attribute.Make (fg, bg);
-
+			var attr = Attribute.Make (fg, bg);
+			Assert.True (attr.Initialized);
 			Assert.Equal (fg, attr.Foreground);
 			Assert.Equal (fg, attr.Foreground);
 			Assert.Equal (bg, attr.Background);
 			Assert.Equal (bg, attr.Background);
 
 
@@ -107,7 +148,23 @@ namespace Terminal.Gui.DriverTests {
 		}
 		}
 
 
 		[Fact]
 		[Fact]
-		public void Get_Asserts_IfNotInit ()
+		public void Make_Creates_NoDriver ()
+		{
+
+			var fg = new Color ();
+			fg = Color.Red;
+
+			var bg = new Color ();
+			bg = Color.Blue;
+
+			var attr = Attribute.Make (fg, bg);
+			Assert.False (attr.Initialized);
+			Assert.Equal (fg, attr.Foreground);
+			Assert.Equal (bg, attr.Background);
+		}
+
+		[Fact]
+		public void Get_Asserts_NoDriver ()
 		{
 		{
 			Assert.Throws<InvalidOperationException> (() => Attribute.Get ());
 			Assert.Throws<InvalidOperationException> (() => Attribute.Get ());
 		}
 		}
@@ -151,5 +208,24 @@ namespace Terminal.Gui.DriverTests {
 			Assert.Equal (Color.Red, fg);
 			Assert.Equal (Color.Red, fg);
 			Assert.Equal (Color.Green, bg);
 			Assert.Equal (Color.Green, bg);
 		}
 		}
+
+		[Fact]
+		public void IsValid_Tests ()
+		{
+			var attr = new Attribute ();
+			Assert.True (attr.HasValidColors);
+
+			attr = new Attribute (Color.Red, Color.Green);
+			Assert.True (attr.HasValidColors);
+
+			attr = new Attribute (Color.Red, Color.Invalid);
+			Assert.False (attr.HasValidColors);
+
+			attr = new Attribute (Color.Invalid, Color.Green);
+			Assert.False (attr.HasValidColors);
+
+			attr = new Attribute (Color.Invalid, Color.Invalid);
+			Assert.False (attr.HasValidColors);
+		}
 	}
 	}
 }
 }

+ 2 - 2
UnitTests/Views/ViewTests.cs

@@ -1602,8 +1602,8 @@ Y
 					// Calling the Text constructor.
 					// Calling the Text constructor.
 					lbl = new Label (text);
 					lbl = new Label (text);
 				}
 				}
-				lbl.ColorScheme = new ColorScheme ();
-				lbl.Redraw (lbl.Bounds);
+				Application.Top.Add (lbl);
+				Application.Top.Redraw (Application.Top.Bounds);
 
 
 				// should have the initial text
 				// should have the initial text
 				Assert.Equal ('t', driver.Contents [0, 0, 0]);
 				Assert.Equal ('t', driver.Contents [0, 0, 0]);