Преглед изворни кода

fixed all views to deal with Driver is null

Tig пре 9 месеци
родитељ
комит
98a2265db2

+ 2 - 2
Terminal.Gui/View/Adornment/ShadowView.cs

@@ -139,9 +139,9 @@ internal class ShadowView : View
         // Fill the rest of the rectangle
         for (int i = Math.Max (0, screen.Y); i < screen.Y + viewport.Height; i++)
         {
-            Driver.Move (screen.X, i);
+            Driver?.Move (screen.X, i);
 
-            if (Driver.Contents is { } && screen.X < Driver.Contents.GetLength (1) && i < Driver.Contents.GetLength (0))
+            if (Driver?.Contents is { } && screen.X < Driver.Contents.GetLength (1) && i < Driver.Contents.GetLength (0))
             {
                 Driver.AddRune (Driver.Contents [i, screen.X].Rune);
             }

+ 9 - 9
Terminal.Gui/Views/ComboBox.cs

@@ -303,9 +303,9 @@ public class ComboBox : View, IDesignable
             return;
         }
 
-        Driver.SetAttribute (ColorScheme.Focus);
+        Driver?.SetAttribute (ColorScheme.Focus);
         Move (Viewport.Right - 1, 0);
-        Driver.AddRune (Glyphs.DownArrow);
+        Driver?.AddRune (Glyphs.DownArrow);
     }
 
 
@@ -887,8 +887,8 @@ public class ComboBox : View, IDesignable
 
         public override void OnDrawContent (Rectangle viewport)
         {
-            Attribute current = ColorScheme.Focus;
-            Driver.SetAttribute (current);
+            Attribute current = ColorScheme?.Focus ?? Attribute.Default;
+            Driver?.SetAttribute (current);
             Move (0, 0);
             Rectangle f = Frame;
             int item = TopItem;
@@ -918,7 +918,7 @@ public class ComboBox : View, IDesignable
 
                 if (newcolor != current)
                 {
-                    Driver.SetAttribute (newcolor);
+                    Driver?.SetAttribute (newcolor);
                     current = newcolor;
                 }
 
@@ -928,7 +928,7 @@ public class ComboBox : View, IDesignable
                 {
                     for (var c = 0; c < f.Width; c++)
                     {
-                        Driver.AddRune ((Rune)' ');
+                        Driver?.AddRune ((Rune)' ');
                     }
                 }
                 else
@@ -939,16 +939,16 @@ public class ComboBox : View, IDesignable
                     if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                     {
                         current = (Attribute)rowEventArgs.RowAttribute;
-                        Driver.SetAttribute (current);
+                        Driver?.SetAttribute (current);
                     }
 
                     if (AllowsMarking)
                     {
-                        Driver.AddRune (
+                        Driver?.AddRune (
                                         Source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
                                         AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
                                        );
-                        Driver.AddRune ((Rune)' ');
+                        Driver?.AddRune ((Rune)' ');
                     }
 
                     Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);

+ 1 - 1
Terminal.Gui/Views/GraphView/GraphView.cs

@@ -344,5 +344,5 @@ public class GraphView : View
     ///     Sets the color attribute of <see cref="Application.Driver"/> to the <see cref="GraphColor"/> (if defined) or
     ///     <see cref="ColorScheme"/> otherwise.
     /// </summary>
-    public void SetDriverColorToGraphColor () { Driver.SetAttribute (GraphColor ?? GetNormalColor ()); }
+    public void SetDriverColorToGraphColor () { Driver?.SetAttribute (GraphColor ?? GetNormalColor ()); }
 }

+ 10 - 10
Terminal.Gui/Views/HexView.cs

@@ -430,7 +430,7 @@ public class HexView : View, IDesignable
 
         Attribute currentAttribute;
         Attribute current = GetFocusColor ();
-        Driver.SetAttribute (current);
+        Driver?.SetAttribute (current);
         Move (0, 0);
 
         int nBlocks = BytesPerLine / NUM_BYTES_PER_HEX_COLUMN;
