Browse Source

Merge branch 'line-drawer' into splitcontainer

tznind 2 years ago
parent
commit
e7e8d8ae31
63 changed files with 471 additions and 701 deletions
  1. 3 3
      Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
  2. 5 131
      Terminal.Gui/Core/ConsoleDriver.cs
  3. 2 8
      Terminal.Gui/Core/Graphs/LineCanvas.cs
  4. 6 6
      Terminal.Gui/Core/TextFormatter.cs
  5. 21 7
      Terminal.Gui/Core/View.cs
  6. 8 5
      Terminal.Gui/Views/ListView.cs
  7. 4 4
      UICatalog/Scenarios/LineDrawing.cs
  8. 1 1
      UnitTests/Application/ApplicationTests.cs
  9. 23 45
      UnitTests/Application/MainLoopTests.cs
  10. 4 5
      UnitTests/Application/RunStateTests.cs
  11. 1 1
      UnitTests/Application/StackExtensionsTests.cs
  12. 1 1
      UnitTests/Application/SynchronizatonContextTests.cs
  13. 1 1
      UnitTests/Core/BorderTests.cs
  14. 1 6
      UnitTests/Core/ResponderTests.cs
  15. 1 1
      UnitTests/Drivers/AttributeTests.cs
  16. 11 23
      UnitTests/Drivers/ClipboardTests.cs
  17. 39 0
      UnitTests/Drivers/ColorTests.cs
  18. 16 249
      UnitTests/Drivers/ConsoleDriverTests.cs
  19. 1 1
      UnitTests/Drivers/KeyTests.cs
  20. 1 1
      UnitTests/LineCanvasTests.cs
  21. 2 2
      UnitTests/Menus/ContextMenuTests.cs
  22. 2 2
      UnitTests/Menus/MenuTests.cs
  23. 6 6
      UnitTests/TestHelpers.cs
  24. 1 1
      UnitTests/Text/CollectionNavigatorTests.cs
  25. 63 34
      UnitTests/Text/TextFormatterTests.cs
  26. 34 34
      UnitTests/TopLevels/DialogTests.cs
  27. 16 37
      UnitTests/TopLevels/MdiTests.cs
  28. 3 2
      UnitTests/TopLevels/MessageBoxTests.cs
  29. 7 13
      UnitTests/TopLevels/ToplevelTests.cs
  30. 8 7
      UnitTests/TopLevels/WindowTests.cs
  31. 21 21
      UnitTests/TopLevels/WizardTests.cs
  32. 4 9
      UnitTests/Types/DimTests.cs
  33. 1 1
      UnitTests/Types/PointTests.cs
  34. 1 2
      UnitTests/Types/PosTests.cs
  35. 1 1
      UnitTests/Types/RectTests.cs
  36. 1 1
      UnitTests/Types/SizeTests.cs
  37. 1 1
      UnitTests/UICatalog/ScenarioTests.cs
  38. 1 1
      UnitTests/Views/AllViewsTests.cs
  39. 1 1
      UnitTests/Views/AutocompleteTests.cs
  40. 1 1
      UnitTests/Views/ButtonTests.cs
  41. 1 1
      UnitTests/Views/CheckboxTests.cs
  42. 1 1
      UnitTests/Views/ColorPickerTests.cs
  43. 1 1
      UnitTests/Views/ComboBoxTests.cs
  44. 1 1
      UnitTests/Views/DateFieldTests.cs
  45. 1 1
      UnitTests/Views/FrameViewTests.cs
  46. 1 1
      UnitTests/Views/GraphViewTests.cs
  47. 1 1
      UnitTests/Views/HexViewTests.cs
  48. 1 1
      UnitTests/Views/LineViewTests.cs
  49. 64 2
      UnitTests/Views/ListViewTests.cs
  50. 1 1
      UnitTests/Views/PanelViewTests.cs
  51. 1 1
      UnitTests/Views/ProgressBarTests.cs
  52. 1 1
      UnitTests/Views/RadioGroupTests.cs
  53. 1 1
      UnitTests/Views/ScrollBarViewTests.cs
  54. 1 1
      UnitTests/Views/ScrollViewTests.cs
  55. 1 1
      UnitTests/Views/StatusBarTests.cs
  56. 1 1
      UnitTests/Views/TabViewTests.cs
  57. 1 1
      UnitTests/Views/TableViewTests.cs
  58. 1 1
      UnitTests/Views/TextFieldTests.cs
  59. 1 1
      UnitTests/Views/TextValidateFieldTests.cs
  60. 1 1
      UnitTests/Views/TextViewTests.cs
  61. 1 1
      UnitTests/Views/TimeFieldTests.cs
  62. 1 1
      UnitTests/Views/TreeViewTests.cs
  63. 61 2
      UnitTests/Views/ViewTests.cs

+ 3 - 3
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -251,7 +251,7 @@ namespace Terminal.Gui {
 				throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 				throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 			}
 			}
 			var winRect = new SmallRect (0, 0, (short)(newCols - 1), (short)Math.Max (newRows - 1, 0));
 			var winRect = new SmallRect (0, 0, (short)(newCols - 1), (short)Math.Max (newRows - 1, 0));
-			if (!SetConsoleWindowInfo (ScreenBuffer, true, ref winRect)) {
+			if (!SetConsoleWindowInfo (OutputHandle, true, ref winRect)) {
 				//throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 				//throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 				return new Size (cols, rows);
 				return new Size (cols, rows);
 			}
 			}
@@ -261,7 +261,7 @@ namespace Terminal.Gui {
 
 
 		void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi)
 		void SetConsoleOutputWindow (CONSOLE_SCREEN_BUFFER_INFOEX csbi)
 		{
 		{
-			if (ScreenBuffer != IntPtr.Zero && !SetConsoleScreenBufferInfoEx (OutputHandle, ref csbi)) {
+			if (ScreenBuffer != IntPtr.Zero && !SetConsoleScreenBufferInfoEx (ScreenBuffer, ref csbi)) {
 				throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 				throw new System.ComponentModel.Win32Exception (Marshal.GetLastWin32Error ());
 			}
 			}
 		}
 		}
@@ -773,7 +773,7 @@ namespace Terminal.Gui {
 					w += 3;
 					w += 3;
 				}
 				}
 				var newSize = WinConsole.SetConsoleWindow (
 				var newSize = WinConsole.SetConsoleWindow (
-					(short)Math.Max (w, 16), (short)Math.Max (e.Height, 1));
+					(short)Math.Max (w, 16), (short)Math.Max (e.Height, 0));
 				left = 0;
 				left = 0;
 				top = 0;
 				top = 0;
 				cols = newSize.Width;
 				cols = newSize.Width;

+ 5 - 131
Terminal.Gui/Core/ConsoleDriver.cs

@@ -212,153 +212,27 @@ namespace Terminal.Gui {
 		/// <summary>
 		/// <summary>
 		/// The default color for text, when the view is not focused.
 		/// The default color for text, when the view is not focused.
 		/// </summary>
 		/// </summary>
-		public Attribute Normal { get { return _normal; } set { _normal = SetAttribute (value); } }
+		public Attribute Normal { get { return _normal; } set { _normal = value; } }
 
 
 		/// <summary>
 		/// <summary>
 		/// The color for text when the view has the focus.
 		/// The color for text when the view has the focus.
 		/// </summary>
 		/// </summary>
-		public Attribute Focus { get { return _focus; } set { _focus = SetAttribute (value); } }
+		public Attribute Focus { get { return _focus; } set { _focus = value; } }
 
 
 		/// <summary>
 		/// <summary>
 		/// The color for the hotkey when a view is not focused
 		/// The color for the hotkey when a view is not focused
 		/// </summary>
 		/// </summary>
-		public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetAttribute (value); } }
+		public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = value; } }
 
 
 		/// <summary>
 		/// <summary>
 		/// The color for the hotkey when the view is focused.
 		/// The color for the hotkey when the view is focused.
 		/// </summary>
 		/// </summary>
-		public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetAttribute (value); } }
+		public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = value; } }
 
 
 		/// <summary>
 		/// <summary>
 		/// The default color for text, when the view is disabled.
 		/// The default color for text, when the view is disabled.
 		/// </summary>
 		/// </summary>
-		public Attribute Disabled { get { return _disabled; } set { _disabled = SetAttribute (value); } }
-
-		bool preparingScheme = false;
-
-		Attribute SetAttribute (Attribute attribute, [CallerMemberName] string callerMemberName = null)
-		{
-			if (!Application._initialized && !preparingScheme)
-				return attribute;
-
-			if (preparingScheme)
-				return attribute;
-
-			preparingScheme = true;
-			switch (caller) {
-			case "TopLevel":
-				switch (callerMemberName) {
-				case "Normal":
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					break;
-				case "Focus":
-					HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
-					break;
-				case "HotNormal":
-					HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
-					break;
-				case "HotFocus":
-					HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
-					if (Focus.Foreground != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
-					break;
-				}
-				break;
-
-			case "Base":
-				switch (callerMemberName) {
-				case "Normal":
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					break;
-				case "Focus":
-					HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
-					break;
-				case "HotNormal":
-					HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
-					Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
-					break;
-				case "HotFocus":
-					HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
-					if (Focus.Foreground != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
-					break;
-				}
-				break;
-
-			case "Menu":
-				switch (callerMemberName) {
-				case "Normal":
-					if (Focus.Background != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
-					break;
-				case "Focus":
-					Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
-					HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
-					break;
-				case "HotNormal":
-					if (Focus.Background != attribute.Background)
-						HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
-					Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
-					Disabled = Application.Driver.MakeAttribute (Disabled.Foreground, attribute.Background);
-					break;
-				case "HotFocus":
-					HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
-					if (Focus.Foreground != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
-					break;
-				case "Disabled":
-					if (Focus.Background != attribute.Background)
-						HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
-					Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					break;
-				}
-				break;
-
-			case "Dialog":
-				switch (callerMemberName) {
-				case "Normal":
-					if (Focus.Background != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (attribute.Foreground, Focus.Background);
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					break;
-				case "Focus":
-					Normal = Application.Driver.MakeAttribute (attribute.Foreground, Normal.Background);
-					HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
-					break;
-				case "HotNormal":
-					if (Focus.Background != attribute.Background)
-						HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, HotFocus.Background);
-					if (Normal.Foreground != attribute.Background)
-						Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
-					break;
-				case "HotFocus":
-					HotNormal = Application.Driver.MakeAttribute (attribute.Foreground, HotNormal.Background);
-					if (Focus.Foreground != attribute.Background)
-						Focus = Application.Driver.MakeAttribute (Focus.Foreground, attribute.Background);
-					break;
-				}
-				break;
-
-			case "Error":
-				switch (callerMemberName) {
-				case "Normal":
-					HotNormal = Application.Driver.MakeAttribute (HotNormal.Foreground, attribute.Background);
-					HotFocus = Application.Driver.MakeAttribute (HotFocus.Foreground, attribute.Background);
-					break;
-				case "HotNormal":
-				case "HotFocus":
-					HotFocus = Application.Driver.MakeAttribute (attribute.Foreground, attribute.Background);
-					Normal = Application.Driver.MakeAttribute (Normal.Foreground, attribute.Background);
-					break;
-				}
-				break;
-			}
-			preparingScheme = false;
-			return attribute;
-		}
+		public Attribute Disabled { get { return _disabled; } set { _disabled = value; } }
 
 
 		/// <summary>
 		/// <summary>
 		/// Compares two <see cref="ColorScheme"/> objects for equality.
 		/// Compares two <see cref="ColorScheme"/> objects for equality.

+ 2 - 8
Terminal.Gui/Core/Graphs/LineCanvas.cs

@@ -13,12 +13,6 @@ namespace Terminal.Gui.Graphs {
 
 
 		
 		
 		private List<StraightLine> lines = new List<StraightLine> ();
 		private List<StraightLine> lines = new List<StraightLine> ();
-		private ConsoleDriver driver;
-
-		public LineCanvas (ConsoleDriver driver)
-		{
-			this.driver = driver;
-		}
 
 
 		/// <summary>
 		/// <summary>
 		/// Add a new line to the canvas starting at <paramref name="from"/>.
 		/// Add a new line to the canvas starting at <paramref name="from"/>.
@@ -60,7 +54,7 @@ namespace Terminal.Gui.Graphs {
 						.ToArray ();
 						.ToArray ();
 
 
 					// TODO: use Driver and LineStyle to map
 					// TODO: use Driver and LineStyle to map
-					canvas [y, x] = GetRuneForIntersects (intersects);
+					canvas [y, x] = GetRuneForIntersects (Application.Driver, intersects);
 
 
 				}
 				}
 			}
 			}
@@ -90,7 +84,7 @@ namespace Terminal.Gui.Graphs {
 			}
 			}
 		}
 		}
 
 
