Skip to content

Commit 5984a3c

Browse files
authored
Fixes #3941 - v2win/v2net: UICatalog crash - Fixes warnings (#3946)
* Tons of API doc updates * Adjust timeout * Code cleanuyp * Disabled All_Scenarios_Benchmark * Removed logs * Fixed a bunch of warnings * Fixed a bunch of warnings2 * Disabled All_Scenarios_Benchmark again...just to make sure * Enabled All_Scenarios_Benchmark again...It is not the culprit
1 parent b0f3281 commit 5984a3c

File tree

17 files changed

+60
-50
lines changed

17 files changed

+60
-50
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,10 @@ demo.*
6161

6262
logs/
6363

64-
log.*
64+
BenchmarkDotNet.Artifacts/
65+
66+
*.log
67+
68+
*.log.*
69+
70+
log.*

Terminal.Gui/Application/Application.Initialization.cs

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ internal static void InternalInit (
167167
InitializedChanged?.Invoke (null, new (init));
168168
}
169169

170+
[RequiresUnreferencedCode ("AOT")]
171+
[RequiresDynamicCode ("AOT")]
170172
internal static void InitializeConfigurationManagement ()
171173
{
172174
// Start the process of configuration management.

Terminal.Gui/Configuration/ConfigurationManager.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,16 @@ public static void PrintJsonErrors ()
327327

328328

329329
/// <summary>
330-
/// Logs any Json deserialization errors that occurred during deserialization to the logging system.
330+
/// Logs Json deserialization errors that occurred during deserialization.
331331
/// </summary>
332332
public static void LogJsonErrors ()
333333
{
334334
if (_jsonErrors.Length > 0)
335335
{
336-
Logging.Warning (
336+
Logging.Error (
337337
@"Encountered the following errors while deserializing configuration files:"
338338
);
339-
Logging.Warning (_jsonErrors.ToString ());
339+
Logging.Error (_jsonErrors.ToString ());
340340
}
341341
}
342342

Terminal.Gui/ConsoleDrivers/AnsiResponseParser/Keyboard/CsiKeyPattern.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public CsiKeyPattern ()
5353
}
5454

5555
/// <summary>
56-
///
56+
/// Called by the base class to determine the key that matches the input.
5757
/// </summary>
5858
/// <param name="input"></param>
5959
/// <returns></returns>

Terminal.Gui/ConsoleDrivers/V2/MainLoop.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ internal void IterationImpl ()
151151

152152
private void SetCursor ()
153153
{
154-
View? mostFocused = Application.Top.MostFocused;
154+
View? mostFocused = Application.Top!.MostFocused;
155155

156156
if (mostFocused == null)
157157
{

Terminal.Gui/ConsoleDrivers/V2/NetInputProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class NetInputProcessor : InputProcessor<ConsoleKeyInfo>
1717
/// </remarks>
1818
/// </summary>
1919
public static bool GenerateTestCasesForKeyPresses = false;
20-
#pragma warning enable CA2211
20+
#pragma warning restore CA2211
2121

2222
/// <inheritdoc/>
2323
public NetInputProcessor (ConcurrentQueue<ConsoleKeyInfo> inputBuffer) : base (inputBuffer, new NetKeyConverter ()) { }

Terminal.Gui/Drawing/Region.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ internal static List<Rectangle> MergeVerticalIntervals (SortedSet<(int yTop, int
658658
}
659659
else
660660
{
661-
result.Add (new (startX, currentTop.Value, endX - startX, currentBottom.Value - currentTop.Value));
661+
result.Add (new (startX, currentTop.Value, endX - startX, currentBottom!.Value - currentTop.Value));
662662
currentTop = yTop;
663663
currentBottom = yBottom;
664664
}

Terminal.Gui/Input/Keyboard/Key.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public override bool Equals (object? obj)
418418
/// <param name="a"></param>
419419
/// <param name="b"></param>
420420
/// <returns></returns>
421-
public static bool operator != (Key a, Key? b) { return !a!.Equals (b); }
421+
public static bool operator != (Key? a, Key? b) { return !a!.Equals (b); }
422422

423423
/// <summary>Compares two <see cref="Key"/>s for less-than.</summary>
424424
/// <param name="a"></param>

Terminal.Gui/View/View.Content.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public ViewportSettings ViewportSettings
264264
/// </para>
265265
/// <para>
266266
/// Altering the Viewport Size will eventually (when the view is next laid out) cause the
267-
/// <see cref="Layout()"/> and <see cref="OnDrawingContent"/> methods to be called.
267+
/// <see cref="Layout()"/> and <see cref="OnDrawingContent()"/> methods to be called.
268268
/// </para>
269269
/// </remarks>
270270
public virtual Rectangle Viewport

Terminal.Gui/View/View.Drawing.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ private void DoDrawContent (DrawContext? context = null)
483483
return;
484484
}
485485

486+
// TODO: Upgrade all overrides of OnDrawingContent to use DrawContext and remove this override
486487
if (OnDrawingContent ())
487488
{
488489
return;
@@ -504,7 +505,7 @@ private void DoDrawContent (DrawContext? context = null)
504505
/// </summary>
505506
/// <param name="context">The draw context to report drawn areas to.</param>
506507
/// <returns><see langword="true"/> to stop further drawing content.</returns>
507-
protected virtual bool OnDrawingContent (DrawContext? context = null) { return false; }
508+
protected virtual bool OnDrawingContent (DrawContext? context) { return false; }
508509

509510
/// <summary>
510511
/// Called when the View's content is to be drawn. The default implementation does nothing.

Terminal.Gui/View/View.Mouse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ internal bool SetPressedHighlight (HighlightStyle newHighlightStyle)
762762
/// INTERNAL: Gets the Views that are under the mouse at <paramref name="location"/>, including Adornments.
763763
/// </summary>
764764
/// <param name="location"></param>
765-
/// <param name="ignoreTransparent"></param>
765+
/// <param name="ignoreTransparent">If <see langword="true"/> any transparent views will be ignored.</param>
766766
/// <returns></returns>
767767
internal static List<View?> GetViewsUnderMouse (in Point location, bool ignoreTransparent = false)
768768
{

Terminal.Gui/Views/RadioGroup.cs

+2
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ public Orientation Orientation
411411
public event EventHandler<EventArgs<Orientation>>? OrientationChanged;
412412
#pragma warning restore CS0067 // The event is never used
413413

414+
#pragma warning restore CS0067
415+
414416
/// <summary>Called when <see cref="Orientation"/> has changed.</summary>
415417
/// <param name="newOrientation"></param>
416418
public void OnOrientationChanged (Orientation newOrientation)

Terminal.Gui/Views/ScrollBar/ScrollBar.cs

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public Orientation Orientation
167167
#pragma warning disable CS0067 // The event is never used
168168
/// <inheritdoc/>
169169
public event EventHandler<CancelEventArgs<Orientation>>? OrientationChanging;
170+
#pragma warning restore CS0067 // The event is never used
170171

171172
/// <inheritdoc/>
172173
public event EventHandler<EventArgs<Orientation>>? OrientationChanged;

UICatalog/Scenario.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static ObservableCollection<Scenario> GetScenarios ()
149149
public virtual void Main () { }
150150

151151
private const uint BENCHMARK_MAX_NATURAL_ITERATIONS = 500; // not including needed for demo keys
152-
private const int BENCHMARK_KEY_PACING = 1; // Must be non-zero
152+
private const int BENCHMARK_KEY_PACING = 10; // Must be non-zero
153153

154154
public static uint BenchmarkTimeout { get; set; } = 2500;
155155

UICatalog/Scenarios/RegionScenario.cs

+32-34
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ public class RegionScenario : Scenario
1919
private Point? _dragStart;
2020
private bool _isDragging;
2121

22-
23-
public Rune? _previewFillRune = Glyphs.Stipple;
24-
25-
public Rune? _fillRune = Glyphs.Dot;
22+
private readonly Rune? _previewFillRune = Glyphs.Stipple;
2623

2724
private RegionDrawStyles _drawStyle;
2825
private RegionOp _regionOp;
@@ -34,25 +31,22 @@ public override void Main ()
3431
Window app = new ()
3532
{
3633
Title = GetQuitKeyAndName (),
37-
TabStop = TabBehavior.TabGroup,
38-
34+
TabStop = TabBehavior.TabGroup
3935
};
40-
app.Padding.Thickness = new (1);
36+
app.Padding!.Thickness = new (1);
4137

4238
var tools = new ToolsView { Title = "Tools", X = Pos.AnchorEnd (), Y = 2 };
4339

44-
tools.CurrentAttribute = app.ColorScheme.HotNormal;
40+
tools.CurrentAttribute = app.ColorScheme!.HotNormal;
4541

4642
tools.SetStyle += b =>
4743
{
4844
_drawStyle = (RegionDrawStyles)b;
49-
app.SetNeedsDraw();
45+
app.SetNeedsDraw ();
5046
};
5147

52-
tools.RegionOpChanged += (s, e) =>
53-
{
54-
_regionOp = e;
55-
};
48+
tools.RegionOpChanged += (s, e) => { _regionOp = e; };
49+
5650
//tools.AddLayer += () => canvas.AddLayer ();
5751

5852
app.Add (tools);
@@ -87,7 +81,7 @@ public override void Main ()
8781
_dragStart = null;
8882
}
8983

90-
app.SetNeedsDraw ();
84+
app.SetNeedsDraw ();
9185
}
9286
};
9387

@@ -120,12 +114,17 @@ public override void Main ()
120114
if (_isDragging && _dragStart.HasValue)
121115
{
122116
Point currentMousePos = Application.GetLastMousePosition ()!.Value;
123-
var previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
117+
Rectangle previewRect = GetRectFromPoints (_dragStart.Value, currentMousePos);
124118
var previewRegion = new Region (previewRect);
125119

126120
previewRegion.FillRectangles (tools.CurrentAttribute!.Value, (Rune)' ');
127121

128-
previewRegion.DrawBoundaries (app.LineCanvas, LineStyle.Dashed, new (tools.CurrentAttribute!.Value.Foreground.GetHighlightColor(), tools.CurrentAttribute!.Value.Background));
122+
previewRegion.DrawBoundaries (
123+
app.LineCanvas,
124+
LineStyle.Dashed,
125+
new (
126+
tools.CurrentAttribute!.Value.Foreground.GetHighlightColor (),
127+
tools.CurrentAttribute!.Value.Background));
129128
}
130129
};
131130

@@ -138,7 +137,7 @@ public override void Main ()
138137

139138
private void AddRectangleFromPoints (Point start, Point end, RegionOp op)
140139
{
141-
var rect = GetRectFromPoints (start, end);
140+
Rectangle rect = GetRectFromPoints (start, end);
142141
var region = new Region (rect);
143142
_region.Combine (region, op); // Or RegionOp.MinimalUnion if you want minimal rectangles
144143
}
@@ -154,7 +153,7 @@ private Rectangle GetRectFromPoints (Point start, Point end)
154153
int width = Math.Max (1, right - left + 1);
155154
int height = Math.Max (1, bottom - top + 1);
156155

157-
return new Rectangle (left, top, width, height);
156+
return new (left, top, width, height);
158157
}
159158
}
160159