@@ -452,13 +452,13 @@ public class HexView : View, IDesignable
 
             Move (0, line);
             currentAttribute = new Attribute (GetNormalColor ().Foreground.GetHighlightColor (), GetNormalColor ().Background);
-            Driver.SetAttribute (currentAttribute);
+            Driver?.SetAttribute (currentAttribute);
             var address = $"{_displayStart + line * nBlocks * NUM_BYTES_PER_HEX_COLUMN:x8}";
-            Driver.AddStr ($"{address.Substring (8 - AddressWidth)}");
+            Driver?.AddStr ($"{address.Substring (8 - AddressWidth)}");
 
             if (AddressWidth > 0)
             {
-                Driver.AddStr (" ");
+                Driver?.AddStr (" ");
             }
 
             SetAttribute (GetNormalColor ());
@@ -480,12 +480,12 @@ public class HexView : View, IDesignable
                         SetAttribute (edited ? editedAttribute : GetNormalColor ());
                     }
 
-                    Driver.AddStr (offset >= n && !edited ? "  " : $"{value:x2}");
+                    Driver?.AddStr (offset >= n && !edited ? "  " : $"{value:x2}");
                     SetAttribute (GetNormalColor ());
-                    Driver.AddRune (_spaceCharRune);
+                    Driver?.AddRune (_spaceCharRune);
                 }
 
-                Driver.AddStr (block + 1 == nBlocks ? " " : $"{_columnSeparatorRune} ");
+                Driver?.AddStr (block + 1 == nBlocks ? " " : $"{_columnSeparatorRune} ");
             }
 
             for (var byteIndex = 0; byteIndex < nBlocks * NUM_BYTES_PER_HEX_COLUMN; byteIndex++)
@@ -538,12 +538,12 @@ public class HexView : View, IDesignable
                     SetAttribute (edited ? editedAttribute : GetNormalColor ());
                 }
 
-                Driver.AddRune (c);
+                Driver?.AddRune (c);
 
                 for (var i = 1; i < utf8BytesConsumed; i++)
                 {
                     byteIndex++;
-                    Driver.AddRune (_periodCharRune);
+                    Driver?.AddRune (_periodCharRune);
                 }
             }
         }
@@ -553,7 +553,7 @@ public class HexView : View, IDesignable
             if (currentAttribute != attribute)
             {
                 currentAttribute = attribute;
-                Driver.SetAttribute (attribute);
+                Driver?.SetAttribute (attribute);
             }
         }
     }

+ 5 - 5
Terminal.Gui/Views/Line.cs

@@ -70,29 +70,29 @@ public class Line : View, IOrientation
 
         if (SuperViewRendersLineCanvas)
         {
-            lc = SuperView.LineCanvas;
+            lc = SuperView?.LineCanvas;
         }
 
         if (SuperView is Adornment adornment)
         {
-            lc = adornment.Parent.LineCanvas;
+            lc = adornment.Parent?.LineCanvas;
         }
 
         Point pos = ViewportToScreen (viewport).Location;
         int length = Orientation == Orientation.Horizontal ? Frame.Width : Frame.Height;
 
-        if (SuperViewRendersLineCanvas && Orientation == Orientation.Horizontal)
+        if (SuperView is {} && SuperViewRendersLineCanvas && Orientation == Orientation.Horizontal)
         {
             pos.Offset (-SuperView.Border.Thickness.Left, 0);
             length += SuperView.Border.Thickness.Horizontal;
         }
 
-        if (SuperViewRendersLineCanvas && Orientation == Orientation.Vertical)
+        if (SuperView is { } && SuperViewRendersLineCanvas && Orientation == Orientation.Vertical)
         {
             pos.Offset (0, -SuperView.Border.Thickness.Top);
             length += SuperView.Border.Thickness.Vertical;
         }
