From 018f4ebd17b379e6455b3ac071ad144fc648a84a Mon Sep 17 00:00:00 2001
From: Elisha Aguilera <103795105+Elisha-Aguilera@users.noreply.github.com>
Date: Sun, 14 May 2023 07:30:27 -0700
Subject: [PATCH] Minor refactors (#1081)
---
.../Extensions/CalendarExtensions.cs | 2 +-
src/Spectre.Console/Widgets/Calendar.cs | 4 ++--
src/Spectre.Console/Widgets/Grid.cs | 4 ++--
src/Spectre.Console/Widgets/Paragraph.cs | 20 ++++++-------------
src/Spectre.Console/Widgets/ProgressBar.cs | 10 ++--------
5 files changed, 13 insertions(+), 27 deletions(-)
diff --git a/src/Spectre.Console/Extensions/CalendarExtensions.cs b/src/Spectre.Console/Extensions/CalendarExtensions.cs
index 3d55649..8662626 100644
--- a/src/Spectre.Console/Extensions/CalendarExtensions.cs
+++ b/src/Spectre.Console/Extensions/CalendarExtensions.cs
@@ -74,7 +74,7 @@ public static class CalendarExtensions
throw new ArgumentNullException(nameof(calendar));
}
- calendar.HightlightStyle = style ?? Style.Plain;
+ calendar.HighlightStyle = style ?? Style.Plain;
return calendar;
}
diff --git a/src/Spectre.Console/Widgets/Calendar.cs b/src/Spectre.Console/Widgets/Calendar.cs
index 280e94e..18f1589 100644
--- a/src/Spectre.Console/Widgets/Calendar.cs
+++ b/src/Spectre.Console/Widgets/Calendar.cs
@@ -82,7 +82,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde
///
/// Gets or sets the calendar's highlight .
///
- public Style HightlightStyle
+ public Style HighlightStyle
{
get => _highlightStyle;
set => MarkAsDirty(() => _highlightStyle = value);
@@ -155,7 +155,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde
_culture = CultureInfo.InvariantCulture;
_highlightStyle = Color.Blue;
_showHeader = true;
- _calendarEvents = new ListWithCallback(() => MarkAsDirty());
+ _calendarEvents = new ListWithCallback(MarkAsDirty);
}
///
diff --git a/src/Spectre.Console/Widgets/Grid.cs b/src/Spectre.Console/Widgets/Grid.cs
index 7a14798..5799885 100644
--- a/src/Spectre.Console/Widgets/Grid.cs
+++ b/src/Spectre.Console/Widgets/Grid.cs
@@ -49,8 +49,8 @@ public sealed class Grid : JustInTimeRenderable, IExpandable, IAlignable
{
_expand = false;
_alignment = null;
- _columns = new ListWithCallback(() => MarkAsDirty());
- _rows = new ListWithCallback(() => MarkAsDirty());
+ _columns = new ListWithCallback(MarkAsDirty);
+ _rows = new ListWithCallback(MarkAsDirty);
}
///
diff --git a/src/Spectre.Console/Widgets/Paragraph.cs b/src/Spectre.Console/Widgets/Paragraph.cs
index 96012d4..5b884b3 100644
--- a/src/Spectre.Console/Widgets/Paragraph.cs
+++ b/src/Spectre.Console/Widgets/Paragraph.cs
@@ -68,8 +68,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
{
- var current = part;
-
if (first)
{
var line = _lines.LastOrDefault();
@@ -79,13 +77,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
line = _lines.Last();
}
- if (string.IsNullOrEmpty(current))
+ if (string.IsNullOrEmpty(part))
{
line.Add(Segment.Empty);
}
else
{
- foreach (var span in current.SplitWords())
+ foreach (var span in part.SplitWords())
{
line.Add(new Segment(span, style ?? Style.Plain));
}
@@ -95,13 +93,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
{
var line = new SegmentLine();
- if (string.IsNullOrEmpty(current))
+ if (string.IsNullOrEmpty(part))
{
line.Add(Segment.Empty);
}
else
{
- foreach (var span in current.SplitWords())
+ foreach (var span in part.SplitWords())
{
line.Add(new Segment(span, style ?? Style.Plain));
}
@@ -198,13 +196,11 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
var lines = new List();
var line = new SegmentLine();
- var newLine = true;
-
using var iterator = new SegmentLineIterator(_lines);
var queue = new Queue();
while (true)
{
- var current = (Segment?)null;
+ Segment? current;
if (queue.Count == 0)
{
if (!iterator.MoveNext())
@@ -224,13 +220,12 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
throw new InvalidOperationException("Iterator returned empty segment.");
}
- newLine = false;
+ var newLine = false;
if (current.IsLineBreak)
{
lines.Add(line);
line = new SegmentLine();
- newLine = true;
continue;
}
@@ -246,7 +241,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
{
lines.Add(line);
line = new SegmentLine();
- newLine = true;
segments.ForEach(s => queue.Enqueue(s));
continue;
@@ -276,8 +270,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
continue;
}
- newLine = false;
-
line.Add(current);
}
diff --git a/src/Spectre.Console/Widgets/ProgressBar.cs b/src/Spectre.Console/Widgets/ProgressBar.cs
index 099e700..2e6ea54 100644
--- a/src/Spectre.Console/Widgets/ProgressBar.cs
+++ b/src/Spectre.Console/Widgets/ProgressBar.cs
@@ -57,11 +57,6 @@ internal sealed class ProgressBar : Renderable, IHasCulture
barCount = Math.Max(0, barCount);
}
- if (barCount < 0)
- {
- yield break;
- }
-
yield return new Segment(new string(bar, barCount), style);
if (ShowValue)
@@ -99,14 +94,13 @@ internal sealed class ProgressBar : Renderable, IHasCulture
{
// For 1-bit and 3-bit colors, fall back to
// a simpler versions with only two colors.
- if (options.ColorSystem == ColorSystem.NoColors ||
- options.ColorSystem == ColorSystem.Legacy)
+ if (options.ColorSystem is ColorSystem.NoColors or ColorSystem.Legacy)
{
// First half of the pulse
var segments = Enumerable.Repeat(new Segment(bar, new Style(style.Foreground)), PULSESIZE / 2);
// Second half of the pulse
- var legacy = options.ColorSystem == ColorSystem.NoColors || options.ColorSystem == ColorSystem.Legacy;
+ var legacy = options.ColorSystem is ColorSystem.NoColors or ColorSystem.Legacy;
var bar2 = legacy ? " " : bar;
segments = segments.Concat(Enumerable.Repeat(new Segment(bar2, new Style(style.Background)), PULSESIZE - (PULSESIZE / 2)));