@@ -165,15 +164,14 @@ public enum RegionDrawStyles
165164
InnerBoundaries = 1,
166165

167166
OuterBoundary = 2
168-
169167
}
170168

171169
public class ToolsView : Window
172170
{
173171
//private Button _addLayerBtn;
174172
private readonly AttributeView _attributeView = new ();
175-
private RadioGroup _stylePicker;
176-
private RegionOpSelector _regionOpSelector;
173+
private RadioGroup? _stylePicker;
174+
private RegionOpSelector? _regionOpSelector;
177175

178176
public Attribute? CurrentAttribute
179177
{
@@ -187,7 +185,6 @@ public ToolsView ()
187185
Border!.Thickness = new (1, 2, 1, 1);
188186
Height = Dim.Auto ();
189187
Width = Dim.Auto ();
190-
191188
}
192189

193190
//public event Action AddLayer;
@@ -200,11 +197,11 @@ public override void BeginInit ()
200197

201198
_stylePicker = new ()
202199
{
203-
Width=Dim.Fill(),
204-
X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames<RegionDrawStyles> ().Select (n => n = "_" + n).ToArray()
200+
Width = Dim.Fill (),
201+
X = 0, Y = Pos.Bottom (_attributeView) + 1, RadioLabels = Enum.GetNames<RegionDrawStyles> ().Select (n => n = "_" + n).ToArray ()
205202
};
206203
_stylePicker.BorderStyle = LineStyle.Single;
207-
_stylePicker.Border.Thickness = new (0, 1, 0, 0);
204+
_stylePicker.Border!.Thickness = new (0, 1, 0, 0);
208205
_stylePicker.Title = "Draw Style";
209206

210207
_stylePicker.SelectedItemChanged += (s, a) => { SetStyle?.Invoke ((LineStyle)a.SelectedItem); };
@@ -221,7 +218,7 @@ public override void BeginInit ()
221218
//_addLayerBtn = new () { Text = "New Layer", X = Pos.Center (), Y = Pos.Bottom (_stylePicker) };
222219

223220
//_addLayerBtn.Accepting += (s, a) => AddLayer?.Invoke ();
224-
Add (_attributeView, _stylePicker, _regionOpSelector);//, _addLayerBtn);
221+
Add (_attributeView, _stylePicker, _regionOpSelector); //, _addLayerBtn);
225222
}
226223