-        lc.AddLine (
+        lc?.AddLine (
                     pos,
                     length,
                     Orientation,

+ 2 - 2
Terminal.Gui/Views/LineView.cs

@@ -59,7 +59,7 @@ public class LineView : View
         base.OnDrawContent (viewport);
 
         Move (0, 0);
-        Driver.SetAttribute (GetNormalColor ());
+        Driver?.SetAttribute (GetNormalColor ());
 
         int hLineWidth = Math.Max (1, Glyphs.HLine.GetColumns ());
 
@@ -87,7 +87,7 @@ public class LineView : View
                 rune = EndingAnchor ?? LineRune;
             }
 
-            Driver.AddRune (rune);
+            Driver?.AddRune (rune);
         }
     }
 }

+ 7 - 7
Terminal.Gui/Views/ListView.cs

@@ -752,8 +752,8 @@ public class ListView : View, IDesignable
     {
         base.OnDrawContent (viewport);
 
-        Attribute current = ColorScheme.Focus;
-        Driver.SetAttribute (current);
+        Attribute current = ColorScheme?.Focus ?? Attribute.Default;
+        Driver?.SetAttribute (current);
         Move (0, 0);
         Rectangle f = Viewport;
         int item = Viewport.Y;
@@ -770,7 +770,7 @@ public class ListView : View, IDesignable
 
             if (newcolor != current)
             {
-                Driver.SetAttribute (newcolor);
+                Driver?.SetAttribute (newcolor);
                 current = newcolor;
             }
 
@@ -780,7 +780,7 @@ public class ListView : View, IDesignable
             {
                 for (var c = 0; c < f.Width; c++)
                 {
-                    Driver.AddRune ((Rune)' ');
+                    Driver?.AddRune ((Rune)' ');
                 }
             }
             else
@@ -791,16 +791,16 @@ public class ListView : View, IDesignable
                 if (rowEventArgs.RowAttribute is { } && current != rowEventArgs.RowAttribute)
                 {
                     current = (Attribute)rowEventArgs.RowAttribute;
-                    Driver.SetAttribute (current);
+                    Driver?.SetAttribute (current);
                 }
 
                 if (_allowsMarking)
                 {
-                    Driver.AddRune (
+                    Driver?.AddRune (
                                     _source.IsMarked (item) ? AllowsMultipleSelection ? Glyphs.CheckStateChecked : Glyphs.Selected :
                                     AllowsMultipleSelection ? Glyphs.CheckStateUnChecked : Glyphs.UnSelected
                                    );
-                    Driver.AddRune ((Rune)' ');
+                    Driver?.AddRune ((Rune)' ');
                 }
 
                 Source.Render (this, Driver, isSelected, item, col, row, f.Width - col, start);

+ 1 - 1
Terminal.Gui/Views/Menu/MenuBar.cs

@@ -299,7 +299,7 @@ public class MenuBar : View, IDesignable
     /// <inheritdoc/>
     public override void OnDrawContent (Rectangle viewport)
     {
-        Driver.SetAttribute (GetNormalColor ());
+        Driver?.SetAttribute (GetNormalColor ());
 
         Clear ();
 

+ 6 - 6
Terminal.Gui/Views/ProgressBar.cs

@@ -141,7 +141,7 @@ public class ProgressBar : View, IDesignable
     ///<inheritdoc/>
     public override void OnDrawContent (Rectangle viewport)
     {
-        Driver.SetAttribute (GetHotNormalColor ());
+        Driver?.SetAttribute (GetHotNormalColor ());
 
         Move (0, 0);
 
@@ -151,11 +151,11 @@ public class ProgressBar : View, IDesignable
             {
                 if (Array.IndexOf (_activityPos, i) != -1)
                 {
-                    Driver.AddRune (SegmentCharacter);
+                    Driver?.AddRune (SegmentCharacter);
                 }
                 else
                 {
-                    Driver.AddRune ((Rune)' ');
+                    Driver?.AddRune ((Rune)' ');
                 }
             }
         }
@@ -166,12 +166,12 @@ public class ProgressBar : View, IDesignable
 
             for (i = 0; (i < mid) & (i < Viewport.Width); i++)
             {
-                Driver.AddRune (SegmentCharacter);
+                Driver?.AddRune (SegmentCharacter);
             }
 
             for (; i < Viewport.Width; i++)
             {
-                Driver.AddRune ((Rune)' ');
+                Driver?.AddRune ((Rune)' ');
             }
         }
 
@@ -185,7 +185,7 @@ public class ProgressBar : View, IDesignable
                 attr = new Attribute (ColorScheme.HotNormal.Background, ColorScheme.HotNormal.Foreground);
             }
 
-            tf?.Draw (
+            tf.Draw (
                       ViewportToScreen (Viewport),
                       attr,
                       ColorScheme.Normal,

+ 4 - 4
Terminal.Gui/Views/RadioGroup.cs

@@ -364,7 +364,7 @@ public class RadioGroup : View, IDesignable, IOrientation
     {
         base.OnDrawContent (viewport);
 
-        Driver.SetAttribute (GetNormalColor ());
+        Driver?.SetAttribute (GetNormalColor ());
 
         for (var i = 0; i < _radioLabels.Count; i++)
         {
@@ -381,8 +381,8 @@ public class RadioGroup : View, IDesignable, IOrientation
             }
 
             string rl = _radioLabels [i];
-            Driver.SetAttribute (GetNormalColor ());
-            Driver.AddStr ($"{(i == _selected ? Glyphs.Selected : Glyphs.UnSelected)} ");
+            Driver?.SetAttribute (GetNormalColor ());
+            Driver?.AddStr ($"{(i == _selected ? Glyphs.Selected : Glyphs.UnSelected)} ");
             TextFormatter.FindHotKey (rl, HotKeySpecifier, out int hotPos, out Key hotKey);
 
             if (hotPos != -1 && hotKey != Key.Empty)
@@ -430,7 +430,7 @@ public class RadioGroup : View, IDesignable, IOrientation
                     }
 
                     Application.Driver?.AddRune (rune);
-                    Driver.SetAttribute (GetNormalColor ());
+                    Driver?.SetAttribute (GetNormalColor ());
                 }
             }
             else

+ 9 - 5
Terminal.Gui/Views/TabView.cs

@@ -292,7 +292,7 @@ public class TabView : View
     /// <inheritdoc/>
     public override void OnDrawContent (Rectangle viewport)
     {
-        Driver.SetAttribute (GetNormalColor ());
+        Driver?.SetAttribute (GetNormalColor ());
 
         if (Tabs.Any ())
         {
@@ -300,7 +300,11 @@ public class TabView : View
             _tabsBar.OnDrawContent (viewport);
             _contentView.SetNeedsDisplay ();
             _contentView.Draw ();
-            Driver.Clip = savedClip;
+
+            if (Driver is { })
+            {
+                Driver.Clip = savedClip;
+            }
         }
     }
 
@@ -648,7 +652,7 @@ public class TabView : View
             RenderTabLine ();
 
             RenderUnderline ();
-            Driver.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
+            Driver?.SetAttribute (HasFocus ? GetFocusColor () : GetNormalColor ());
         }
 
         public override void OnDrawContentComplete (Rectangle viewport)
