diff --git a/.gitignore b/.gitignore index 14e25a86c1..e73c01487b 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,11 @@ demo.* *.dotCover logs/ + +BenchmarkDotNet.Artifacts/ + +*.log + +*.log.* + + diff --git a/Terminal.Gui/Application/Application.Initialization.cs b/Terminal.Gui/Application/Application.Initialization.cs index a74f1545d1..d23f4f49c8 100644 --- a/Terminal.Gui/Application/Application.Initialization.cs +++ b/Terminal.Gui/Application/Application.Initialization.cs @@ -167,6 +167,8 @@ internal static void InternalInit ( InitializedChanged?.Invoke (null, new (init)); } + [RequiresUnreferencedCode ("AOT")] + [RequiresDynamicCode ("AOT")] internal static void InitializeConfigurationManagement () { // Start the process of configuration management. diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index a493f30569..016c36329d 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -63,7 +63,7 @@ public static string ToString (IConsoleDriver? driver) { Rune rune = contents [r, c].Rune; - if (rune.DecodeSurrogatePair (out char [] sp)) + if (rune.DecodeSurrogatePair (out char []? sp)) { sb.Append (sp); } diff --git a/Terminal.Gui/Configuration/ConfigurationManager.cs b/Terminal.Gui/Configuration/ConfigurationManager.cs index 676f68251e..b2b5f47664 100644 --- a/Terminal.Gui/Configuration/ConfigurationManager.cs +++ b/Terminal.Gui/Configuration/ConfigurationManager.cs @@ -326,14 +326,17 @@ public static void PrintJsonErrors () } + /// + /// Logs Json deserialization errors that occurred during deserialization. + /// public static void LogJsonErrors () { if (_jsonErrors.Length > 0) { - Logging.Warning ( + Logging.Error ( @"Encountered the following errors while deserializing configuration files:" ); - Logging.Warning (_jsonErrors.ToString ()); + Logging.Error (_jsonErrors.ToString ()); } } diff --git a/Terminal.Gui/Configuration/ScopeJsonConverter.cs b/Terminal.Gui/Configuration/ScopeJsonConverter.cs index 11e83c6f7f..d1d6e475e8 100644 --- a/Terminal.Gui/Configuration/ScopeJsonConverter.cs +++ b/Terminal.Gui/Configuration/ScopeJsonConverter.cs @@ -91,7 +91,7 @@ public override scopeT Read (ref Utf8JsonReader reader, Type typeToConvert, Json scope! [propertyName].PropertyValue = JsonSerializer.Deserialize (ref reader, propertyType!, SerializerContext); } - catch (Exception ex) + catch (Exception) { // Logging.Trace ($"scopeT Read: {ex}"); } diff --git a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs index 9c442e5e21..522f7ac4c9 100644 --- a/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs +++ b/Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs @@ -52,6 +52,11 @@ public CsiKeyPattern () _pattern = new (@$"^\u001b\[(1;(\d+))?([{terms}]|\d+~)$"); } + /// + /// Called by the base class to determine the key that matches the input. + /// + /// + /// protected override Key? GetKeyImpl (string input) { Match match = _pattern.Match (input); diff --git a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs index 08575a1ba3..d4bd54863a 100644 --- a/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs @@ -151,7 +151,7 @@ internal void IterationImpl () private void SetCursor () { - View? mostFocused = Application.Top.MostFocused; + View? mostFocused = Application.Top!.MostFocused; if (mostFocused == null) { diff --git a/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs b/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs index d08daca5f4..e507c97f66 100644 --- a/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs +++ b/Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs @@ -17,7 +17,7 @@ public class NetInputProcessor : InputProcessor /// /// public static bool GenerateTestCasesForKeyPresses = false; -#pragma warning enable CA2211 +#pragma warning restore CA2211 /// public NetInputProcessor (ConcurrentQueue inputBuffer) : base (inputBuffer, new NetKeyConverter ()) { } diff --git a/Terminal.Gui/Drawing/Region.cs b/Terminal.Gui/Drawing/Region.cs index a5b144f212..2e51319758 100644 --- a/Terminal.Gui/Drawing/Region.cs +++ b/Terminal.Gui/Drawing/Region.cs @@ -658,7 +658,7 @@ internal static List MergeVerticalIntervals (SortedSet<(int yTop, int } else { - result.Add (new (startX, currentTop.Value, endX - startX, currentBottom.Value - currentTop.Value)); + result.Add (new (startX, currentTop.Value, endX - startX, currentBottom!.Value - currentTop.Value)); currentTop = yTop; currentBottom = yBottom; } diff --git a/Terminal.Gui/Input/Keyboard/Key.cs b/Terminal.Gui/Input/Keyboard/Key.cs index 53d6292756..e0d4119aa3 100644 --- a/Terminal.Gui/Input/Keyboard/Key.cs +++ b/Terminal.Gui/Input/Keyboard/Key.cs @@ -418,7 +418,7 @@ public override bool Equals (object? obj) /// /// /// - public static bool operator != (Key a, Key? b) { return !a!.Equals (b); } + public static bool operator != (Key? a, Key? b) { return !a!.Equals (b); } /// Compares two s for less-than. /// diff --git a/Terminal.Gui/View/DrawContext.cs b/Terminal.Gui/View/DrawContext.cs index 36b60c4c4d..2648caefe7 100644 --- a/Terminal.Gui/View/DrawContext.cs +++ b/Terminal.Gui/View/DrawContext.cs @@ -2,7 +2,7 @@ namespace Terminal.Gui; /// -/// Tracks the region that has been drawn during . This is primarily +/// Tracks the region that has been drawn during . This is primarily /// in support of . /// public class DrawContext diff --git a/Terminal.Gui/View/DrawEventArgs.cs b/Terminal.Gui/View/DrawEventArgs.cs index 5aabd2e660..b172d85ab3 100644 --- a/Terminal.Gui/View/DrawEventArgs.cs +++ b/Terminal.Gui/View/DrawEventArgs.cs @@ -16,7 +16,7 @@ public class DrawEventArgs : CancelEventArgs /// . /// /// - /// Add any regions that have been drawn to during operations to this context. This is + /// Add any regions that have been drawn to during operations to this context. This is /// primarily /// in support of . /// @@ -34,7 +34,7 @@ public DrawEventArgs (Rectangle newViewport, Rectangle oldViewport, DrawContext? public Rectangle NewViewport { get; } /// - /// Add any regions that have been drawn to during operations to this context. This is + /// Add any regions that have been drawn to during operations to this context. This is /// primarily /// in support of . /// diff --git a/Terminal.Gui/View/View.Content.cs b/Terminal.Gui/View/View.Content.cs index b187e01407..418f123c28 100644 --- a/Terminal.Gui/View/View.Content.cs +++ b/Terminal.Gui/View/View.Content.cs @@ -264,7 +264,7 @@ public ViewportSettings ViewportSettings /// /// /// Altering the Viewport Size will eventually (when the view is next laid out) cause the - /// and methods to be called. + /// and methods to be called. /// /// public virtual Rectangle Viewport diff --git a/Terminal.Gui/View/View.Drawing.cs b/Terminal.Gui/View/View.Drawing.cs index aa77e3f05a..11887b9df0 100644 --- a/Terminal.Gui/View/View.Drawing.cs +++ b/Terminal.Gui/View/View.Drawing.cs @@ -483,6 +483,7 @@ private void DoDrawContent (DrawContext? context = null) return; } + // TODO: Upgrade all overrides of OnDrawingContent to use DrawContext and remove this override if (OnDrawingContent ()) { return; @@ -504,7 +505,7 @@ private void DoDrawContent (DrawContext? context = null) /// /// The draw context to report drawn areas to. /// to stop further drawing content. - protected virtual bool OnDrawingContent (DrawContext? context = null) { return false; } + protected virtual bool OnDrawingContent (DrawContext? context) { return false; } /// /// Called when the View's content is to be drawn. The default implementation does nothing. diff --git a/Terminal.Gui/View/View.Mouse.cs b/Terminal.Gui/View/View.Mouse.cs index 691c10d8a8..bdce9b5e29 100644 --- a/Terminal.Gui/View/View.Mouse.cs +++ b/Terminal.Gui/View/View.Mouse.cs @@ -762,6 +762,7 @@ internal bool SetPressedHighlight (HighlightStyle newHighlightStyle) /// INTERNAL: Gets the Views that are under the mouse at , including Adornments. /// /// + /// If any transparent views will be ignored. /// internal static List GetViewsUnderMouse (in Point location, bool ignoreTransparent = false) { diff --git a/Terminal.Gui/Views/Bar.cs b/Terminal.Gui/Views/Bar.cs index 05bcc11014..d5b72c1857 100644 --- a/Terminal.Gui/Views/Bar.cs +++ b/Terminal.Gui/Views/Bar.cs @@ -109,11 +109,13 @@ public Orientation Orientation set => _orientationHelper.Orientation = value; } +#pragma warning disable CS0067 // The event is never used /// public event EventHandler>? OrientationChanging; /// public event EventHandler>? OrientationChanged; +#pragma warning restore CS0067 // The event is never used /// Called when has changed. /// diff --git a/Terminal.Gui/Views/Line.cs b/Terminal.Gui/Views/Line.cs index 9d28893733..45d2fa3cf0 100644 --- a/Terminal.Gui/Views/Line.cs +++ b/Terminal.Gui/Views/Line.cs @@ -33,11 +33,13 @@ public Orientation Orientation set => _orientationHelper.Orientation = value; } +#pragma warning disable CS0067 // The event is never used /// public event EventHandler> OrientationChanging; /// public event EventHandler> OrientationChanged; +#pragma warning restore CS0067 // The event is never used /// Called when has changed. /// diff --git a/Terminal.Gui/Views/RadioGroup.cs b/Terminal.Gui/Views/RadioGroup.cs index d72bebad79..c5513b09f5 100644 --- a/Terminal.Gui/Views/RadioGroup.cs +++ b/Terminal.Gui/Views/RadioGroup.cs @@ -403,12 +403,15 @@ public Orientation Orientation private readonly OrientationHelper _orientationHelper; +#pragma warning disable CS0067 // The event is never used /// public event EventHandler>? OrientationChanging; /// public event EventHandler>? OrientationChanged; +#pragma warning restore CS0067 + /// Called when has changed. /// public void OnOrientationChanged (Orientation newOrientation) diff --git a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs index 10df243a11..262e6091ae 100644 --- a/Terminal.Gui/Views/ScrollBar/ScrollBar.cs +++ b/Terminal.Gui/Views/ScrollBar/ScrollBar.cs @@ -164,8 +164,10 @@ public Orientation Orientation set => _orientationHelper.Orientation = value; } +#pragma warning disable CS0067 // The event is never used /// public event EventHandler>? OrientationChanging; +#pragma warning restore CS0067 // The event is never used /// public event EventHandler>? OrientationChanged; diff --git a/Terminal.Gui/Views/Wizard/WizardStep.cs b/Terminal.Gui/Views/Wizard/WizardStep.cs index 8d9be18b05..afb750ffba 100644 --- a/Terminal.Gui/Views/Wizard/WizardStep.cs +++ b/Terminal.Gui/Views/Wizard/WizardStep.cs @@ -125,7 +125,7 @@ public override View Add (View? view) { _contentView.Add (view); - if (view.CanFocus) + if (view!.CanFocus) { CanFocus = true; } diff --git a/UICatalog/Scenario.cs b/UICatalog/Scenario.cs index e45e269f7d..860ef27207 100644 --- a/UICatalog/Scenario.cs +++ b/UICatalog/Scenario.cs @@ -149,7 +149,7 @@ public static ObservableCollection GetScenarios () public virtual void Main () { } private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys - private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero + private const int BENCHMARK_KEY_PACING = 10; // Must be non-zero public static uint BenchmarkTimeout { get; set; } = 2500; diff --git a/UICatalog/Scenarios/RegionScenario.cs b/UICatalog/Scenarios/RegionScenario.cs index 9b2e29c1a0..2eb64d945d 100644 --- a/UICatalog/Scenarios/RegionScenario.cs +++ b/UICatalog/Scenarios/RegionScenario.cs @@ -19,10 +19,7 @@ public class RegionScenario : Scenario private Point? _dragStart; private bool _isDragging; - - public Rune? _previewFillRune = Glyphs.Stipple; - - public Rune? _fillRune = Glyphs.Dot; + private readonly Rune? _previewFillRune = Glyphs.Stipple; private RegionDrawStyles _drawStyle; private RegionOp _regionOp; @@ -34,25 +31,22 @@ public override void Main () Window app = new () { Title = GetQuitKeyAndName (), - TabStop = TabBehavior.TabGroup, - + TabStop = TabBehavior.TabGroup }; - app.Padding.Thickness = new (1); + app.Padding!.Thickness = new (1); var tools = new ToolsView { Title = "Tools", X = Pos.AnchorEnd (), Y = 2 }; - tools.CurrentAttribute = app.ColorScheme.HotNormal; + tools.CurrentAttribute = app.ColorScheme!.HotNormal; tools.SetStyle += b => { _drawStyle = (RegionDrawStyles)b; - app.SetNeedsDraw(); + app.SetNeedsDraw (); }; - tools.RegionOpChanged += (s, e) => - { - _regionOp = e; - }; + tools.RegionOpChanged += (s, e) => { _regionOp = e; }; + //tools.AddLayer += () => canvas.AddLayer (); app.Add (tools); @@ -87,7 +81,7 @@ public override void Main () _dragStart = null; } - app.SetNeedsDraw (); + app.SetNeedsDraw (); } }; @@ -120,12 +114,17 @@ public override void Main () if (_isDragging && _dragStart.HasValue) { Point currentMousePos = Application.GetLastMousePosition ()!.Value; - var previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos); + Rectangle previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos); var previewRegion = new Region (previewRect); previewRegion.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' '); - previewRegion.DrawBoundaries (app.LineCanvas, LineStyle.Dashed, new (tools.CurrentAttribute!.Value.Foreground.GetHighlightColor(), tools.CurrentAttribute!.Value.Background)); + previewRegion.DrawBoundaries ( + app.LineCanvas, + LineStyle.Dashed, + new ( + tools.CurrentAttribute!.Value.Foreground.GetHighlightColor (), + tools.CurrentAttribute!.Value.Background)); } }; @@ -138,7 +137,7 @@ public override void Main () private void AddRectangleFromPoints (Point start, Point end, RegionOp op) { - var rect = GetRectFromPoints (start, end); + Rectangle rect = GetRectFromPoints (start, end); var region = new Region (rect); _region.Combine (region, op); // Or RegionOp.MinimalUnion if you want minimal rectangles } @@ -154,7 +153,7 @@ private Rectangle GetRectFromPoints (Point start, Point end) int width = Math.Max (1, right - left + 1); int height = Math.Max (1, bottom - top + 1); - return new Rectangle (left, top, width, height); + return new (left, top, width, height); } } @@ -165,15 +164,14 @@ public enum RegionDrawStyles InnerBoundaries = 1, OuterBoundary = 2 - } public class ToolsView : Window { //private Button _addLayerBtn; private readonly AttributeView _attributeView = new (); - private RadioGroup _stylePicker; - private RegionOpSelector _regionOpSelector; + private RadioGroup? _stylePicker; + private RegionOpSelector? _regionOpSelector; public Attribute? CurrentAttribute { @@ -187,7 +185,6 @@ public ToolsView () Border!.Thickness = new (1, 2, 1, 1); Height = Dim.Auto (); Width = Dim.Auto (); - } //public event Action AddLayer; @@ -200,11 +197,11 @@ public override void BeginInit () _stylePicker = new () { - Width=Dim.Fill(), - X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames ().Select (n => n = "_" + n).ToArray() + Width = Dim.Fill (), + X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames ().Select (n => n = "_" + n).ToArray () }; _stylePicker.BorderStyle = LineStyle.Single; - _stylePicker.Border.Thickness = new (0, 1, 0, 0); + _stylePicker.Border!.Thickness = new (0, 1, 0, 0); _stylePicker.Title = "Draw Style"; _stylePicker.SelectedItemChanged += (s, a) => { SetStyle?.Invoke ((LineStyle)a.SelectedItem); }; @@ -221,7 +218,7 @@ public override void BeginInit () //_addLayerBtn = new () { Text = "New Layer", X = Pos.Center (), Y = Pos.Bottom (_stylePicker) }; //_addLayerBtn.Accepting += (s, a) => AddLayer?.Invoke (); - Add (_attributeView, _stylePicker, _regionOpSelector);//, _addLayerBtn); + Add (_attributeView, _stylePicker, _regionOpSelector); //, _addLayerBtn); } public event EventHandler? AttributeChanged; @@ -231,14 +228,15 @@ public override void BeginInit () public class RegionOpSelector : View { - private RadioGroup _radioGroup; + private readonly RadioGroup _radioGroup; + public RegionOpSelector () { Width = Dim.Auto (); Height = Dim.Auto (); BorderStyle = LineStyle.Single; - Border.Thickness = new (0, 1, 0, 0); + Border!.Thickness = new (0, 1, 0, 0); Title = "RegionOp"; _radioGroup = new () @@ -250,14 +248,14 @@ public RegionOpSelector () _radioGroup.SelectedItemChanged += (s, a) => { SelectedItemChanged?.Invoke (this, (RegionOp)a.SelectedItem); }; Add (_radioGroup); } + public event EventHandler? SelectedItemChanged; public RegionOp SelectedItem { get => (RegionOp)_radioGroup.SelectedItem; - set => _radioGroup.SelectedItem = (int) value; + set => _radioGroup.SelectedItem = (int)value; } - } public class AttributeView : View @@ -289,11 +287,11 @@ public Attribute? Value public AttributeView () { - Width = Dim.Fill(); + Width = Dim.Fill (); Height = 4; BorderStyle = LineStyle.Single; - Border.Thickness = new (0, 1, 0, 0); + Border!.Thickness = new (0, 1, 0, 0); Title = "Attribute"; } @@ -366,8 +364,8 @@ protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { ClickedInBackground (); } - } + mouseEvent.Handled = true; return mouseEvent.Handled; @@ -394,4 +392,4 @@ private void ClickedInForeground () SetNeedsDraw (); } } -} \ No newline at end of file +} diff --git a/UICatalog/Scenarios/Transparent.cs b/UICatalog/Scenarios/Transparent.cs index f2790cbc57..5841ed90fa 100644 --- a/UICatalog/Scenarios/Transparent.cs +++ b/UICatalog/Scenarios/Transparent.cs @@ -87,7 +87,7 @@ public TransparentView () Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, ShadowStyle = ShadowStyle.Transparent, }; - transparentSubView.Border.Thickness = new (1, 1, 1, 1); + transparentSubView.Border!.Thickness = new (1, 1, 1, 1); transparentSubView.ColorScheme = Colors.ColorSchemes ["Dialog"]; Button button = new Button () diff --git a/UICatalog/UICatalog.cs b/UICatalog/UICatalog.cs index 3ff3035ddc..e906ecd493 100644 --- a/UICatalog/UICatalog.cs +++ b/UICatalog/UICatalog.cs @@ -1304,14 +1304,14 @@ private List CreateLoggingMenuItems () { List menuItems = new () { - CreateLoggingFlagsMenuItems () + CreateLoggingFlagsMenuItems ()! }; return menuItems; } [SuppressMessage ("Style", "IDE1006:Naming Styles", Justification = "")] - private MenuItem [] CreateLoggingFlagsMenuItems () + private MenuItem? [] CreateLoggingFlagsMenuItems () { string [] logLevelMenuStrings = Enum.GetNames ().Select (n => n = "_" + n).ToArray (); LogLevel [] logLevels = Enum.GetValues ();