227224
public event EventHandler<Attribute?>? AttributeChanged;
@@ -231,14 +228,15 @@ public override void BeginInit ()
231228

232229
public class RegionOpSelector : View
233230
{
234-
private RadioGroup _radioGroup;
231+
private readonly RadioGroup _radioGroup;
232+
235233
public RegionOpSelector ()
236234
{
237235
Width = Dim.Auto ();
238236
Height = Dim.Auto ();
239237

240238
BorderStyle = LineStyle.Single;
241-
Border.Thickness = new (0, 1, 0, 0);
239+
Border!.Thickness = new (0, 1, 0, 0);
242240
Title = "RegionOp";
243241

244242
_radioGroup = new ()
@@ -250,14 +248,14 @@ public RegionOpSelector ()
250248
_radioGroup.SelectedItemChanged += (s, a) => { SelectedItemChanged?.Invoke (this, (RegionOp)a.SelectedItem); };
251249
Add (_radioGroup);
252250
}
251+
253252
public event EventHandler<RegionOp>? SelectedItemChanged;
254253

255254
public RegionOp SelectedItem
256255
{
257256
get => (RegionOp)_radioGroup.SelectedItem;
258-
set => _radioGroup.SelectedItem = (int) value;
257+
set => _radioGroup.SelectedItem = (int)value;
259258
}
260-
261259
}
262260