@@ -1271,7 +1275,7 @@ public class TabView : View
 
                 tab.OnDrawAdornments ();
 
-                Attribute prevAttr = Driver.GetAttribute ();
+                Attribute prevAttr = Driver?.GetAttribute () ?? Attribute.Default;
 
                 // if tab is the selected one and focus is inside this control
                 if (toRender.IsSelected && _host.HasFocus)
@@ -1296,7 +1300,7 @@ public class TabView : View
 
                 tab.OnRenderLineCanvas ();
 
-                Driver.SetAttribute (GetNormalColor ());
+                Driver?.SetAttribute (GetNormalColor ());
             }
         }
 

+ 27 - 17
Terminal.Gui/Views/TableView/TableView.cs

@@ -1320,10 +1320,10 @@ public class TableView : View
     /// <returns></returns>
     internal int GetHeaderHeightIfAny () { return ShouldRenderHeaders () ? GetHeaderHeight () : 0; }
 
-    private void AddRuneAt (ConsoleDriver d, int col, int row, Rune ch)
+    private void AddRuneAt (ConsoleDriver? d, int col, int row, Rune ch)
     {
         Move (col, row);
-        d.AddRune (ch);
+        d?.AddRune (ch);
     }
 
     /// <summary>
@@ -1505,6 +1505,10 @@ public class TableView : View
     /// <param name="width"></param>
     private void ClearLine (int row, int width)
     {
+        if (Driver is null)
+        {
+            return;
+        }
         Move (0, row);
         Driver.SetAttribute (GetNormalColor ());
         Driver.AddStr (new string (' ', width));
@@ -1728,7 +1732,7 @@ public class TableView : View
 
             Move (current.X, row);
 
-            Driver.AddStr (TruncateOrPad (colName, colName, current.Width, colStyle));
+            Driver?.AddStr (TruncateOrPad (colName, colName, current.Width, colStyle));
 
             if (Style.ExpandLastColumn == false && current.IsVeryLast)
             {
@@ -1776,7 +1780,10 @@ public class TableView : View
                 }
             }
 