-		private Rune? GetRuneForIntersects (IntersectionDefinition [] intersects)
+		private Rune? GetRuneForIntersects (ConsoleDriver driver, IntersectionDefinition [] intersects)
 		{
 		{
 			if (!intersects.Any ())
 			if (!intersects.Any ())
 				return null;
 				return null;

+ 6 - 6
Terminal.Gui/Core/TextFormatter.cs

@@ -1212,11 +1212,11 @@ namespace Terminal.Gui {
 					if (isVertical) {
 					if (isVertical) {
 						var runesWidth = GetSumMaxCharWidth (Lines, line);
 						var runesWidth = GetSumMaxCharWidth (Lines, line);
 						x = bounds.Right - runesWidth;
 						x = bounds.Right - runesWidth;
-						CursorPosition = bounds.Width - runesWidth + hotKeyPos;
+						CursorPosition = bounds.Width - runesWidth + (hotKeyPos > -1 ? hotKeyPos : 0);
 					} else {
 					} else {
 						var runesWidth = GetTextWidth (ustring.Make (runes));
 						var runesWidth = GetTextWidth (ustring.Make (runes));
 						x = bounds.Right - runesWidth;
 						x = bounds.Right - runesWidth;
-						CursorPosition = bounds.Width - runesWidth + hotKeyPos;
+						CursorPosition = bounds.Width - runesWidth + (hotKeyPos > -1 ? hotKeyPos : 0);
 					}
 					}
 				} else if (textAlignment == TextAlignment.Left || textAlignment == TextAlignment.Justified) {
 				} else if (textAlignment == TextAlignment.Left || textAlignment == TextAlignment.Justified) {
 					if (isVertical) {
 					if (isVertical) {
@@ -1225,16 +1225,16 @@ namespace Terminal.Gui {
 					} else {
 					} else {
 						x = bounds.Left;
 						x = bounds.Left;
 					}
 					}
-					CursorPosition = hotKeyPos;
+					CursorPosition = hotKeyPos > -1 ? hotKeyPos : 0;
 				} else if (textAlignment == TextAlignment.Centered) {
 				} else if (textAlignment == TextAlignment.Centered) {
 					if (isVertical) {
 					if (isVertical) {
 						var runesWidth = GetSumMaxCharWidth (Lines, line);
 						var runesWidth = GetSumMaxCharWidth (Lines, line);
 						x = bounds.Left + line + ((bounds.Width - runesWidth) / 2);
 						x = bounds.Left + line + ((bounds.Width - runesWidth) / 2);
-						CursorPosition = (bounds.Width - runesWidth) / 2 + hotKeyPos;
+						CursorPosition = (bounds.Width - runesWidth) / 2 + (hotKeyPos > -1 ? hotKeyPos : 0);
 					} else {
 					} else {
 						var runesWidth = GetTextWidth (ustring.Make (runes));
 						var runesWidth = GetTextWidth (ustring.Make (runes));
 						x = bounds.Left + (bounds.Width - runesWidth) / 2;
 						x = bounds.Left + (bounds.Width - runesWidth) / 2;
-						CursorPosition = (bounds.Width - runesWidth) / 2 + hotKeyPos;
+						CursorPosition = (bounds.Width - runesWidth) / 2 + (hotKeyPos > -1 ? hotKeyPos : 0);
 					}
 					}
 				} else {
 				} else {
 					throw new ArgumentOutOfRangeException ();
 					throw new ArgumentOutOfRangeException ();
@@ -1291,7 +1291,7 @@ namespace Terminal.Gui {
 							rune = runes [idx];
 							rune = runes [idx];
 						}
 						}
 					}
 					}
-					if (idx == HotKeyPos) {
+					if (HotKeyPos > -1 && idx == HotKeyPos) {
 						if ((isVertical && textVerticalAlignment == VerticalTextAlignment.Justified) ||
 						if ((isVertical && textVerticalAlignment == VerticalTextAlignment.Justified) ||
 						(!isVertical && textAlignment == TextAlignment.Justified)) {
 						(!isVertical && textAlignment == TextAlignment.Justified)) {
 							CursorPosition = idx - start;
 							CursorPosition = idx - start;

+ 21 - 7
Terminal.Gui/Core/View.cs

@@ -1093,8 +1093,15 @@ namespace Terminal.Gui {
 		/// </remarks>
 		/// </remarks>
 		public void Clear ()
 		public void Clear ()
 		{
 		{
-			var h = Frame.Height;
-			var w = Frame.Width;
+			Rect containerBounds = GetContainerBounds ();
+			Rect viewBounds = Bounds;
+			if (!containerBounds.IsEmpty) {
+				viewBounds.Width = Math.Min (viewBounds.Width, containerBounds.Width);
+				viewBounds.Height = Math.Min (viewBounds.Height, containerBounds.Height);
+			}
+
+			var h = viewBounds.Height;
+			var w = viewBounds.Width;
 			for (var line = 0; line < h; line++) {
 			for (var line = 0; line < h; line++) {
 				Move (0, line);
 				Move (0, line);
 				for (var col = 0; col < w; col++)
 				for (var col = 0; col < w; col++)
@@ -1511,11 +1518,7 @@ namespace Terminal.Gui {
 				if (TextFormatter != null) {
 				if (TextFormatter != null) {
 					TextFormatter.NeedsFormat = true;
 					TextFormatter.NeedsFormat = true;
 				}
 				}
-				var containerBounds = SuperView == null ? default : SuperView.ViewToScreen (SuperView.Bounds);
-				containerBounds.X = Math.Max (containerBounds.X, Driver.Clip.X);
-				containerBounds.Y = Math.Max (containerBounds.Y, Driver.Clip.Y);
-				containerBounds.Width = Math.Min (containerBounds.Width, Driver.Clip.Width);
-				containerBounds.Height = Math.Min (containerBounds.Height, Driver.Clip.Height);
+				Rect containerBounds = GetContainerBounds ();
 				TextFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (),
 				TextFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? ColorScheme.Focus : GetNormalColor (),
 				    HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled,
 				    HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled,
 				    containerBounds);
 				    containerBounds);
@@ -1558,6 +1561,17 @@ namespace Terminal.Gui {
 			ClearNeedsDisplay ();
 			ClearNeedsDisplay ();
 		}
 		}
 
 
+		Rect GetContainerBounds ()
+		{
+			var containerBounds = SuperView == null ? default : SuperView.ViewToScreen (SuperView.Bounds);
+			var driverClip = Driver == null ? Rect.Empty : Driver.Clip;
+			containerBounds.X = Math.Max (containerBounds.X, driverClip.X);
+			containerBounds.Y = Math.Max (containerBounds.Y, driverClip.Y);
+			containerBounds.Width = Math.Min (containerBounds.Width, driverClip.Width);
+			containerBounds.Height = Math.Min (containerBounds.Height, driverClip.Height);
+			return containerBounds;
+		}
+
 		/// <summary>
 		/// <summary>
 		/// Event invoked when the content area of the View is to be drawn.
 		/// Event invoked when the content area of the View is to be drawn.
 		/// </summary>
 		/// </summary>

+ 8 - 5
Terminal.Gui/Views/ListView.cs

@@ -430,7 +430,7 @@ namespace Terminal.Gui {
 				var newItem = KeystrokeNavigator?.GetNextMatchingItem (SelectedItem, (char)kb.KeyValue);
 				var newItem = KeystrokeNavigator?.GetNextMatchingItem (SelectedItem, (char)kb.KeyValue);
 				if (newItem is int && newItem != -1) {
 				if (newItem is int && newItem != -1) {
 					SelectedItem = (int)newItem;
 					SelectedItem = (int)newItem;
-					EnsuresVisibilitySelectedItem ();
+					EnsureSelectedItemVisible ();
 					SetNeedsDisplay ();
 					SetNeedsDisplay ();
 					return true;
 					return true;
 				}
 				}
@@ -727,7 +727,7 @@ namespace Terminal.Gui {
 			Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
 			Application.Driver.SetCursorVisibility (CursorVisibility.Invisible);
 
 
 			if (lastSelectedItem == -1) {
 			if (lastSelectedItem == -1) {
-				EnsuresVisibilitySelectedItem ();
+				EnsureSelectedItemVisible ();
 			}
 			}
 
 
 			return base.OnEnter (view);
 			return base.OnEnter (view);
@@ -743,7 +743,10 @@ namespace Terminal.Gui {
 			return base.OnLeave (view);
 			return base.OnLeave (view);
 		}
 		}
 
 
-		void EnsuresVisibilitySelectedItem ()
+		/// <summary>
+		/// Ensures the selected item is always visible on the screen.
+		/// </summary>
+		public void EnsureSelectedItemVisible ()
 		{
 		{
 			SuperView?.LayoutSubviews ();
 			SuperView?.LayoutSubviews ();
 			if (selected < top) {
 			if (selected < top) {
@@ -840,7 +843,7 @@ namespace Terminal.Gui {
 			if (src == null || src?.Count == 0) {
 			if (src == null || src?.Count == 0) {
 				return 0;
 				return 0;
 			}
 			}
-			
+
 			int maxLength = 0;
 			int maxLength = 0;
 			for (int i = 0; i < src.Count; i++) {
 			for (int i = 0; i < src.Count; i++) {
 				var t = src [i];
 				var t = src [i];
@@ -924,7 +927,7 @@ namespace Terminal.Gui {
 						return i;
 						return i;
 					}
 					}
 				} else if (t is string s) {
 				} else if (t is string s) {
-					if (s.ToUpperInvariant ().StartsWith (search.ToUpperInvariant ())) {
+					if (s.StartsWith (search, StringComparison.InvariantCultureIgnoreCase)) {
 						return i;
 						return i;
 					}
 					}
 				}
 				}

+ 4 - 4
UICatalog/Scenarios/Drawing.cs → UICatalog/Scenarios/LineDrawing.cs

@@ -6,10 +6,10 @@ using Terminal.Gui.Graphs;
 
 
 namespace UICatalog.Scenarios {
 namespace UICatalog.Scenarios {
 
 
-	[ScenarioMetadata (Name: "Drawing", Description: "Demonstrates LineCanvas.")]
+	[ScenarioMetadata (Name: "Line Drawing", Description: "Demonstrates LineCanvas.")]
 	[ScenarioCategory ("Controls")]
 	[ScenarioCategory ("Controls")]
 	[ScenarioCategory ("Layout")]
 	[ScenarioCategory ("Layout")]
-	public class Drawing : Scenario {
+	public class LineDrawing : Scenario {
 
 
 		public override void Setup ()
 		public override void Setup ()
 		{
 		{
@@ -52,7 +52,7 @@ namespace UICatalog.Scenarios {
 
 
 			public ToolsView (int width)
 			public ToolsView (int width)
 			{
 			{
-				grid = new LineCanvas (Application.Driver);
+				grid = new LineCanvas ();
 
 
 				grid.AddLine (new Point (0, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single);
 				grid.AddLine (new Point (0, 0), int.MaxValue, Orientation.Vertical, BorderStyle.Single);
 				grid.AddLine (new Point (0, 0), width, Orientation.Horizontal, BorderStyle.Single);
 				grid.AddLine (new Point (0, 0), width, Orientation.Horizontal, BorderStyle.Single);
@@ -139,7 +139,7 @@ namespace UICatalog.Scenarios {
 					return;
 					return;
 				}
 				}
 
 
-				canvases.Add (new LineCanvas (Application.Driver));
+				canvases.Add (new LineCanvas ());
 				colorLayers.Add (c, canvases.Count - 1);
 				colorLayers.Add (c, canvases.Count - 1);
 				currentColor = canvases.Count - 1;
 				currentColor = canvases.Count - 1;
 			}
 			}

+ 1 - 1
UnitTests/ApplicationTests.cs → UnitTests/Application/ApplicationTests.cs

@@ -9,7 +9,7 @@ using Xunit;
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ApplicationTests {
 	public class ApplicationTests {
 	public class ApplicationTests {
 		public ApplicationTests ()
 		public ApplicationTests ()
 		{
 		{

+ 23 - 45
UnitTests/MainLoopTests.cs → UnitTests/Application/MainLoopTests.cs

@@ -13,7 +13,7 @@ using Xunit.Sdk;
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ApplicationTests {
 	/// <summary>
 	/// <summary>
 	/// Tests MainLoop using the FakeMainLoop.
 	/// Tests MainLoop using the FakeMainLoop.
 	/// </summary>
 	/// </summary>
@@ -171,9 +171,7 @@ namespace Terminal.Gui.Core {
 			var functionCalled = 0;
 			var functionCalled = 0;
 			Func<bool> fn1 = () => {
 			Func<bool> fn1 = () => {
 				functionCalled++;
 				functionCalled++;
-				if (functionCalled == 10) {
-					return false;
-				}
+				if (functionCalled == 10) 					return false;
 				return true;
 				return true;
 			};
 			};
 
 
@@ -181,9 +179,7 @@ namespace Terminal.Gui.Core {
 			var stopCount = 0;
 			var stopCount = 0;
 			Func<bool> fnStop = () => {
 			Func<bool> fnStop = () => {
 				stopCount++;
 				stopCount++;
-				if (stopCount == 20) {
-					ml.Stop ();
-				}
+				if (stopCount == 20) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 
 
@@ -212,9 +208,7 @@ namespace Terminal.Gui.Core {
 			var stopCount = 0;
 			var stopCount = 0;
 			Func<bool> fnStop = () => {
 			Func<bool> fnStop = () => {
 				stopCount++;
 				stopCount++;
-				if (stopCount == 10) {
-					ml.Stop ();
-				}
+				if (stopCount == 10) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 
 
@@ -237,9 +231,7 @@ namespace Terminal.Gui.Core {
 			var functionCalled = 0;
 			var functionCalled = 0;
 			Func<bool> fn = () => {
 			Func<bool> fn = () => {
 				functionCalled++;
 				functionCalled++;
-				if (functionCalled == 10) {
-					ml.Stop ();
-				}
+				if (functionCalled == 10) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 
 
@@ -258,7 +250,7 @@ namespace Terminal.Gui.Core {
 			var ms = 100;
 			var ms = 100;
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
 				return true;
 				return true;
 			};
 			};
@@ -279,7 +271,7 @@ namespace Terminal.Gui.Core {
 			var ms = 100;
 			var ms = 100;
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
 				ml.Stop ();
 				ml.Stop ();
 				return true;
 				return true;
@@ -300,11 +292,9 @@ namespace Terminal.Gui.Core {
 			object token1 = null, token2 = null;
 			object token1 = null, token2 = null;
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
-				if (callbackCount == 2) {
-					ml.Stop ();
-				}
+				if (callbackCount == 2) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 
 
@@ -332,11 +322,9 @@ namespace Terminal.Gui.Core {
 			object token1 = null, token2 = null;
 			object token1 = null, token2 = null;
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
-				if (callbackCount == 2) {
-					ml.Stop ();
-				}
+				if (callbackCount == 2) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 
 
@@ -369,7 +357,7 @@ namespace Terminal.Gui.Core {
 			var watch = new System.Diagnostics.Stopwatch ();
 			var watch = new System.Diagnostics.Stopwatch ();
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				watch.Stop ();
 				watch.Stop ();
 				callbackCount++;
 				callbackCount++;
 				ml.Stop ();
 				ml.Stop ();
@@ -381,7 +369,7 @@ namespace Terminal.Gui.Core {
 			ml.Run ();
 			ml.Run ();
 			// +/- 100ms should be good enuf
 			// +/- 100ms should be good enuf
 			// https://github.com/xunit/assert.xunit/pull/25
 			// https://github.com/xunit/assert.xunit/pull/25
-			Assert.Equal<TimeSpan> (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
+			Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
 
 
 			Assert.True (ml.RemoveTimeout (token));
 			Assert.True (ml.RemoveTimeout (token));
 			Assert.Equal (1, callbackCount);
 			Assert.Equal (1, callbackCount);
@@ -395,7 +383,7 @@ namespace Terminal.Gui.Core {
 			var watch = new System.Diagnostics.Stopwatch ();
 			var watch = new System.Diagnostics.Stopwatch ();
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
 				if (callbackCount == 2) {
 				if (callbackCount == 2) {
 					watch.Stop ();
 					watch.Stop ();
@@ -409,7 +397,7 @@ namespace Terminal.Gui.Core {
 			ml.Run ();
 			ml.Run ();
 			// +/- 100ms should be good enuf
 			// +/- 100ms should be good enuf
 			// https://github.com/xunit/assert.xunit/pull/25
 			// https://github.com/xunit/assert.xunit/pull/25
-			Assert.Equal<TimeSpan> (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
+			Assert.Equal (ms * callbackCount, watch.Elapsed, new MillisecondTolerance (100));
 
 
 			Assert.True (ml.RemoveTimeout (token));
 			Assert.True (ml.RemoveTimeout (token));
 			Assert.Equal (2, callbackCount);
 			Assert.Equal (2, callbackCount);
@@ -425,15 +413,13 @@ namespace Terminal.Gui.Core {
 			var stopCount = 0;
 			var stopCount = 0;
 			Func<bool> fnStop = () => {
 			Func<bool> fnStop = () => {
 				stopCount++;
 				stopCount++;
-				if (stopCount == 10) {
-					ml.Stop ();
-				}
+				if (stopCount == 10) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 			ml.AddIdle (fnStop);
 			ml.AddIdle (fnStop);
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
 				return true;
 				return true;
 			};
 			};
@@ -455,15 +441,13 @@ namespace Terminal.Gui.Core {
 			Func<bool> fnStop = () => {
 			Func<bool> fnStop = () => {
 				Thread.Sleep (10); // Sleep to enable timer to fire
 				Thread.Sleep (10); // Sleep to enable timer to fire
 				stopCount++;
 				stopCount++;
-				if (stopCount == 10) {
-					ml.Stop ();
-				}
+				if (stopCount == 10) 					ml.Stop ();
 				return true;
 				return true;
 			};
 			};
 			ml.AddIdle (fnStop);
 			ml.AddIdle (fnStop);
 
 
 			var callbackCount = 0;
 			var callbackCount = 0;
-			Func<MainLoop, bool> callback = (MainLoop loop) => {
+			Func<MainLoop, bool> callback = (loop) => {
 				callbackCount++;
 				callbackCount++;
 				return false;
 				return false;
 			};
 			};
@@ -541,10 +525,8 @@ namespace Terminal.Gui.Core {
 				Application.MainLoop.Invoke (() => {
 				Application.MainLoop.Invoke (() => {
 					tf.Text = $"index{r.Next ()}";
 					tf.Text = $"index{r.Next ()}";
 					Interlocked.Increment (ref tbCounter);
 					Interlocked.Increment (ref tbCounter);
-					if (target == tbCounter) {
-						// On last increment wake up the check
+					if (target == tbCounter) 						// On last increment wake up the check
 						_wakeUp.Set ();
 						_wakeUp.Set ();
-					}
 				});
 				});
 			});
 			});
 		}
 		}
@@ -554,9 +536,7 @@ namespace Terminal.Gui.Core {
 			for (int j = 0; j < numPasses; j++) {
 			for (int j = 0; j < numPasses; j++) {
 
 
 				_wakeUp.Reset ();
 				_wakeUp.Reset ();
-				for (var i = 0; i < numIncrements; i++) {
-					Launch (r, tf, (j + 1) * numIncrements);
-				}
+				for (var i = 0; i < numIncrements; i++) 					Launch (r, tf, (j + 1) * numIncrements);
 
 
 
 
 				while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
 				while (tbCounter != (j + 1) * numIncrements) // Wait for tbCounter to reach expected value
@@ -594,7 +574,7 @@ namespace Terminal.Gui.Core {
 
 
 			await task; // Propagate exception if any occurred
 			await task; // Propagate exception if any occurred
 
 
-			Assert.Equal ((numIncrements * numPasses), tbCounter);
+			Assert.Equal (numIncrements * numPasses, tbCounter);
 		}
 		}
 
 
 		private static int total;
 		private static int total;
@@ -652,9 +632,7 @@ namespace Terminal.Gui.Core {
 					Assert.True (btn.ProcessKey (new KeyEvent (Key.Enter, null)));
 					Assert.True (btn.ProcessKey (new KeyEvent (Key.Enter, null)));
 					Assert.Equal (cancel, btn.Text);
 					Assert.Equal (cancel, btn.Text);
 					Assert.Equal (one, total);
 					Assert.Equal (one, total);
-				} else if (taskCompleted) {
-					Application.RequestStop ();
-				}
+				} else if (taskCompleted) 					Application.RequestStop ();
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();

+ 4 - 5
UnitTests/RunStateTests.cs → UnitTests/Application/RunStateTests.cs

@@ -3,12 +3,13 @@ using System.Diagnostics;
 using System.Linq;
 using System.Linq;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using Terminal.Gui;
 using Xunit;
 using Xunit;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ApplicationTests {
 	/// <summary>
 	/// <summary>
 	/// These tests focus on Application.RunState and the various ways it can be changed.
 	/// These tests focus on Application.RunState and the various ways it can be changed.
 	/// </summary>
 	/// </summary>
@@ -26,7 +27,7 @@ namespace Terminal.Gui.Core {
 		{
 		{
 			var rs = new Application.RunState (null);
 			var rs = new Application.RunState (null);
 			Assert.Null (rs.Toplevel);
 			Assert.Null (rs.Toplevel);
-			
+
 			var top = new Toplevel ();
 			var top = new Toplevel ();
 			rs = new Application.RunState (top);
 			rs = new Application.RunState (top);
 			Assert.Equal (top, rs.Toplevel);
 			Assert.Equal (top, rs.Toplevel);
@@ -72,9 +73,7 @@ namespace Terminal.Gui.Core {
 			Application.Shutdown ();
 			Application.Shutdown ();
 #if DEBUG_IDISPOSABLE
 #if DEBUG_IDISPOSABLE
 			// Validate there are no outstanding RunState-based instances left
 			// Validate there are no outstanding RunState-based instances left
-			foreach (var inst in Application.RunState.Instances) {
-				Assert.True (inst.WasDisposed);
-			}
+			foreach (var inst in Application.RunState.Instances) 				Assert.True (inst.WasDisposed);
 #endif
 #endif
 		}
 		}
 
 

+ 1 - 1
UnitTests/StackExtensionsTests.cs → UnitTests/Application/StackExtensionsTests.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ApplicationTests {
 	public class StackExtensionsTests {
 	public class StackExtensionsTests {
 		[Fact]
 		[Fact]
 		public void Stack_Toplevels_CreateToplevels ()
 		public void Stack_Toplevels_CreateToplevels ()

+ 1 - 1
UnitTests/SynchronizatonContextTests.cs → UnitTests/Application/SynchronizatonContextTests.cs

@@ -13,7 +13,7 @@ using Xunit.Sdk;
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ApplicationTests {
 	public class SyncrhonizationContextTests {
 	public class SyncrhonizationContextTests {
 
 
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]

+ 1 - 1
UnitTests/BorderTests.cs → UnitTests/Core/BorderTests.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Rune = System.Rune;
 using Rune = System.Rune;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.CoreTests {
 	public class BorderTests {
 	public class BorderTests {
 		[Fact]
 		[Fact]
 		[AutoInitShutdown]
 		[AutoInitShutdown]

+ 1 - 6
UnitTests/ResponderTests.cs → UnitTests/Core/ResponderTests.cs

@@ -1,14 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Terminal.Gui;
 using Xunit;
 using Xunit;
-using static Terminal.Gui.Core.ViewTests;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.CoreTests {
 	public class ResponderTests {
 	public class ResponderTests {
 		[Fact]
 		[Fact]
 		public void New_Initializes ()
 		public void New_Initializes ()

+ 1 - 1
UnitTests/AttributeTests.cs → UnitTests/Drivers/AttributeTests.cs

@@ -7,7 +7,7 @@ using Xunit;
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.ConsoleDrivers {
+namespace Terminal.Gui.DriverTests {
 	public class AttributeTests {
 	public class AttributeTests {
 		[Fact]
 		[Fact]
 		public void Constuctors_Constuct ()
 		public void Constuctors_Constuct ()

+ 11 - 23
UnitTests/ClipboardTests.cs → UnitTests/Drivers/ClipboardTests.cs

@@ -1,11 +1,12 @@
 using System;
 using System;
 using System.Diagnostics;
 using System.Diagnostics;
 using System.Runtime.InteropServices;
 using System.Runtime.InteropServices;
+using Terminal.Gui;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using static AutoInitShutdownAttribute;
 using static AutoInitShutdownAttribute;
 
 
-namespace Terminal.Gui.ConsoleDrivers {
+namespace Terminal.Gui.DriverTests {
 	public class ClipboardTests {
 	public class ClipboardTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -101,11 +102,8 @@ namespace Terminal.Gui.ConsoleDrivers {
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
 		public void IsSupported_Get ()
 		public void IsSupported_Get ()
 		{
 		{
-			if (Clipboard.IsSupported) {
-				Assert.True (Clipboard.IsSupported);
-			} else {
-				Assert.False (Clipboard.IsSupported);
-			}
+			if (Clipboard.IsSupported) 				Assert.True (Clipboard.IsSupported);
+else 				Assert.False (Clipboard.IsSupported);
 		}
 		}
 
 
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
@@ -131,21 +129,15 @@ namespace Terminal.Gui.ConsoleDrivers {
 		public void TrySetClipboardData_Sets_The_OS_Clipboard ()
 		public void TrySetClipboardData_Sets_The_OS_Clipboard ()
 		{
 		{
 			var clipText = "The TrySetClipboardData_Sets_The_OS_Clipboard unit test pasted this to the OS clipboard.";
 			var clipText = "The TrySetClipboardData_Sets_The_OS_Clipboard unit test pasted this to the OS clipboard.";
-			if (Clipboard.IsSupported) {
-				Assert.True (Clipboard.TrySetClipboardData (clipText));
-			} else {
-				Assert.False (Clipboard.TrySetClipboardData (clipText));
-			}
+			if (Clipboard.IsSupported) 				Assert.True (Clipboard.TrySetClipboardData (clipText));
+else 				Assert.False (Clipboard.TrySetClipboardData (clipText));
 
 
 			Application.Iteration += () => Application.RequestStop ();
 			Application.Iteration += () => Application.RequestStop ();
 
 
 			Application.Run ();
 			Application.Run ();
 
 
-			if (Clipboard.IsSupported) {
-				Assert.Equal (clipText, Clipboard.Contents);
-			} else {
-				Assert.NotEqual (clipText, Clipboard.Contents);
-			}
+			if (Clipboard.IsSupported) 				Assert.Equal (clipText, Clipboard.Contents);
+else 				Assert.NotEqual (clipText, Clipboard.Contents);
 		}
 		}
 
 
 
 
@@ -217,9 +209,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 
 
 			Application.Run ();
 			Application.Run ();
 
 
-			if (!failed) {
-				Assert.Equal (clipText, getClipText);
-			}
+			if (!failed) 				Assert.Equal (clipText, getClipText);
 		}
 		}
 
 
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
 		[Fact, AutoInitShutdown (useFakeClipboard: false)]
@@ -275,9 +265,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 
 
 			Application.Run ();
 			Application.Run ();
 
 
-			if (!failed) {
-				Assert.Equal (clipText, clipReadText.TrimEnd ());
-			}
+			if (!failed) 				Assert.Equal (clipText, clipReadText.TrimEnd ());
 
 
 		}
 		}
 
 
@@ -292,7 +280,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 			try {
 			try {
 				var (_, result) = ClipboardProcessRunner.Process ("bash", $"-c \"which xclip\"");
 				var (_, result) = ClipboardProcessRunner.Process ("bash", $"-c \"which xclip\"");
 				return result.TrimEnd () != "";
 				return result.TrimEnd () != "";
-			} catch (System.Exception) {
+			} catch (Exception) {
 				return false;
 				return false;
 			}
 			}
 		}
 		}

+ 39 - 0
UnitTests/Drivers/ColorTests.cs

@@ -0,0 +1,39 @@
+using System;
+using Xunit;
+
+// Alias Console to MockConsole so we don't accidentally use Console
+using Console = Terminal.Gui.FakeConsole;
+
+namespace Terminal.Gui.DriverTests {
+	public class ColorTests {
+
+		[Theory]
+		[InlineData (typeof (FakeDriver))]
+		//[InlineData (typeof (NetDriver))]
+		//[InlineData (typeof (CursesDriver))]
+		//[InlineData (typeof (WindowsDriver))]
+		public void SetColors_Changes_Colors (Type driverType)
+		{
+			var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
+			Application.Init (driver);
+			driver.Init (() => { });
+			Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
+			Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
+
+			Console.ForegroundColor = ConsoleColor.Red;
+			Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
+
+			Console.BackgroundColor = ConsoleColor.Green;
+			Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
+
+			Console.ResetColor ();
+			Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
+			Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
+			driver.End ();
+
+			// Shutdown must be called to safely clean up Application if Init has been called
+			Application.Shutdown ();
+		}
+
+	}
+}

+ 16 - 249
UnitTests/ConsoleDriverTests.cs → UnitTests/Drivers/ConsoleDriverTests.cs

@@ -1,16 +1,14 @@
 using System;
 using System;
 using System.Collections;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
-using System.IO;
 using System.Linq;
 using System.Linq;
-using Terminal.Gui.Views;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.ConsoleDrivers {
+namespace Terminal.Gui.DriverTests {
 	public class ConsoleDriverTests {
 	public class ConsoleDriverTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -53,10 +51,10 @@ namespace Terminal.Gui.ConsoleDrivers {
 			Application.Init (driver);
 			Application.Init (driver);
 			driver.Init (() => { });
 			driver.Init (() => { });
 
 
-			FakeConsole.ForegroundColor = ConsoleColor.Red;
+			Console.ForegroundColor = ConsoleColor.Red;
 			Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
 			Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
 
 
-			FakeConsole.BackgroundColor = ConsoleColor.Green;
+			Console.BackgroundColor = ConsoleColor.Green;
 			Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
 			Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
 			driver.Move (2, 3);
 			driver.Move (2, 3);
 			Assert.Equal (2, Console.CursorLeft);
 			Assert.Equal (2, Console.CursorLeft);
@@ -72,34 +70,6 @@ namespace Terminal.Gui.ConsoleDrivers {
 			Application.Shutdown ();
 			Application.Shutdown ();
 		}
 		}
 
 
-		[Theory]
-		[InlineData (typeof (FakeDriver))]
-		//[InlineData (typeof (NetDriver))]
-		//[InlineData (typeof (CursesDriver))]
-		//[InlineData (typeof (WindowsDriver))]
-		public void SetColors_Changes_Colors (Type driverType)
-		{
-			var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
-			Application.Init (driver);
-			driver.Init (() => { });
-			Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
-			Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
-
-			Console.ForegroundColor = ConsoleColor.Red;
-			Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
-
-			Console.BackgroundColor = ConsoleColor.Green;
-			Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
-
-			Console.ResetColor ();
-			Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
-			Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
-			driver.End ();
-
-			// Shutdown must be called to safely clean up Application if Init has been called
-			Application.Shutdown ();
-		}
-
 		[Theory]
 		[Theory]
 		[InlineData (typeof (FakeDriver))]
 		[InlineData (typeof (FakeDriver))]
 		public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType)
 		public void FakeDriver_Only_Sends_Keystrokes_Through_MockKeyPresses (Type driverType)
@@ -119,9 +89,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
 				count++;
 				count++;
-				if (count == 10) {
-					Application.RequestStop ();
-				}
+				if (count == 10) Application.RequestStop ();
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();
@@ -146,7 +114,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 				var cki = new ConsoleKeyInfo (r, ck, false, false, false);
 				var cki = new ConsoleKeyInfo (r, ck, false, false, false);
 				mKeys.Push (cki);
 				mKeys.Push (cki);
 			}
 			}
-			FakeConsole.MockKeyPresses = mKeys;
+			Console.MockKeyPresses = mKeys;
 
 
 			var top = Application.Top;
 			var top = Application.Top;
 			var view = new View ();
 			var view = new View ();
@@ -163,9 +131,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 			top.Add (view);
 			top.Add (view);
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
-				if (mKeys.Count == 0) {
-					Application.RequestStop ();
-				}
+				if (mKeys.Count == 0) Application.RequestStop ();
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();
@@ -176,105 +142,6 @@ namespace Terminal.Gui.ConsoleDrivers {
 			Application.Shutdown ();
 			Application.Shutdown ();
 		}
 		}
 
 
-		[Theory]
-		[InlineData (typeof (FakeDriver))]
-		public void SendKeys_Test (Type driverType)
-		{
-			var driver = (ConsoleDriver)Activator.CreateInstance (driverType);
-			Application.Init (driver);
-
-			var top = Application.Top;
-			var view = new View ();
-			var shift = false; var alt = false; var control = false;
-			Key key = default;
-			Key lastKey = default;
-			List<Key> keyEnums = GetKeys ();
-			int i = 0;
-			int idxKey = 0;
-			var PushIterations = 0;
-			var PopIterations = 0;
-
-			List<Key> GetKeys ()
-			{
-				List<Key> keys = new List<Key> ();
-
-				foreach (Key k in Enum.GetValues (typeof (Key))) {
-					if ((uint)k <= 0xff) {
-						keys.Add (k);
-					} else if ((uint)k > 0xff) {
-						break;
-					}
-				}
-
-				return keys;
-			}
-
-			view.KeyPress += (e) => {
-				e.Handled = true;
-				PopIterations++;
-				var rMk = new KeyModifiers () {
-					Shift = e.KeyEvent.IsShift,
-					Alt = e.KeyEvent.IsAlt,
-					Ctrl = e.KeyEvent.IsCtrl
-				};
-				lastKey = ShortcutHelper.GetModifiersKey (new KeyEvent (e.KeyEvent.Key, rMk));
-				Assert.Equal (key, lastKey);
-			};
-			top.Add (view);
-
-			Application.Iteration += () => {
-				switch (i) {
-				case 0:
-					SendKeys ();
-					break;
-				case 1:
-					shift = true;
-					SendKeys ();
-					break;
-				case 2:
-					alt = true;
-					SendKeys ();
-					break;
-				case 3:
-					control = true;
-					SendKeys ();
-					break;
-				}
-				if (PushIterations == keyEnums.Count * 4) {
-					Application.RequestStop ();
-				}
-			};
-
-			void SendKeys ()
-			{
-				var k = shift && char.IsLetter ((char)keyEnums [idxKey]) && char.IsLower ((char)keyEnums [idxKey])
-					? (Key)char.ToUpper ((char)keyEnums [idxKey]) : keyEnums [idxKey];
-				var c = (char)k;
-				var ck = char.IsLetter (c) ? (ConsoleKey)char.ToUpper (c) : (ConsoleKey)c;
-				var mk = new KeyModifiers () {
-					Shift = shift,
-					Alt = alt,
-					Ctrl = control
-				};
-				key = ShortcutHelper.GetModifiersKey (new KeyEvent (k, mk));
-				Application.Driver.SendKeys (c, ck, shift, alt, control);
-				PushIterations++;
-				if (idxKey + 1 < keyEnums.Count) {
-					idxKey++;
-				} else {
-					idxKey = 0;
-					i++;
-				}
-			}
-
-			Application.Run ();
-
-			Assert.Equal (key, lastKey);
-
-			// Shutdown must be called to safely clean up Application if Init has been called
-			Application.Shutdown ();
-		}
-
 		[Theory]
 		[Theory]
 		[InlineData (typeof (FakeDriver))]
 		[InlineData (typeof (FakeDriver))]
 		public void TerminalResized_Simulation (Type driverType)
 		public void TerminalResized_Simulation (Type driverType)
@@ -452,93 +319,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 
 
 			Application.Shutdown ();
 			Application.Shutdown ();
 		}
 		}
-
-		[Fact]
-		public void Internal_Tests ()
-		{
-			var cs = new ColorScheme ();
-			Assert.Equal ("", cs.caller);
-		}
-
-		[Fact]
-		[AutoInitShutdown]
-		public void KeyModifiers_Resetting_At_New_Keystrokes ()
-		{
-			bool? okInitialFocused = null;
-			bool? cancelInitialFocused = null;
-			var okClicked = false;
-			var closing = false;
-			var cursorRight = false;
-			var endingKeyPress = false;
-			var closed = false;
-
-			var top = Application.Top;
-
-			var ok = new Button ("Ok");
-			ok.Clicked += () => {
-				if (!okClicked) {
-					okClicked = true;
-					Application.RequestStop ();
-				}
-			};
-
-			var cancel = new Button ("Cancel");
-
-			var d = new Dialog ("Quit", cancel, ok);
-			d.KeyPress += (e) => {
-				if (e.KeyEvent.Key == (Key.Q | Key.CtrlMask)) {
-					if (!okClicked && !closing) {
-						okInitialFocused = ok.HasFocus;
-						cancelInitialFocused = cancel.HasFocus;
-						closing = true;
-						var mKeys = new Stack<ConsoleKeyInfo> ();
-						var cki = new ConsoleKeyInfo ('\0', ConsoleKey.Enter, false, false, false);
-						mKeys.Push (cki);
-						cki = new ConsoleKeyInfo ('\0', ConsoleKey.RightArrow, false, false, false);
-						mKeys.Push (cki);
-						FakeConsole.MockKeyPresses = mKeys;
-					}
-					e.Handled = true;
-				} else if (e.KeyEvent.Key == Key.CursorRight) {
-					if (!cursorRight) {
-						cursorRight = true;
-					} else if (ok.HasFocus) {
-						e.Handled = endingKeyPress = true;
-					}
-				}
-			};
-			d.Loaded += () => {
-				var mKeys = new Stack<ConsoleKeyInfo> ();
-				var cki = new ConsoleKeyInfo ('q', ConsoleKey.Q, false, false, true);
-				mKeys.Push (cki);
-				FakeConsole.MockKeyPresses = mKeys;
-			};
-			d.Closed += (_) => {
-				if (okClicked && closing) {
-					closed = true;
-				}
-			};
-
-			top.Ready += () => Application.Run (d);
-
-			Application.Iteration += () => {
-				if (closed) {
-					Application.RequestStop ();
-				}
-			};
-
-			Application.Run ();
-
-			Assert.False (okInitialFocused);
-			Assert.True (cancelInitialFocused);
-			Assert.True (okClicked);
-			Assert.True (closing);
-			Assert.True (cursorRight);
-			Assert.True (endingKeyPress);
-			Assert.True (closed);
-			Assert.Empty (FakeConsole.MockKeyPresses);
-		}
-
+		
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void AddRune_On_Clip_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
 		public void AddRune_On_Clip_Left_Or_Right_Replace_Previous_Or_Next_Wide_Rune_With_Space ()
 		{
 		{
@@ -670,33 +451,21 @@ namespace Terminal.Gui.ConsoleDrivers {
 		[ClassData (typeof (PacketTest))]
 		[ClassData (typeof (PacketTest))]
 		public void TestVKPacket (uint unicodeCharacter, bool shift, bool alt, bool control, uint initialVirtualKey, uint initialScanCode, Key expectedRemapping, uint expectedVirtualKey, uint expectedScanCode)
 		public void TestVKPacket (uint unicodeCharacter, bool shift, bool alt, bool control, uint initialVirtualKey, uint initialScanCode, Key expectedRemapping, uint expectedVirtualKey, uint expectedScanCode)
 		{
 		{
-			ConsoleModifiers modifiers = new ConsoleModifiers ();
-			if (shift) {
-				modifiers |= ConsoleModifiers.Shift;
-			}
-			if (alt) {
-				modifiers |= ConsoleModifiers.Alt;
-			}
-			if (control) {
-				modifiers |= ConsoleModifiers.Control;
-			}
+			var modifiers = new ConsoleModifiers ();
+			if (shift) modifiers |= ConsoleModifiers.Shift;
+			if (alt) modifiers |= ConsoleModifiers.Alt;
+			if (control) modifiers |= ConsoleModifiers.Control;
 			var mappedConsoleKey = ConsoleKeyMapping.GetConsoleKeyFromKey (unicodeCharacter, modifiers, out uint scanCode, out uint outputChar);
 			var mappedConsoleKey = ConsoleKeyMapping.GetConsoleKeyFromKey (unicodeCharacter, modifiers, out uint scanCode, out uint outputChar);
 
 
-			if ((scanCode > 0 || mappedConsoleKey == 0) && mappedConsoleKey == initialVirtualKey) {
-				Assert.Equal (mappedConsoleKey, initialVirtualKey);
-			} else {
-				Assert.Equal (mappedConsoleKey, outputChar < 0xff ? (uint)(outputChar & 0xff | 0xff << 8) : outputChar);
-			}
+			if ((scanCode > 0 || mappedConsoleKey == 0) && mappedConsoleKey == initialVirtualKey) Assert.Equal (mappedConsoleKey, initialVirtualKey);
+			else Assert.Equal (mappedConsoleKey, outputChar < 0xff ? outputChar & 0xff | 0xff << 8 : outputChar);
 			Assert.Equal (scanCode, initialScanCode);
 			Assert.Equal (scanCode, initialScanCode);
 
 
 			var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (mappedConsoleKey, modifiers, out uint consoleKey, out scanCode);
 			var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (mappedConsoleKey, modifiers, out uint consoleKey, out scanCode);
 
 
 			//if (scanCode > 0 && consoleKey == keyChar && consoleKey > 48 && consoleKey > 57 && consoleKey < 65 && consoleKey > 91) {
 			//if (scanCode > 0 && consoleKey == keyChar && consoleKey > 48 && consoleKey > 57 && consoleKey < 65 && consoleKey > 91) {
-			if (scanCode > 0 && keyChar == 0 && consoleKey == mappedConsoleKey) {
-				Assert.Equal (0, (double)keyChar);
-			} else {
-				Assert.Equal (keyChar, unicodeCharacter);
-			}
+			if (scanCode > 0 && keyChar == 0 && consoleKey == mappedConsoleKey) Assert.Equal (0, (double)keyChar);
+			else Assert.Equal (keyChar, unicodeCharacter);
 			Assert.Equal (consoleKey, expectedVirtualKey);
 			Assert.Equal (consoleKey, expectedVirtualKey);
 			Assert.Equal (scanCode, expectedScanCode);
 			Assert.Equal (scanCode, expectedScanCode);
 
 
@@ -713,9 +482,7 @@ namespace Terminal.Gui.ConsoleDrivers {
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
 				iterations++;
 				iterations++;
-				if (iterations == 0) {
-					Application.Driver.SendKeys ((char)mappedConsoleKey, ConsoleKey.Packet, shift, alt, control);
-				}
+				if (iterations == 0) Application.Driver.SendKeys ((char)mappedConsoleKey, ConsoleKey.Packet, shift, alt, control);
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();

+ 1 - 1
UnitTests/KeyTests.cs → UnitTests/Drivers/KeyTests.cs

@@ -1,7 +1,7 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.DriverTests {
 	public class KeyTests {
 	public class KeyTests {
 		enum SimpleEnum { Zero, One, Two, Three, Four, Five }
 		enum SimpleEnum { Zero, One, Two, Three, Four, Five }
 
 

+ 1 - 1
UnitTests/LineCanvasTests.cs

@@ -226,7 +226,7 @@ namespace Terminal.Gui.Core {
 				Bounds = new Rect (0, 0, 10, 5)
 				Bounds = new Rect (0, 0, 10, 5)
 			};
 			};
 
 
-			var canvasCopy = canvas =  new LineCanvas (Application.Driver);
+			var canvasCopy = canvas =  new LineCanvas ();
 			v.DrawContentComplete += (r)=> canvasCopy.Draw (v, v.Bounds);
 			v.DrawContentComplete += (r)=> canvasCopy.Draw (v, v.Bounds);
 
 
 			return v;
 			return v;

+ 2 - 2
UnitTests/ContextMenuTests.cs → UnitTests/Menus/ContextMenuTests.cs

@@ -2,9 +2,9 @@
 using System.Threading;
 using System.Threading;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
-using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
+//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.MenuTests {
 	public class ContextMenuTests {
 	public class ContextMenuTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 2 - 2
UnitTests/MenuTests.cs → UnitTests/Menus/MenuTests.cs

@@ -3,9 +3,9 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
-using static Terminal.Gui.Views.MenuTests;
+//using static Terminal.Gui.ViewTests.MenuTests;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.MenuTests {
 	public class MenuTests {
 	public class MenuTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 6 - 6
UnitTests/TestHelpers.cs

@@ -37,9 +37,9 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
 	/// <param name="fakeClipboardIsSupportedAlwaysTrue">Only valid if <paramref name="autoInit"/> is true.
 	/// <param name="fakeClipboardIsSupportedAlwaysTrue">Only valid if <paramref name="autoInit"/> is true.
 	/// Only valid if <see cref="consoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.</param>
 	/// Only valid if <see cref="consoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.</param>
 	public AutoInitShutdownAttribute (bool autoInit = true, bool autoShutdown = true,
 	public AutoInitShutdownAttribute (bool autoInit = true, bool autoShutdown = true,
-		Type consoleDriverType = null, 
-		bool useFakeClipboard = false, 
-		bool fakeClipboardAlwaysThrowsNotSupportedException = false, 
+		Type consoleDriverType = null,
+		bool useFakeClipboard = false,
+		bool fakeClipboardAlwaysThrowsNotSupportedException = false,
 		bool fakeClipboardIsSupportedAlwaysTrue = false)
 		bool fakeClipboardIsSupportedAlwaysTrue = false)
 	{
 	{
 		//Assert.True (autoInit == false && consoleDriverType == null);
 		//Assert.True (autoInit == false && consoleDriverType == null);
@@ -54,7 +54,7 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
 
 
 	static bool _init = false;
 	static bool _init = false;
 	bool AutoInit { get; }
 	bool AutoInit { get; }
-	bool AutoShutdown { get;  }
+	bool AutoShutdown { get; }
 	Type DriverType;
 	Type DriverType;
 
 
 	public override void Before (MethodInfo methodUnderTest)
 	public override void Before (MethodInfo methodUnderTest)
@@ -251,7 +251,7 @@ class TestHelpers {
 
 
 				var match = expectedColors.Where (e => e.Value == val).ToList ();
 				var match = expectedColors.Where (e => e.Value == val).ToList ();
 				if (match.Count == 0) {
 				if (match.Count == 0) {
-					throw new Exception ($"Unexpected color {DescribeColor (val)} was used at row {r} and col {c} (indexes start at 0).  Color value was {val} (expected colors were {string.Join (",", expectedColors.Select (c => c.Value))})");
+					throw new Exception ($"Unexpected color {DescribeColor (val)} was used at row {r} and col {c} (indexes start at 0).  Color value was {val} (expected colors were {string.Join (",", expectedColors.Select (c => DescribeColor (c.Value)))})");
 				} else if (match.Count > 1) {
 				} else if (match.Count > 1) {
 					throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
 					throw new ArgumentException ($"Bad value for expectedColors, {match.Count} Attributes had the same Value");
 				}
 				}
@@ -260,7 +260,7 @@ class TestHelpers {
 				var userExpected = line [c];
 				var userExpected = line [c];
 
 
 				if (colorUsed != userExpected) {
 				if (colorUsed != userExpected) {
-					throw new Exception ($"Colors used did not match expected at row {r} and col {c} (indexes start at 0).  Color index used was {DescribeColor (colorUsed)} but test expected {DescribeColor (userExpected)} (these are indexes into the expectedColors array)");
+					throw new Exception ($"Colors used did not match expected at row {r} and col {c} (indexes start at 0).  Color index used was {colorUsed} ({DescribeColor (val)}) but test expected {userExpected} ({DescribeColor (expectedColors [int.Parse (userExpected.ToString ())].Value)}) (these are indexes into the expectedColors array)");
 				}
 				}
 			}
 			}
 
 

+ 1 - 1
UnitTests/CollectionNavigatorTests.cs → UnitTests/Text/CollectionNavigatorTests.cs

@@ -2,7 +2,7 @@
 using System.Threading;
 using System.Threading;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TextTests {
 	public class CollectionNavigatorTests {
 	public class CollectionNavigatorTests {
 		static string [] simpleStrings = new string []{
 		static string [] simpleStrings = new string []{
 		    "appricot", // 0
 		    "appricot", // 0

+ 63 - 34
UnitTests/TextFormatterTests.cs → UnitTests/Text/TextFormatterTests.cs

@@ -2,14 +2,14 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
-using Terminal.Gui.Views;
+using Terminal.Gui;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TextTests {
 	public class TextFormatterTests {
 	public class TextFormatterTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -394,7 +394,7 @@ namespace Terminal.Gui.Core {
 			bool supportFirstUpperCase = true;
 			bool supportFirstUpperCase = true;
 
 
 			var text = ustring.Empty;
 			var text = ustring.Empty;
-			Rune hotKeySpecifier = (Rune)0;
+			var hotKeySpecifier = (Rune)0;
 			int hotPos = 0;
 			int hotPos = 0;
 			Key hotKey = Key.Unknown;
 			Key hotKey = Key.Unknown;
 			bool result = false;
 			bool result = false;
@@ -437,7 +437,7 @@ namespace Terminal.Gui.Core {
 			bool supportFirstUpperCase = true;
 			bool supportFirstUpperCase = true;
 
 
 			var text = ustring.Empty;
 			var text = ustring.Empty;
-			Rune hotKeySpecifier = (Rune)0;
+			var hotKeySpecifier = (Rune)0;
 			int hotPos = 0;
 			int hotPos = 0;
 			Key hotKey = Key.Unknown;
 			Key hotKey = Key.Unknown;
 			bool result = false;
 			bool result = false;
@@ -2162,9 +2162,7 @@ namespace Terminal.Gui.Core {
 			var height = 8;
 			var height = 8;
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var breakLines = "";
 			var breakLines = "";
-			foreach (var line in wrappedLines) {
-				breakLines += $"{line}{Environment.NewLine}";
-			}
+			foreach (var line in wrappedLines) 				breakLines += $"{line}{Environment.NewLine}";
 			var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
 			var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
 			var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
 			var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
 
 
@@ -2202,9 +2200,7 @@ namespace Terminal.Gui.Core {
 			var height = 3;
 			var height = 3;
 			var wrappedLines = TextFormatter.WordWrap (text, height, true);
 			var wrappedLines = TextFormatter.WordWrap (text, height, true);
 			var breakLines = "";
 			var breakLines = "";
-			for (int i = 0; i < wrappedLines.Count; i++) {
-				breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
-			}
+			for (int i = 0; i < wrappedLines.Count; i++) 				breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
 			var label = new Label (breakLines) {
 			var label = new Label (breakLines) {
 				TextDirection = TextDirection.TopBottom_LeftRight,
 				TextDirection = TextDirection.TopBottom_LeftRight,
 				Width = Dim.Fill (),
 				Width = Dim.Fill (),
@@ -2241,9 +2237,7 @@ namespace Terminal.Gui.Core {
 			var height = 8;
 			var height = 8;
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var breakLines = "";
 			var breakLines = "";
-			foreach (var line in wrappedLines) {
-				breakLines += $"{line}{Environment.NewLine}";
-			}
+			foreach (var line in wrappedLines) 				breakLines += $"{line}{Environment.NewLine}";
 			var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
 			var label = new Label (breakLines) { Width = Dim.Fill (), Height = Dim.Fill () };
 			var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
 			var frame = new FrameView () { Width = Dim.Fill (), Height = Dim.Fill () };
 
 
@@ -2282,9 +2276,7 @@ namespace Terminal.Gui.Core {
 			var height = 4;
 			var height = 4;
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var wrappedLines = TextFormatter.WordWrap (text, width, true);
 			var breakLines = "";
 			var breakLines = "";
-			for (int i = 0; i < wrappedLines.Count; i++) {
-				breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
-			}
+			for (int i = 0; i < wrappedLines.Count; i++) 				breakLines += $"{wrappedLines [i]}{(i < wrappedLines.Count - 1 ? Environment.NewLine : string.Empty)}";
 			var label = new Label (breakLines) {
 			var label = new Label (breakLines) {
 				TextDirection = TextDirection.TopBottom_LeftRight,
 				TextDirection = TextDirection.TopBottom_LeftRight,
 				Width = Dim.Fill (),
 				Width = Dim.Fill (),
@@ -2433,13 +2425,13 @@ namespace Terminal.Gui.Core {
 			Assert.Equal (ustring.Make (new Rune [] { 't', tag, 's', 't' }), tf.ReplaceHotKeyWithTag (text, hotPos));
 			Assert.Equal (ustring.Make (new Rune [] { 't', tag, 's', 't' }), tf.ReplaceHotKeyWithTag (text, hotPos));
 
 
 			var result = tf.ReplaceHotKeyWithTag (text, hotPos);
 			var result = tf.ReplaceHotKeyWithTag (text, hotPos);
-			Assert.Equal ('e', (uint)(result.ToRunes () [1]));
+			Assert.Equal ('e', result.ToRunes () [1]);
 
 
 			text = "Ok";
 			text = "Ok";
 			tag = 'O';
 			tag = 'O';
 			hotPos = 0;
 			hotPos = 0;
 			Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
 			Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
-			Assert.Equal ('O', (uint)(result.ToRunes () [0]));
+			Assert.Equal ('O', result.ToRunes () [0]);
 
 
 			text = "[◦ Ok ◦]";
 			text = "[◦ Ok ◦]";
 			text = ustring.Make (new Rune [] { '[', '◦', ' ', 'O', 'k', ' ', '◦', ']' });
 			text = ustring.Make (new Rune [] { '[', '◦', ' ', 'O', 'k', ' ', '◦', ']' });
@@ -2449,13 +2441,13 @@ namespace Terminal.Gui.Core {
 			tag = 'O';
 			tag = 'O';
 			hotPos = 3;
 			hotPos = 3;
 			Assert.Equal (ustring.Make (new Rune [] { '[', '◦', ' ', tag, 'k', ' ', '◦', ']' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
 			Assert.Equal (ustring.Make (new Rune [] { '[', '◦', ' ', tag, 'k', ' ', '◦', ']' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
-			Assert.Equal ('O', (uint)(result.ToRunes () [3]));
+			Assert.Equal ('O', result.ToRunes () [3]);
 
 
 			text = "^k";
 			text = "^k";
 			tag = '^';
 			tag = '^';
 			hotPos = 0;
 			hotPos = 0;
 			Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
 			Assert.Equal (ustring.Make (new Rune [] { tag, 'k' }), result = tf.ReplaceHotKeyWithTag (text, hotPos));
-			Assert.Equal ('^', (uint)(result.ToRunes () [0]));
+			Assert.Equal ('^', result.ToRunes () [0]);
 		}
 		}
 
 
 		[Fact]
 		[Fact]
@@ -2814,37 +2806,37 @@ namespace Terminal.Gui.Core {
 		[Fact]
 		[Fact]
 		public void System_Rune_ColumnWidth ()
 		public void System_Rune_ColumnWidth ()
 		{
 		{
-			var c = new System.Rune ('a');
+			var c = new Rune ('a');
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).Length);
 			Assert.Equal (1, ustring.Make (c).Length);
 
 
-			c = new System.Rune ('b');
+			c = new Rune ('b');
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).Length);
 			Assert.Equal (1, ustring.Make (c).Length);
 
 
-			c = new System.Rune (123);
+			c = new Rune (123);
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, Rune.ColumnWidth (c));
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).Length);
 			Assert.Equal (1, ustring.Make (c).Length);
 
 
-			c = new System.Rune ('\u1150');
+			c = new Rune ('\u1150');
 			Assert.Equal (2, Rune.ColumnWidth (c));      // 0x1150	ᅐ	Unicode Technical Report #11
 			Assert.Equal (2, Rune.ColumnWidth (c));      // 0x1150	ᅐ	Unicode Technical Report #11
 			Assert.Equal (2, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (2, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (3, ustring.Make (c).Length);
 			Assert.Equal (3, ustring.Make (c).Length);
 
 
-			c = new System.Rune ('\u1161');
+			c = new Rune ('\u1161');
 			Assert.Equal (0, Rune.ColumnWidth (c));      // 0x1161	ᅡ	column width of 0
 			Assert.Equal (0, Rune.ColumnWidth (c));      // 0x1161	ᅡ	column width of 0
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (3, ustring.Make (c).Length);
 			Assert.Equal (3, ustring.Make (c).Length);
 
 
-			c = new System.Rune (31);
+			c = new Rune (31);
 			Assert.Equal (-1, Rune.ColumnWidth (c));        // non printable character
 			Assert.Equal (-1, Rune.ColumnWidth (c));        // non printable character
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);// ConsoleWidth only returns zero or greater than zero
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);// ConsoleWidth only returns zero or greater than zero
 			Assert.Equal (1, ustring.Make (c).Length);
 			Assert.Equal (1, ustring.Make (c).Length);
 
 
-			c = new System.Rune (127);
+			c = new Rune (127);
 			Assert.Equal (-1, Rune.ColumnWidth (c));       // non printable character
 			Assert.Equal (-1, Rune.ColumnWidth (c));       // non printable character
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (0, ustring.Make (c).ConsoleWidth);
 			Assert.Equal (1, ustring.Make (c).Length);
 			Assert.Equal (1, ustring.Make (c).Length);
@@ -2896,9 +2888,7 @@ namespace Terminal.Gui.Core {
 			Assert.Equal ("nd", list1 [10].ToString ());
 			Assert.Equal ("nd", list1 [10].ToString ());
 			Assert.Equal ("Line", list1 [11].ToString ());
 			Assert.Equal ("Line", list1 [11].ToString ());
 			Assert.Equal ("- 2.", list1 [^1].ToString ());
 			Assert.Equal ("- 2.", list1 [^1].ToString ());
-			foreach (var txt in list1) {
-				wrappedText1 += txt;
-			}
+			foreach (var txt in list1) 				wrappedText1 += txt;
 			Assert.Equal (" Asentencehaswords.  This isthesecondLine- 2.", wrappedText1);
 			Assert.Equal (" Asentencehaswords.  This isthesecondLine- 2.", wrappedText1);
 
 
 			// With preserveTrailingSpaces = true.
 			// With preserveTrailingSpaces = true.
@@ -2920,9 +2910,7 @@ namespace Terminal.Gui.Core {
 			Assert.Equal ("Line", list2 [13].ToString ());
 			Assert.Equal ("Line", list2 [13].ToString ());
 			Assert.Equal (" - ", list2 [14].ToString ());
 			Assert.Equal (" - ", list2 [14].ToString ());
 			Assert.Equal ("2. ", list2 [^1].ToString ());
 			Assert.Equal ("2. ", list2 [^1].ToString ());
-			foreach (var txt in list2) {
-				wrappedText2 += txt;
-			}
+			foreach (var txt in list2) 				wrappedText2 += txt;
 			Assert.Equal (" A sentence has words.  This is the second Line - 2. ", wrappedText2);
 			Assert.Equal (" A sentence has words.  This is the second Line - 2. ", wrappedText2);
 		}
 		}
 
 
@@ -3430,7 +3418,7 @@ This TextFormatter (tf2) is rewritten.
 		[Fact]
 		[Fact]
 		public void GetSumMaxCharWidth_List_Simple_And_Wide_Runes ()
 		public void GetSumMaxCharWidth_List_Simple_And_Wide_Runes ()
 		{
 		{
-			List<ustring> text = new List<ustring> () { "Hello", "World" };
+			var text = new List<ustring> () { "Hello", "World" };
 			Assert.Equal (2, TextFormatter.GetSumMaxCharWidth (text));
 			Assert.Equal (2, TextFormatter.GetSumMaxCharWidth (text));
 			Assert.Equal (1, TextFormatter.GetSumMaxCharWidth (text, 1, 1));
 			Assert.Equal (1, TextFormatter.GetSumMaxCharWidth (text, 1, 1));
 			text = new List<ustring> () { "こんにちは", "世界" };
 			text = new List<ustring> () { "こんにちは", "世界" };
@@ -4259,5 +4247,46 @@ This TextFormatter (tf2) is rewritten.
 0111000000
 0111000000
 0000000000", expectedColors);
 0000000000", expectedColors);
 		}
 		}
+
+		[Fact, AutoInitShutdown]
+		public void Colors_On_TextAlignment_Right_And_Bottom ()
+		{
+			var labelRight = new Label ("Test") {
+				Width = 6,
+				Height = 1,
+				TextAlignment = TextAlignment.Right,
+				ColorScheme = Colors.Base
+			};
+			var labelBottom = new Label ("Test", TextDirection.TopBottom_LeftRight) {
+				Y = 1,
+				Width = 1,
+				Height = 6,
+				VerticalTextAlignment = VerticalTextAlignment.Bottom,
+				ColorScheme = Colors.Base
+			};
+			var top = Application.Top;
+			top.Add (labelRight, labelBottom);
+
+			Application.Begin (top);
+			((FakeDriver)Application.Driver).SetBufferSize (7, 7);
+
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+  Test
+      
+      
+T     
+e     
+s     
+t     ", output);
+
+			TestHelpers.AssertDriverColorsAre (@"
+000000
+0
+0
+0
+0
+0
+0", new Attribute [] { Colors.Base.Normal });
+		}
 	}
 	}
 }
 }

+ 34 - 34
UnitTests/DialogTests.cs → UnitTests/TopLevels/DialogTests.cs

@@ -9,7 +9,7 @@ using System.Globalization;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using NStack;
 using NStack;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.TopLevelTests {
 
 
 	public class DialogTests {
 	public class DialogTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
@@ -29,7 +29,7 @@ namespace Terminal.Gui.Views {
 		[AutoInitShutdown]
 		[AutoInitShutdown]
 		public void ButtonAlignment_One ()
 		public void ButtonAlignment_One ()
 		{
 		{
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
 			var title = "1234";
 			var title = "1234";
@@ -37,8 +37,8 @@ namespace Terminal.Gui.Views {
 			var btnText = "ok";
 			var btnText = "ok";
 			var buttonRow = $"{d.VLine}   {d.LeftBracket} {btnText} {d.RightBracket}   {d.VLine}";
 			var buttonRow = $"{d.VLine}   {d.LeftBracket} {btnText} {d.RightBracket}   {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 
 
 			d.SetBufferSize (width, 3);
 			d.SetBufferSize (width, 3);
 
 
@@ -74,7 +74,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			// E.g "|[ yes ][ no ]|"
 			// E.g "|[ yes ][ no ]|"
@@ -85,8 +85,8 @@ namespace Terminal.Gui.Views {
 
 
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 
 
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
@@ -123,7 +123,7 @@ namespace Terminal.Gui.Views {
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 			bool firstIteration = false;
 			bool firstIteration = false;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			// E.g "|[ yes ][ no ]|"
 			// E.g "|[ yes ][ no ]|"
@@ -134,8 +134,8 @@ namespace Terminal.Gui.Views {
 
 
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 
 
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
@@ -191,7 +191,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			// E.g "|[ yes ][ no ][ maybe ]|"
 			// E.g "|[ yes ][ no ][ maybe ]|"
@@ -204,8 +204,8 @@ namespace Terminal.Gui.Views {
 
 
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3} {d.VLine}";
 			var buttonRow = $@"{d.VLine} {btn1} {btn2} {btn3} {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 
 
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
@@ -241,7 +241,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 
 
@@ -257,8 +257,8 @@ namespace Terminal.Gui.Views {
 
 
 			var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
 			var buttonRow = $"{d.VLine} {btn1} {btn2} {btn3} {btn4} {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
 			// Default - Center
 			// Default - Center
@@ -294,7 +294,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 
 
@@ -349,7 +349,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 
 
@@ -368,8 +368,8 @@ namespace Terminal.Gui.Views {
 			//                         12345                           123456
 			//                         12345                           123456
 			var buttonRow = $"{d.VLine}     {btn1} {btn2} {btn3} {btn4}      {d.VLine}";
 			var buttonRow = $"{d.VLine}     {btn1} {btn2} {btn3} {btn4}      {d.VLine}";
 			var width = ustring.Make (buttonRow).ConsoleWidth;
 			var width = ustring.Make (buttonRow).ConsoleWidth;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 			d.SetBufferSize (width, 3);
 			d.SetBufferSize (width, 3);
 
 
 			// Default - Center
 			// Default - Center
@@ -405,7 +405,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 
 
@@ -423,8 +423,8 @@ namespace Terminal.Gui.Views {
 			//                         12345                          123456
 			//                         12345                          123456
 			var buttonRow = $"{d.VLine}     {btn1} {btn2} {btn3} {btn4}      {d.VLine}";
 			var buttonRow = $"{d.VLine}     {btn1} {btn2} {btn3} {btn4}      {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
 			// Default - Center
 			// Default - Center
@@ -460,14 +460,14 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 
 
 			var buttonRow = $"{d.VLine}        {d.VLine}";
 			var buttonRow = $"{d.VLine}        {d.VLine}";
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
 			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
 			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
@@ -482,15 +482,15 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			var btnText = "ok";
 			var btnText = "ok";
 			var buttonRow = $"{d.VLine}   {d.LeftBracket} {btnText} {d.RightBracket}   {d.VLine}";
 			var buttonRow = $"{d.VLine}   {d.LeftBracket} {btnText} {d.RightBracket}   {d.VLine}";
 
 
 			var width = buttonRow.Length;
 			var width = buttonRow.Length;
-			var topRow = $"┌ {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}┐";
-			var bottomRow = $"└{new String (d.HLine.ToString () [0], width - 2)}┘";
+			var topRow = $"┌ {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}┐";
+			var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
 			d.SetBufferSize (buttonRow.Length, 3);
 			d.SetBufferSize (buttonRow.Length, 3);
 
 
 			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
 			(runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
@@ -504,7 +504,7 @@ namespace Terminal.Gui.Views {
 		{
 		{
 			Application.RunState runstate = null;
 			Application.RunState runstate = null;
 
 
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			var btn1Text = "yes";
 			var btn1Text = "yes";
@@ -516,8 +516,8 @@ namespace Terminal.Gui.Views {
 			var width = $@"{d.VLine} {btn1} {btn2} {d.VLine}".Length;
 			var width = $@"{d.VLine} {btn1} {btn2} {d.VLine}".Length;
 			d.SetBufferSize (width, 3);
 			d.SetBufferSize (width, 3);
 
 
-			var topRow = $"{d.ULCorner} {title} {new String (d.HLine.ToString () [0], width - title.Length - 4)}{d.URCorner}";
-			var bottomRow = $"{d.LLCorner}{new String (d.HLine.ToString () [0], width - 2)}{d.LRCorner}";
+			var topRow = $"{d.ULCorner} {title} {new string (d.HLine.ToString () [0], width - title.Length - 4)}{d.URCorner}";
+			var bottomRow = $"{d.LLCorner}{new string (d.HLine.ToString () [0], width - 2)}{d.LRCorner}";
 
 
 			// Default (center)
 			// Default (center)
 			var dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
 			var dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Center };
@@ -550,7 +550,7 @@ namespace Terminal.Gui.Views {
 			// Right
 			// Right
 			dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
 			dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Right };
 			runstate = Application.Begin (dlg);
 			runstate = Application.Begin (dlg);
-			buttonRow = $"{d.VLine}{new String (' ', width - btn1.Length - 2)}{btn1}{d.VLine}";
+			buttonRow = $"{d.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{d.VLine}";
 			TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
 			TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
 
 
 			// Now add a second button
 			// Now add a second button
@@ -564,7 +564,7 @@ namespace Terminal.Gui.Views {
 			// Left
 			// Left
 			dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
 			dlg = new Dialog (title, width, 3, new Button (btn1Text)) { ButtonAlignment = Dialog.ButtonAlignments.Left };
 			runstate = Application.Begin (dlg);
 			runstate = Application.Begin (dlg);
-			buttonRow = $"{d.VLine}{btn1}{new String (' ', width - btn1.Length - 2)}{d.VLine}";
+			buttonRow = $"{d.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{d.VLine}";
 			TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
 			TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
 
 
 			// Now add a second button
 			// Now add a second button

+ 16 - 37
UnitTests/MdiTests.cs → UnitTests/TopLevels/MdiTests.cs

@@ -3,12 +3,13 @@ using System.Diagnostics;
 using System.Linq;
 using System.Linq;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using Terminal.Gui;
 using Xunit;
 using Xunit;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TopLevelTests {
 	public class MdiTests {
 	public class MdiTests {
 		public MdiTests ()
 		public MdiTests ()
 		{
 		{
@@ -94,17 +95,11 @@ namespace Terminal.Gui.Core {
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
 				Assert.Null (Application.MdiChildes);
 				Assert.Null (Application.MdiChildes);
-				if (iterations == 4) {
-					Assert.True (Application.Current == d);
-				} else if (iterations == 3) {
-					Assert.True (Application.Current == top4);
-				} else if (iterations == 2) {
-					Assert.True (Application.Current == top3);
-				} else if (iterations == 1) {
-					Assert.True (Application.Current == top2);
-				} else {
-					Assert.True (Application.Current == top1);
-				}
+				if (iterations == 4) 					Assert.True (Application.Current == d);
+else if (iterations == 3) 					Assert.True (Application.Current == top4);
+else if (iterations == 2) 					Assert.True (Application.Current == top3);
+else if (iterations == 1) 					Assert.True (Application.Current == top2);
+else 					Assert.True (Application.Current == top1);
 				Application.RequestStop (top1);
 				Application.RequestStop (top1);
 				iterations--;
 				iterations--;
 			};
 			};
@@ -171,9 +166,7 @@ namespace Terminal.Gui.Core {
 					Assert.False (d.Running);
 					Assert.False (d.Running);
 				} else {
 				} else {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
-					for (int i = 0; i < iterations; i++) {
-						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
-					}
+					for (int i = 0; i < iterations; i++) 						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
 				}
 				}
 				iterations--;
 				iterations--;
 			};
 			};
@@ -231,9 +224,7 @@ namespace Terminal.Gui.Core {
 					Assert.False (d.Running);
 					Assert.False (d.Running);
 				} else {
 				} else {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
-					for (int i = 0; i < iterations; i++) {
-						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
-					}
+					for (int i = 0; i < iterations; i++) 						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
 				}
 				}
 				iterations--;
 				iterations--;
 			};
 			};
@@ -292,9 +283,7 @@ namespace Terminal.Gui.Core {
 					Assert.False (d.Running);
 					Assert.False (d.Running);
 				} else {
 				} else {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
-					for (int i = 0; i < iterations; i++) {
-						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
-					}
+					for (int i = 0; i < iterations; i++) 						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
 				}
 				}
 				iterations--;
 				iterations--;
 			};
 			};
@@ -392,9 +381,7 @@ namespace Terminal.Gui.Core {
 					Assert.False (Application.Current.Running);
 					Assert.False (Application.Current.Running);
 				} else {
 				} else {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
-					for (int i = 0; i < iterations; i++) {
-						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
-					}
+					for (int i = 0; i < iterations; i++) 						Assert.Equal ((iterations - i + 1).ToString (), Application.MdiChildes [i].Id);
 				}
 				}
 				iterations--;
 				iterations--;
 			};
 			};
@@ -461,10 +448,8 @@ namespace Terminal.Gui.Core {
 					Assert.True (c4.Running);
 					Assert.True (c4.Running);
 				} else {
 				} else {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
-					for (int i = 0; i < iterations; i++) {
-						Assert.Equal ((iterations - i + (iterations == 4 && i == 0 ? 2 : 1)).ToString (),
+					for (int i = 0; i < iterations; i++) 						Assert.Equal ((iterations - i + (iterations == 4 && i == 0 ? 2 : 1)).ToString (),
 							Application.MdiChildes [i].Id);
 							Application.MdiChildes [i].Id);
-					}
 				}
 				}
 				iterations--;
 				iterations--;
 			};
 			};
@@ -586,9 +571,7 @@ namespace Terminal.Gui.Core {
 					};
 					};
 
 
 					stage.Closed += (_) => {
 					stage.Closed += (_) => {
-						if (iterations == 11) {
-							allStageClosed = true;
-						}
+						if (iterations == 11) 							allStageClosed = true;
 						Assert.Equal (iterations, Application.MdiChildes.Count);
 						Assert.Equal (iterations, Application.MdiChildes.Count);
 						if (running) {
 						if (running) {
 							stageCompleted = true;
 							stageCompleted = true;
@@ -610,16 +593,12 @@ namespace Terminal.Gui.Core {
 					running = false;
 					running = false;
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 
 
-				} else if (!mdiRequestStop && running && !allStageClosed) {
-					Assert.Equal (iterations, Application.MdiChildes.Count);
-
-				} else if (!mdiRequestStop && !running && allStageClosed) {
+				} else if (!mdiRequestStop && running && !allStageClosed) 					Assert.Equal (iterations, Application.MdiChildes.Count);
+else if (!mdiRequestStop && !running && allStageClosed) {
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					Assert.Equal (iterations, Application.MdiChildes.Count);
 					mdiRequestStop = true;
 					mdiRequestStop = true;
 					mdi.RequestStop ();
 					mdi.RequestStop ();
-				} else {
-					Assert.Empty (Application.MdiChildes);
-				}
+				} else 					Assert.Empty (Application.MdiChildes);
 			};
 			};
 
 
 			Application.Run (mdi);
 			Application.Run (mdi);

+ 3 - 2
UnitTests/MessageBoxTests.cs → UnitTests/TopLevels/MessageBoxTests.cs

@@ -2,8 +2,9 @@
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using System.Text;
 using System.Text;
+using Terminal.Gui;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.TopLevelTests {
 
 
 	public class MessageBoxTests {
 	public class MessageBoxTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
@@ -54,7 +55,7 @@ namespace Terminal.Gui.Views {
 				iterations++;
 				iterations++;
 
 
 				if (iterations == 0) {
 				if (iterations == 0) {
-					StringBuilder aboutMessage = new StringBuilder ();
+					var aboutMessage = new StringBuilder ();
 					aboutMessage.AppendLine (@"A comprehensive sample library for");
 					aboutMessage.AppendLine (@"A comprehensive sample library for");
 					aboutMessage.AppendLine (@"");
 					aboutMessage.AppendLine (@"");
 					aboutMessage.AppendLine (@"  _______                  _             _   _____       _  ");
 					aboutMessage.AppendLine (@"  _______                  _             _   _____       _  ");

+ 7 - 13
UnitTests/ToplevelTests.cs → UnitTests/TopLevels/ToplevelTests.cs

@@ -1,8 +1,9 @@
 using System;
 using System;
+using Terminal.Gui;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TopLevelTests {
 	public class ToplevelTests {
 	public class ToplevelTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -695,8 +696,7 @@ namespace Terminal.Gui.Core {
 					((FakeDriver)Application.Driver).SetBufferSize (40, 15);
 					((FakeDriver)Application.Driver).SetBufferSize (40, 15);
 					MessageBox.Query ("About", "Hello Word", "Ok");
 					MessageBox.Query ("About", "Hello Word", "Ok");
 
 
-				} else if (iterations == 1) {
-					TestHelpers.AssertDriverContentsWithFrameAre (@"
+				} else if (iterations == 1) 					TestHelpers.AssertDriverContentsWithFrameAre (@"
  File                                   
  File                                   
 ┌ Window ──────────────────────────────┐
 ┌ Window ──────────────────────────────┐
 │                                      │
 │                                      │
@@ -712,8 +712,7 @@ namespace Terminal.Gui.Core {
 │                                      │
 │                                      │
 └──────────────────────────────────────┘
 └──────────────────────────────────────┘
  CTRL-N New                             ", output);
  CTRL-N New                             ", output);
-
-				} else if (iterations == 2) {
+else if (iterations == 2) {
 					Assert.Null (Application.MouseGrabView);
 					Assert.Null (Application.MouseGrabView);
 					// Grab the mouse
 					// Grab the mouse
 					ReflectionTools.InvokePrivate (
 					ReflectionTools.InvokePrivate (
@@ -816,11 +815,8 @@ namespace Terminal.Gui.Core {
 
 
 					Assert.Null (Application.MouseGrabView);
 					Assert.Null (Application.MouseGrabView);
 
 
-				} else if (iterations == 8) {
-					Application.RequestStop ();
-				} else if (iterations == 9) {
-					Application.RequestStop ();
-				}
+				} else if (iterations == 8) 					Application.RequestStop ();
+else if (iterations == 9) 					Application.RequestStop ();
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();
@@ -960,9 +956,7 @@ namespace Terminal.Gui.Core {
 
 
 					Assert.Null (Application.MouseGrabView);
 					Assert.Null (Application.MouseGrabView);
 
 
-				} else if (iterations == 8) {
-					Application.RequestStop ();
-				}
+				} else if (iterations == 8) 					Application.RequestStop ();
 			};
 			};
 
 
 			Application.Run ();
 			Application.Run ();

+ 8 - 7
UnitTests/WindowTests.cs → UnitTests/TopLevels/WindowTests.cs

@@ -1,13 +1,14 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
-using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
+//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 using NStack;
 using NStack;
+using Terminal.Gui;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TopLevelTests {
 	public class WindowTests {
 	public class WindowTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -22,7 +23,7 @@ namespace Terminal.Gui.Core {
 			// Parameterless
 			// Parameterless
 			var r = new Window ();
 			var r = new Window ();
 			Assert.NotNull (r);
 			Assert.NotNull (r);
-			Assert.Equal(ustring.Empty, r.Title);
+			Assert.Equal (ustring.Empty, r.Title);
 			Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
 			Assert.Equal (LayoutStyle.Computed, r.LayoutStyle);
 			Assert.Equal ("Window()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
 			Assert.Equal ("Window()({X=0,Y=0,Width=0,Height=0})", r.ToString ());
 			Assert.True (r.CanFocus);
 			Assert.True (r.CanFocus);
@@ -116,13 +117,13 @@ namespace Terminal.Gui.Core {
 			r.Title = expectedDuring = expectedAfter = "title";
 			r.Title = expectedDuring = expectedAfter = "title";
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 
 
-			expectedOld = r.Title.ToString();
+			expectedOld = r.Title.ToString ();
 			r.Title = expectedDuring = expectedAfter = "a different title";
 			r.Title = expectedDuring = expectedAfter = "a different title";
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 
 
 			// Now setup cancelling the change and change it back to "title"
 			// Now setup cancelling the change and change it back to "title"
 			cancel = true;
 			cancel = true;
-			expectedOld = r.Title.ToString();
+			expectedOld = r.Title.ToString ();
 			r.Title = expectedDuring = "title";
 			r.Title = expectedDuring = "title";
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 			Assert.Equal (expectedAfter, r.Title.ToString ());
 			r.Dispose ();
 			r.Dispose ();
@@ -154,7 +155,7 @@ namespace Terminal.Gui.Core {
 			r.Dispose ();
 			r.Dispose ();
 		}
 		}
 
 
-		[Fact,AutoInitShutdown]
+		[Fact, AutoInitShutdown]
 		public void MenuBar_And_StatusBar_Inside_Window ()
 		public void MenuBar_And_StatusBar_Inside_Window ()
 		{
 		{
 			var menu = new MenuBar (new MenuBarItem [] {
 			var menu = new MenuBar (new MenuBarItem [] {
@@ -175,7 +176,7 @@ namespace Terminal.Gui.Core {
 
 
 			var fv = new FrameView ("Frame View") {
 			var fv = new FrameView ("Frame View") {
 				Y = 1,
 				Y = 1,
-				Width = Dim.Fill(),
+				Width = Dim.Fill (),
 				Height = Dim.Fill (1)
 				Height = Dim.Fill (1)
 			};
 			};
 			var win = new Window ();
 			var win = new Window ();

+ 21 - 21
UnitTests/WizardTests.cs → UnitTests/TopLevels/WizardTests.cs

@@ -9,7 +9,7 @@ using System.Globalization;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using NStack;
 using NStack;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.TopLevelTests {
 
 
 	public class WizardTests {
 	public class WizardTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
@@ -92,7 +92,7 @@ namespace Terminal.Gui.Views {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void DefaultConstructor_SizedProperly ()
 		public void DefaultConstructor_SizedProperly ()
 		{
 		{
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var wizard = new Wizard ();
 			var wizard = new Wizard ();
 			Assert.NotEqual (0, wizard.Width);
 			Assert.NotEqual (0, wizard.Width);
@@ -104,7 +104,7 @@ namespace Terminal.Gui.Views {
 		// and that the title is correct
 		// and that the title is correct
 		public void ZeroStepWizard_Shows ()
 		public void ZeroStepWizard_Shows ()
 		{
 		{
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			var stepTitle = "";
 			var stepTitle = "";
@@ -118,12 +118,12 @@ namespace Terminal.Gui.Views {
 			var btnNextText = "Finish";
 			var btnNextText = "Finish";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 
 
-			var topRow = $"{d.ULDCorner} {title}{stepTitle} {new String (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
-			var row2 = $"{d.VDLine}{new String (' ', width - 2)}{d.VDLine}";
+			var topRow = $"{d.ULDCorner} {title}{stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
+			var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
 			var row3 = row2;
 			var row3 = row2;
-			var separatorRow = $"{d.VDLine}{new String (' ', width - 2)}{d.VDLine}";
-			var buttonRow = $"{d.VDLine}{btnBack}{new String (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
-			var bottomRow = $"{d.LLDCorner}{new String (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
+			var separatorRow = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
+			var buttonRow = $"{d.VDLine}{btnBack}{new string (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
+			var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
 
 
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			Application.End (Application.Begin (wizard));
 			Application.End (Application.Begin (wizard));
@@ -135,7 +135,7 @@ namespace Terminal.Gui.Views {
 		// and that the title is correct
 		// and that the title is correct
 		public void OneStepWizard_Shows ()
 		public void OneStepWizard_Shows ()
 		{
 		{
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			var stepTitle = "ABCD";
 			var stepTitle = "ABCD";
@@ -149,13 +149,13 @@ namespace Terminal.Gui.Views {
 			var btnNextText = "Finish"; // "Next";
 			var btnNextText = "Finish"; // "Next";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 
 
-			var topRow = $"{d.ULDCorner} {title} - {stepTitle} {new String (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 7)}{d.URDCorner}";
-			var row2 = $"{d.VDLine}{new String (' ', width - 2)}{d.VDLine}";
+			var topRow = $"{d.ULDCorner} {title} - {stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 7)}{d.URDCorner}";
+			var row2 = $"{d.VDLine}{new string (' ', width - 2)}{d.VDLine}";
 			var row3 = row2;
 			var row3 = row2;
 			var row4 = row3;
 			var row4 = row3;
-			var separatorRow = $"{d.VDLine}{new String (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
-			var buttonRow = $"{d.VDLine}{btnBack}{new String (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
-			var bottomRow = $"{d.LLDCorner}{new String (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
+			var separatorRow = $"{d.VDLine}{new string (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
+			var buttonRow = $"{d.VDLine}{btnBack}{new string (' ', width - btnBack.Length - btnNext.Length - 2)}{btnNext}{d.VDLine}";
+			var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
 
 
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			wizard.AddStep (new Wizard.WizardStep (stepTitle));
 			wizard.AddStep (new Wizard.WizardStep (stepTitle));
@@ -207,7 +207,7 @@ namespace Terminal.Gui.Views {
 		// this test is needed because Wizard overrides Dialog's title behavior ("Title - StepTitle")
 		// this test is needed because Wizard overrides Dialog's title behavior ("Title - StepTitle")
 		public void Setting_Title_Works ()
 		public void Setting_Title_Works ()
 		{
 		{
-			var d = ((FakeDriver)Application.Driver);
+			var d = (FakeDriver)Application.Driver;
 
 
 			var title = "1234";
 			var title = "1234";
 			var stepTitle = " - ABCD";
 			var stepTitle = " - ABCD";
@@ -219,13 +219,13 @@ namespace Terminal.Gui.Views {
 			var btnNextText = "Finish";
 			var btnNextText = "Finish";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 			var btnNext = $"{d.LeftBracket}{d.LeftDefaultIndicator} {btnNextText} {d.RightDefaultIndicator}{d.RightBracket}";
 
 
-			var topRow = $"{d.ULDCorner} {title}{stepTitle} {new String (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
-			var separatorRow = $"{d.VDLine}{new String (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
+			var topRow = $"{d.ULDCorner} {title}{stepTitle} {new string (d.HDLine.ToString () [0], width - title.Length - stepTitle.Length - 4)}{d.URDCorner}";
+			var separatorRow = $"{d.VDLine}{new string (d.HLine.ToString () [0], width - 2)}{d.VDLine}";
 
 
 			// Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791
 			// Once this is fixed, revert to commented out line: https://github.com/gui-cs/Terminal.Gui/issues/1791
-			var buttonRow = $"{d.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
+			var buttonRow = $"{d.VDLine}{new string (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
 			//var buttonRow = $"{d.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
 			//var buttonRow = $"{d.VDLine}{new String (' ', width - btnNext.Length - 2)}{btnNext}{d.VDLine}";
-			var bottomRow = $"{d.LLDCorner}{new String (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
+			var bottomRow = $"{d.LLDCorner}{new string (d.HDLine.ToString () [0], width - 2)}{d.LRDCorner}";
 
 
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			var wizard = new Wizard (title) { Width = width, Height = height };
 			wizard.AddStep (new Wizard.WizardStep ("ABCD"));
 			wizard.AddStep (new Wizard.WizardStep ("ABCD"));
@@ -560,13 +560,13 @@ namespace Terminal.Gui.Views {
 			runstate = Application.Begin (wizard);
 			runstate = Application.Begin (wizard);
 			Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
 			Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
 
 
-			Assert.Equal (step1.Title.ToString(), wizard.CurrentStep.Title.ToString());
+			Assert.Equal (step1.Title.ToString (), wizard.CurrentStep.Title.ToString ());
 			wizard.NextFinishButton.OnClicked ();
 			wizard.NextFinishButton.OnClicked ();
 			Assert.False (finishedFired);
 			Assert.False (finishedFired);
 			Assert.False (closedFired);
 			Assert.False (closedFired);
 
 
 			Assert.Equal (step2.Title.ToString (), wizard.CurrentStep.Title.ToString ());
 			Assert.Equal (step2.Title.ToString (), wizard.CurrentStep.Title.ToString ());
-			Assert.Equal (wizard.GetLastStep().Title.ToString(), wizard.CurrentStep.Title.ToString ());
+			Assert.Equal (wizard.GetLastStep ().Title.ToString (), wizard.CurrentStep.Title.ToString ());
 			wizard.NextFinishButton.OnClicked ();
 			wizard.NextFinishButton.OnClicked ();
 			Application.End (runstate);
 			Application.End (runstate);
 			Assert.True (finishedFired);
 			Assert.True (finishedFired);

+ 4 - 9
UnitTests/DimTests.cs → UnitTests/Types/DimTests.cs

@@ -6,14 +6,13 @@ using System.IO;
 using System.Linq;
 using System.Linq;
 using System.Threading;
 using System.Threading;
 using Terminal.Gui;
 using Terminal.Gui;
-using Terminal.Gui.Views;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TypeTests {
 	public class DimTests {
 	public class DimTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -22,7 +21,7 @@ namespace Terminal.Gui.Core {
 			this.output = output;
 			this.output = output;
 			Console.OutputEncoding = System.Text.Encoding.Default;
 			Console.OutputEncoding = System.Text.Encoding.Default;
 			// Change current culture
 			// Change current culture
-			CultureInfo culture = CultureInfo.CreateSpecificCulture ("en-US");
+			var culture = CultureInfo.CreateSpecificCulture ("en-US");
 			Thread.CurrentThread.CurrentCulture = culture;
 			Thread.CurrentThread.CurrentCulture = culture;
 			Thread.CurrentThread.CurrentUICulture = culture;
 			Thread.CurrentThread.CurrentUICulture = culture;
 		}
 		}
@@ -646,9 +645,7 @@ namespace Terminal.Gui.Core {
 			};
 			};
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
-				while (count < 20) {
-					field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
-				}
+				while (count < 20) 					field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
 
 
 				Application.RequestStop ();
 				Application.RequestStop ();
 			};
 			};
@@ -1091,9 +1088,7 @@ namespace Terminal.Gui.Core {
 			};
 			};
 
 
 			Application.Iteration += () => {
 			Application.Iteration += () => {
-				while (count > 0) {
-					field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
-				}
+				while (count > 0) 					field.OnKeyDown (new KeyEvent (Key.Enter, new KeyModifiers ()));
 
 
 				Application.RequestStop ();
 				Application.RequestStop ();
 			};
 			};

+ 1 - 1
UnitTests/PointTests.cs → UnitTests/Types/PointTests.cs

@@ -1,7 +1,7 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Types {
+namespace Terminal.Gui.TypeTests {
 	public class PointTests {
 	public class PointTests {
 		[Fact]
 		[Fact]
 		public void Point_New ()
 		public void Point_New ()

+ 1 - 2
UnitTests/PosTests.cs → UnitTests/Types/PosTests.cs

@@ -5,14 +5,13 @@ using System.Data;
 using System.IO;
 using System.IO;
 using System.Linq;
 using System.Linq;
 using Terminal.Gui;
 using Terminal.Gui;
-using Terminal.Gui.Views;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.TypeTests {
 	public class PosTests {
 	public class PosTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/RectTests.cs → UnitTests/Types/RectTests.cs

@@ -1,7 +1,7 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Types {
+namespace Terminal.Gui.TypeTests {
 	public class RectTests {
 	public class RectTests {
 		[Fact]
 		[Fact]
 		public void Rect_New ()
 		public void Rect_New ()

+ 1 - 1
UnitTests/SizeTests.cs → UnitTests/Types/SizeTests.cs

@@ -1,7 +1,7 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Types {
+namespace Terminal.Gui.TypeTests {
 	public class SizeTests {
 	public class SizeTests {
 		[Fact]
 		[Fact]
 		public void Size_New ()
 		public void Size_New ()

+ 1 - 1
UnitTests/ScenarioTests.cs → UnitTests/UICatalog/ScenarioTests.cs

@@ -11,7 +11,7 @@ using Xunit.Abstractions;
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace UICatalog {
+namespace UICatalog.Tests {
 	public class ScenarioTests {
 	public class ScenarioTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/AllViewsTests.cs → UnitTests/Views/AllViewsTests.cs

@@ -5,7 +5,7 @@ using System.Reflection;
 using Xunit;
 using Xunit;
 using System.IO;
 using System.IO;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class AllViewsTests {
 	public class AllViewsTests {
 		[Fact]
 		[Fact]
 		public void AllViews_Tests_All_Constructors ()
 		public void AllViews_Tests_All_Constructors ()

+ 1 - 1
UnitTests/AutocompleteTests.cs → UnitTests/Views/AutocompleteTests.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 using Terminal.Gui;
 using Terminal.Gui;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ViewTests {
 	public class AutocompleteTests {
 	public class AutocompleteTests {
 
 
 		[Fact]
 		[Fact]

+ 1 - 1
UnitTests/ButtonTests.cs → UnitTests/Views/ButtonTests.cs

@@ -2,7 +2,7 @@
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ButtonTests {
 	public class ButtonTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/CheckboxTests.cs → UnitTests/Views/CheckboxTests.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class CheckboxTests {
 	public class CheckboxTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/ColorPickerTests.cs → UnitTests/Views/ColorPickerTests.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ColorPickerTests {
 	public class ColorPickerTests {
 		[Fact]
 		[Fact]
 		public void Constructors ()
 		public void Constructors ()

+ 1 - 1
UnitTests/ComboBoxTests.cs → UnitTests/Views/ComboBoxTests.cs

@@ -4,7 +4,7 @@ using System.Linq;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ComboBoxTests {
 	public class ComboBoxTests {
 		ITestOutputHelper output;
 		ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/DateFieldTests.cs → UnitTests/Views/DateFieldTests.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class DateFieldTests {
 	public class DateFieldTests {
 		[Fact]
 		[Fact]
 		public void Constructors_Defaults ()
 		public void Constructors_Defaults ()

+ 1 - 1
UnitTests/FrameViewTests.cs → UnitTests/Views/FrameViewTests.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class FrameViewTests {
 	public class FrameViewTests {
 		[Fact]
 		[Fact]
 		public void Constuctors_Defaults ()
 		public void Constuctors_Defaults ()

+ 1 - 1
UnitTests/GraphViewTests.cs → UnitTests/Views/GraphViewTests.cs

@@ -11,7 +11,7 @@ using System.Text.RegularExpressions;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using Rune = System.Rune;
 using Rune = System.Rune;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 
 
 	#region Helper Classes
 	#region Helper Classes
 	class FakeHAxis : HorizontalAxis {
 	class FakeHAxis : HorizontalAxis {

+ 1 - 1
UnitTests/HexViewTests.cs → UnitTests/Views/HexViewTests.cs

@@ -6,7 +6,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class HexViewTests {
 	public class HexViewTests {
 		[Fact]
 		[Fact]
 		public void Constructors_Defaults ()
 		public void Constructors_Defaults ()

+ 1 - 1
UnitTests/LineViewTests.cs → UnitTests/Views/LineViewTests.cs

@@ -1,7 +1,7 @@
 using Terminal.Gui.Graphs;
 using Terminal.Gui.Graphs;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class LineViewTests {
 	public class LineViewTests {
 
 
 		[Fact]
 		[Fact]

+ 64 - 2
UnitTests/ListViewTests.cs → UnitTests/Views/ListViewTests.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ListViewTests {
 	public class ListViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -203,7 +203,7 @@ namespace Terminal.Gui.Views {
 
 
 		[Fact]
 		[Fact]
 		[AutoInitShutdown]
 		[AutoInitShutdown]
-		public void EnsuresVisibilitySelectedItem_Top ()
+		public void EnsureSelectedItemVisible_Top ()
 		{
 		{
 			var source = new List<string> () { "First", "Second" };
 			var source = new List<string> () { "First", "Second" };
 			ListView lv = new ListView (source) { Width = Dim.Fill (), Height = 1 };
 			ListView lv = new ListView (source) { Width = Dim.Fill (), Height = 1 };
@@ -451,5 +451,67 @@ namespace Terminal.Gui.Views {
 			lv.SetSourceAsync (null);
 			lv.SetSourceAsync (null);
 			Assert.NotNull (lv.Source);
 			Assert.NotNull (lv.Source);
 		}
 		}
+
+		[Fact]
+		public void ListWrapper_StartsWith ()
+		{
+			var lw = new ListWrapper (new List<string> { "One", "Two", "Three" });
+
+			Assert.Equal (1, lw.StartsWith ("t"));
+			Assert.Equal (1, lw.StartsWith ("tw"));
+			Assert.Equal (2, lw.StartsWith ("th"));
+			Assert.Equal (1, lw.StartsWith ("T"));
+			Assert.Equal (1, lw.StartsWith ("TW"));
+			Assert.Equal (2, lw.StartsWith ("TH"));
+
+			lw = new ListWrapper (new List<NStack.ustring> { "One", "Two", "Three" });
+
+			Assert.Equal (1, lw.StartsWith ("t"));
+			Assert.Equal (1, lw.StartsWith ("tw"));
+			Assert.Equal (2, lw.StartsWith ("th"));
+			Assert.Equal (1, lw.StartsWith ("T"));
+			Assert.Equal (1, lw.StartsWith ("TW"));
+			Assert.Equal (2, lw.StartsWith ("TH"));
+		}
+
+		[Fact, AutoInitShutdown]
+		public void EnsureSelectedItemVisible_SelectedItem ()
+		{
+			var source = new List<string> ();
+			for (int i = 0; i < 10; i++) {
+				source.Add ($"Item {i}");
+			}
+			var lv = new ListView (source) {
+				Width = 10,
+				Height = 5
+			};
+			Application.Top.Add (lv);
+			Application.Begin (Application.Top);
+
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+Item 0
+Item 1
+Item 2
+Item 3
+Item 4", output);
+
+			lv.SelectedItem = 6;
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+Item 0
+Item 1
+Item 2
+Item 3
+Item 4", output);
+
+			lv.EnsureSelectedItemVisible ();
+			Application.Refresh ();
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+Item 2
+Item 3
+Item 4
+Item 5
+Item 6", output);
+		}
 	}
 	}
 }
 }

+ 1 - 1
UnitTests/PanelViewTests.cs → UnitTests/Views/PanelViewTests.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class PanelViewTests {
 	public class PanelViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/ProgressBarTests.cs → UnitTests/Views/ProgressBarTests.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ProgressBarTests {
 	public class ProgressBarTests {
 		[Fact]
 		[Fact]
 		[AutoInitShutdown]
 		[AutoInitShutdown]

+ 1 - 1
UnitTests/RadioGroupTests.cs → UnitTests/Views/RadioGroupTests.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class RadioGroupTests {
 	public class RadioGroupTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/ScrollBarViewTests.cs → UnitTests/Views/ScrollBarViewTests.cs

@@ -5,7 +5,7 @@ using System.Reflection;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ScrollBarViewTests {
 	public class ScrollBarViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/ScrollViewTests.cs → UnitTests/Views/ScrollViewTests.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class ScrollViewTests {
 	public class ScrollViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/StatusBarTests.cs → UnitTests/Views/StatusBarTests.cs

@@ -2,7 +2,7 @@
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class StatusBarTests {
 	public class StatusBarTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 

+ 1 - 1
UnitTests/TabViewTests.cs → UnitTests/Views/TabViewTests.cs

@@ -8,7 +8,7 @@ using Xunit;
 using System.Globalization;
 using System.Globalization;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 
 
 	public class TabViewTests {
 	public class TabViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;

+ 1 - 1
UnitTests/TableViewTests.cs → UnitTests/Views/TableViewTests.cs

@@ -9,7 +9,7 @@ using System.Globalization;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 using System.Reflection;
 using System.Reflection;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 
 
 	public class TableViewTests {
 	public class TableViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;

+ 1 - 1
UnitTests/TextFieldTests.cs → UnitTests/Views/TextFieldTests.cs

@@ -2,7 +2,7 @@
 using System.Reflection;
 using System.Reflection;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class TextFieldTests {
 	public class TextFieldTests {
 
 
 		// This class enables test functions annotated with the [InitShutdown] attribute
 		// This class enables test functions annotated with the [InitShutdown] attribute

+ 1 - 1
UnitTests/TextValidateFieldTests.cs → UnitTests/Views/TextValidateFieldTests.cs

@@ -5,7 +5,7 @@ using Terminal.Gui.TextValidateProviders;
 
 
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 
 
 	public class TextValidateField_NET_Provider_Tests {
 	public class TextValidateField_NET_Provider_Tests {
 
 

+ 1 - 1
UnitTests/TextViewTests.cs → UnitTests/Views/TextViewTests.cs

@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class TextViewTests {
 	public class TextViewTests {
 		private static TextView _textView;
 		private static TextView _textView;
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;

+ 1 - 1
UnitTests/TimeFieldTests.cs → UnitTests/Views/TimeFieldTests.cs

@@ -5,7 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using Xunit;
 using Xunit;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 	public class TimeFieldTests {
 	public class TimeFieldTests {
 		[Fact]
 		[Fact]
 		public void Constructors_Defaults ()
 		public void Constructors_Defaults ()

+ 1 - 1
UnitTests/TreeViewTests.cs → UnitTests/Views/TreeViewTests.cs

@@ -8,7 +8,7 @@ using Terminal.Gui.Trees;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
 
 
-namespace Terminal.Gui.Views {
+namespace Terminal.Gui.ViewTests {
 
 
 	public class TreeViewTests {
 	public class TreeViewTests {
 
 

+ 61 - 2
UnitTests/ViewTests.cs → UnitTests/Views/ViewTests.cs

@@ -1,12 +1,12 @@
 using System;
 using System;
 using Xunit;
 using Xunit;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
-using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
+//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
 
 
 // Alias Console to MockConsole so we don't accidentally use Console
 // Alias Console to MockConsole so we don't accidentally use Console
 using Console = Terminal.Gui.FakeConsole;
 using Console = Terminal.Gui.FakeConsole;
 
 
-namespace Terminal.Gui.Core {
+namespace Terminal.Gui.ViewTests {
 	public class ViewTests {
 	public class ViewTests {
 		readonly ITestOutputHelper output;
 		readonly ITestOutputHelper output;
 
 
@@ -4117,5 +4117,64 @@ This is a tes
 			view.Enabled = false;
 			view.Enabled = false;
 			Assert.Equal (view.ColorScheme.Disabled, view.GetHotNormalColor ());
 			Assert.Equal (view.ColorScheme.Disabled, view.GetHotNormalColor ());
 		}
 		}
+
+		[Theory, AutoInitShutdown]
+		[InlineData (true)]
+		[InlineData (false)]
+		public void Clear_Does_Not_Spillover_Its_Parent (bool label)
+		{
+			var root = new View () { Width = 20, Height = 10 };
+
+			var v = label == true ?
+				new Label (new string ('c', 100)) {
+					Width = Dim.Fill ()
+				} :
+				(View)new TextView () {
+					Height = 1,
+					Text = new string ('c', 100),
+					Width = Dim.Fill ()
+				};
+
+			root.Add (v);
+
+			Application.Top.Add (root);
+			Application.Begin (Application.Top);
+
+			if (label) {
+				Assert.True (v.AutoSize);
+				Assert.False (v.CanFocus);
+				Assert.Equal (new Rect (0, 0, 100, 1), v.Frame);
+			} else {
+				Assert.False (v.AutoSize);
+				Assert.True (v.CanFocus);
+				Assert.Equal (new Rect (0, 0, 20, 1), v.Frame);
+			}
+
+			TestHelpers.AssertDriverContentsWithFrameAre (@"
+cccccccccccccccccccc", output);
+
+			var attributes = new Attribute [] {
+				Colors.TopLevel.Normal,
+				Colors.TopLevel.Focus,
+
+			};
+			if (label) {
+				TestHelpers.AssertDriverColorsAre (@"
+000000000000000000000", attributes);
+			} else {
+				TestHelpers.AssertDriverColorsAre (@"
+111111111111111111110", attributes);
+			}
+
+			if (label) {
+				root.CanFocus = true;
+				v.CanFocus = true;
+				Assert.False (v.HasFocus);
+				v.SetFocus ();
+				Application.Refresh ();
+				TestHelpers.AssertDriverColorsAre (@"
+111111111111111111110", attributes);
+			}
+		}
 	}
 	}
 }
 }