263261
public class AttributeView : View
@@ -289,11 +287,11 @@ public Attribute? Value
289287

290288
public AttributeView ()
291289
{
292-
Width = Dim.Fill();
290+
Width = Dim.Fill ();
293291
Height = 4;
294292

295293
BorderStyle = LineStyle.Single;
296-
Border.Thickness = new (0, 1, 0, 0);
294+
Border!.Thickness = new (0, 1, 0, 0);
297295
Title = "Attribute";
298296
}
299297

@@ -366,8 +364,8 @@ protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
366364
{
367365
ClickedInBackground ();
368366
}
369-
370367
}
368+
371369
mouseEvent.Handled = true;
372370

373371
return mouseEvent.Handled;
@@ -394,4 +392,4 @@ private void ClickedInForeground ()
394392
SetNeedsDraw ();
395393
}
396394
}
397-
}
395+
}

UICatalog/Scenarios/Transparent.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public TransparentView ()
8787
Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable,
8888
ShadowStyle = ShadowStyle.Transparent,
8989
};
90-
transparentSubView.Border.Thickness = new (1, 1, 1, 1);
90+
transparentSubView.Border!.Thickness = new (1, 1, 1, 1);
9191
transparentSubView.ColorScheme = Colors.ColorSchemes ["Dialog"];
9292

9393
Button button = new Button ()

UICatalog/UICatalog.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1308,14 +1308,14 @@ private List<MenuItem []> CreateLoggingMenuItems ()
13081308
{
13091309
List<MenuItem []> menuItems = new ()
13101310
{
1311-
CreateLoggingFlagsMenuItems ()
1311+
CreateLoggingFlagsMenuItems ()!
13121312
};
13131313

13141314
return menuItems;
13151315
}
13161316

13171317
[SuppressMessage ("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
1318-
private MenuItem [] CreateLoggingFlagsMenuItems ()
1318+
private MenuItem? [] CreateLoggingFlagsMenuItems ()
13191319
{
13201320
string [] logLevelMenuStrings = Enum.GetNames<LogLevel> ().Select (n => n = "_" + n).ToArray ();
13211321
LogLevel [] logLevels = Enum.GetValues<LogLevel> ();

0 commit comments

Comments
 (0)