-            AddRuneAt (Driver, c, row, rune);
+            if (Driver is { })
+            {
+                AddRuneAt (Driver, c, row, rune);
+            }
         }
     }
 
@@ -1885,19 +1892,19 @@ public class TableView : View
         //start by clearing the entire line
         Move (0, row);
 
-        Attribute color;
+        Attribute? color;
 
         if (FullRowSelect && IsSelected (0, rowToRender))
         {
-            color = focused ? rowScheme.Focus : rowScheme.HotNormal;
+            color = focused ? rowScheme?.Focus : rowScheme?.HotNormal;
         }
         else
         {
-            color = Enabled ? rowScheme.Normal : rowScheme.Disabled;
+            color = Enabled ? rowScheme?.Normal : rowScheme?.Disabled;
         }
 
-        Driver.SetAttribute (color);
-        Driver.AddStr (new string (' ', Viewport.Width));
+        Driver?.SetAttribute (color.Value);
+        Driver?.AddStr (new string (' ', Viewport.Width));
 
         // Render cells for each visible header for the current row
         for (var i = 0; i < columnsToRender.Length; i++)
@@ -1948,15 +1955,15 @@ public class TableView : View
                 scheme = rowScheme;
             }
 
-            Attribute cellColor;
+            Attribute? cellColor;
 
             if (isSelectedCell)
             {
-                cellColor = focused ? scheme.Focus : scheme.HotNormal;
+                cellColor = focused ? scheme?.Focus : scheme?.HotNormal;
             }
             else
             {
-                cellColor = Enabled ? scheme.Normal : scheme.Disabled;
+                cellColor = Enabled ? scheme?.Normal : scheme?.Disabled;
             }
 
             string render = TruncateOrPad (val, representation, current.Width, colStyle);
@@ -1964,7 +1971,10 @@ public class TableView : View
             // While many cells can be selected (see MultiSelectedRegions) only one cell is the primary (drives navigation etc)
             bool isPrimaryCell = current.Column == selectedColumn && rowToRender == selectedRow;
 
-            RenderCell (cellColor, render, isPrimaryCell);
+            if (cellColor.HasValue)
+            {
+                RenderCell (cellColor.Value, render, isPrimaryCell);
+            }
 
             // Reset color scheme to normal for drawing separators if we drew text with custom scheme
             if (scheme != rowScheme)
@@ -1978,18 +1988,18 @@ public class TableView : View
                     color = Enabled ? rowScheme.Normal : rowScheme.Disabled;
                 }
 
-                Driver.SetAttribute (color);
+                Driver?.SetAttribute (color.Value);
             }
 
             // If not in full row select mode always, reset color scheme to normal and render the vertical line (or space) at the end of the cell
             if (!FullRowSelect)
             {
-                Driver.SetAttribute (Enabled ? rowScheme.Normal : rowScheme.Disabled);
+                Driver?.SetAttribute (Enabled ? rowScheme.Normal : rowScheme.Disabled);
             }
 
             if (style.AlwaysUseNormalColorForVerticalCellLines && style.ShowVerticalCellLines)
             {
-                Driver.SetAttribute (rowScheme.Normal);
+                Driver?.SetAttribute (rowScheme.Normal);
             }
 
             RenderSeparator (current.X - 1, row, false);
@@ -2002,7 +2012,7 @@ public class TableView : View
 
         if (style.ShowVerticalCellLines)
         {
-            Driver.SetAttribute (rowScheme.Normal);
+            Driver?.SetAttribute (rowScheme.Normal);
 
             //render start and end of line
             AddRune (0, row, Glyphs.VLine);

+ 7 - 7
Terminal.Gui/Views/TextValidateField.cs

@@ -558,7 +558,7 @@ namespace Terminal.Gui
             if (_provider is null)
             {
                 Move (0, 0);
-                Driver.AddStr ("Error: ITextValidateProvider not set!");
+                Driver?.AddStr ("Error: ITextValidateProvider not set!");
 
                 return;
             }
@@ -571,28 +571,28 @@ namespace Terminal.Gui
             Move (0, 0);
 
             // Left Margin
-            Driver.SetAttribute (textColor);
+            Driver?.SetAttribute (textColor);
 
             for (var i = 0; i < margin_left; i++)
             {
-                Driver.AddRune ((Rune)' ');
+                Driver?.AddRune ((Rune)' ');
             }
 
             // Content
-            Driver.SetAttribute (textColor);
+            Driver?.SetAttribute (textColor);
 
             // Content
             for (var i = 0; i < _provider.DisplayText.Length; i++)
             {
-                Driver.AddRune ((Rune)_provider.DisplayText [i]);
+                Driver?.AddRune ((Rune)_provider.DisplayText [i]);
             }
 
             // Right Margin
-            Driver.SetAttribute (textColor);
+            Driver?.SetAttribute (textColor);
 
             for (var i = 0; i < margin_right; i++)
             {
-                Driver.AddRune ((Rune)' ');
+                Driver?.AddRune ((Rune)' ');
             }
         }
 

+ 11 - 11
Terminal.Gui/Views/TextView.cs

@@ -3960,7 +3960,7 @@ public class TextView : View
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Normal"/>.
+    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Normal"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -3974,18 +3974,18 @@ public class TextView : View
         if (line [idxCol].Attribute is { })
         {
             Attribute? attribute = line [idxCol].Attribute;
-            Driver.SetAttribute ((Attribute)attribute!);
+            Driver?.SetAttribute ((Attribute)attribute!);
         }
         else
         {
-            Driver.SetAttribute (GetNormalColor ());
+            Driver?.SetAttribute (GetNormalColor ());
         }
     }
 
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
+    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4009,13 +4009,13 @@ public class TextView : View
             attribute = new (cellAttribute.Value.Foreground, ColorScheme!.Focus.Background);
         }
 
-        Driver.SetAttribute (attribute);
+        Driver?.SetAttribute (attribute);
     }
 
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
+    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.Focus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4031,13 +4031,13 @@ public class TextView : View
         {
             Attribute? attribute = line [idxCol].Attribute;
 
-            Driver.SetAttribute (
+            Driver?.SetAttribute (
                                  new (attribute!.Value.Background, attribute.Value.Foreground)
                                 );
         }
         else
         {
-            Driver.SetAttribute (
+            Driver?.SetAttribute (
                                  new (
                                       ColorScheme!.Focus.Background,
                                       ColorScheme!.Focus.Foreground
@@ -4049,7 +4049,7 @@ public class TextView : View
     /// <summary>
     ///     Sets the <see cref="View.Driver"/> to an appropriate color for rendering the given <paramref name="idxCol"/>
     ///     of the current <paramref name="line"/>. Override to provide custom coloring by calling
-    ///     <see cref="ConsoleDriver.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.HotFocus"/>.
+    ///     <see cref="ConsoleDriver?.SetAttribute(Attribute)"/> Defaults to <see cref="ColorScheme.HotFocus"/>.
     /// </summary>
     /// <param name="line">The line.</param>
     /// <param name="idxCol">The col index.</param>
@@ -4076,7 +4076,7 @@ public class TextView : View
     ///     Sets the driver to the default color for the control where no text is being rendered. Defaults to
     ///     <see cref="ColorScheme.Normal"/>.
     /// </summary>
-    protected virtual void SetNormalColor () { Driver.SetAttribute (GetNormalColor ()); }
+    protected virtual void SetNormalColor () { Driver?.SetAttribute (GetNormalColor ()); }
 
     private void Adjust ()
     {
@@ -6363,7 +6363,7 @@ public class TextView : View
     {
         // BUGBUG: (v2 truecolor) This code depends on 8-bit color names; disabling for now
         //if ((colorScheme!.HotNormal.Foreground & colorScheme.Focus.Background) == colorScheme.Focus.Foreground) {
-        Driver.SetAttribute (new (attribute!.Value.Background, attribute!.Value.Foreground));
+        Driver?.SetAttribute (new (attribute!.Value.Background, attribute!.Value.Foreground));
     }
 
     /// <summary>Restore from original model.</summary>

+ 2 - 2
Terminal.Gui/Views/TileView.cs

@@ -177,7 +177,7 @@ public class TileView : View
     /// <inheritdoc/>
     public override void OnDrawContent (Rectangle viewport)
     {
-        Driver.SetAttribute (ColorScheme.Normal);
+        Driver?.SetAttribute (ColorScheme.Normal);
 
         Clear ();
 
@@ -236,7 +236,7 @@ public class TileView : View
             }
         }
 
-        Driver.SetAttribute (ColorScheme.Normal);
+        Driver?.SetAttribute (ColorScheme.Normal);
 
         foreach (KeyValuePair<Point, Rune> p in lc.GetMap (Viewport))
         {

+ 3 - 3
Terminal.Gui/Views/TreeView/TreeView.cs

@@ -1137,7 +1137,7 @@ public class TreeView<T> : View, ITreeView where T : class
         if (TreeBuilder is null)
         {
             Move (0, 0);
-            Driver.AddStr (NoBuilderError);
+            Driver?.AddStr (NoBuilderError);
 
             return;
         }
@@ -1158,8 +1158,8 @@ public class TreeView<T> : View, ITreeView where T : class
             {
                 // Else clear the line to prevent stale symbols due to scrolling etc
                 Move (0, line);
-                Driver.SetAttribute (GetNormalColor ());
-                Driver.AddStr (new string (' ', Viewport.Width));
+                Driver?.SetAttribute (GetNormalColor ());
+                Driver?.AddStr (new string (' ', Viewport.Width));
             }
         }
     }

+ 2 - 1
UnitTests/View/Draw/AllViewsDrawTests.cs

@@ -6,7 +6,7 @@ public class AllViewsDrawTests (ITestOutputHelper _output) : TestsAllViews
 {
     [Theory]
     [MemberData (nameof (AllViewTypes))]
-    public void AllViews_Does_Not_Layout (Type viewType)
+    public void AllViews_Draw_Does_Not_Layout (Type viewType)
     {
         var view = (View)CreateInstanceIfNotGeneric (viewType);
 
@@ -38,6 +38,7 @@ public class AllViewsDrawTests (ITestOutputHelper _output) : TestsAllViews
         Assert.Equal (1, layoutStartedCount);
         Assert.Equal (1, layoutCompleteCount);
 
+        view.SetNeedsDisplay ();
         view.Draw ();
 
         Assert.Equal (1, drawContentCount);

+ 1 - 0
UnitTests/View/Layout/LayoutTests.cs

@@ -32,6 +32,7 @@ public class LayoutTests (ITestOutputHelper _output) : TestsAllViews
         view.LayoutComplete += (s, e) => layoutCompleteCount++;
 
         view.SetLayoutNeeded ();
+        view.SetNeedsDisplay();
         view.Layout ();
 
         Assert.Equal (0, drawContentCount);