Skip to content

Commit 018f4eb

Browse files
Minor refactors (#1081)
1 parent 404b052 commit 018f4eb

File tree

5 files changed

+13
-27
lines changed

5 files changed

+13
-27
lines changed

src/Spectre.Console/Extensions/CalendarExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static Calendar HighlightStyle(this Calendar calendar, Style? style)
7474
throw new ArgumentNullException(nameof(calendar));
7575
}
7676

77-
calendar.HightlightStyle = style ?? Style.Plain;
77+
calendar.HighlightStyle = style ?? Style.Plain;
7878
return calendar;
7979
}
8080

src/Spectre.Console/Widgets/Calendar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public CultureInfo? Culture
8282
/// <summary>
8383
/// Gets or sets the calendar's highlight <see cref="Style"/>.
8484
/// </summary>
85-
public Style HightlightStyle
85+
public Style HighlightStyle
8686
{
8787
get => _highlightStyle;
8888
set => MarkAsDirty(() => _highlightStyle = value);
@@ -155,7 +155,7 @@ public Calendar(int year, int month, int day)
155155
_culture = CultureInfo.InvariantCulture;
156156
_highlightStyle = Color.Blue;
157157
_showHeader = true;
158-
_calendarEvents = new ListWithCallback<CalendarEvent>(() => MarkAsDirty());
158+
_calendarEvents = new ListWithCallback<CalendarEvent>(MarkAsDirty);
159159
}
160160

161161
/// <inheritdoc/>

src/Spectre.Console/Widgets/Grid.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public Grid()
4949
{
5050
_expand = false;
5151
_alignment = null;
52-
_columns = new ListWithCallback<GridColumn>(() => MarkAsDirty());
53-
_rows = new ListWithCallback<GridRow>(() => MarkAsDirty());
52+
_columns = new ListWithCallback<GridColumn>(MarkAsDirty);
53+
_rows = new ListWithCallback<GridRow>(MarkAsDirty);
5454
}
5555

5656
/// <summary>

src/Spectre.Console/Widgets/Paragraph.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public Paragraph Append(string text, Style? style = null)
6868

6969
foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
7070
{
71-
var current = part;
72-
7371
if (first)
7472
{
7573
var line = _lines.LastOrDefault();
@@ -79,13 +77,13 @@ public Paragraph Append(string text, Style? style = null)
7977
line = _lines.Last();
8078
}
8179

82-
if (string.IsNullOrEmpty(current))
80+
if (string.IsNullOrEmpty(part))
8381
{
8482
line.Add(Segment.Empty);
8583
}
8684
else
8785
{
88-
foreach (var span in current.SplitWords())
86+
foreach (var span in part.SplitWords())
8987
{
9088
line.Add(new Segment(span, style ?? Style.Plain));
9189
}
@@ -95,13 +93,13 @@ public Paragraph Append(string text, Style? style = null)
9593
{
9694
var line = new SegmentLine();
9795

98-
if (string.IsNullOrEmpty(current))
96+
if (string.IsNullOrEmpty(part))
9997
{
10098
line.Add(Segment.Empty);
10199
}
102100
else
103101
{
104-
foreach (var span in current.SplitWords())
102+
foreach (var span in part.SplitWords())
105103
{
106104
line.Add(new Segment(span, style ?? Style.Plain));
107105
}
@@ -198,13 +196,11 @@ private List<SegmentLine> SplitLines(int maxWidth)
198196
var lines = new List<SegmentLine>();
199197
var line = new SegmentLine();
200198

201-
var newLine = true;
202-
203199
using var iterator = new SegmentLineIterator(_lines);
204200
var queue = new Queue<Segment>();
205201
while (true)
206202
{
207-
var current = (Segment?)null;
203+
Segment? current;
208204
if (queue.Count == 0)
209205
{
210206
if (!iterator.MoveNext())
@@ -224,13 +220,12 @@ private List<SegmentLine> SplitLines(int maxWidth)
224220
throw new InvalidOperationException("Iterator returned empty segment.");
225221
}
226222

227-
newLine = false;
223+
var newLine = false;
228224

229225
if (current.IsLineBreak)
230226
{
231227
lines.Add(line);
232228
line = new SegmentLine();
233-
newLine = true;
234229
continue;
235230
}
236231

@@ -246,7 +241,6 @@ private List<SegmentLine> SplitLines(int maxWidth)
246241
{
247242
lines.Add(line);
248243
line = new SegmentLine();
249-
newLine = true;
250244

251245
segments.ForEach(s => queue.Enqueue(s));
252246
continue;
@@ -276,8 +270,6 @@ private List<SegmentLine> SplitLines(int maxWidth)
276270
continue;
277271
}
278272

279-
newLine = false;
280-
281273
line.Add(current);
282274
}
283275

src/Spectre.Console/Widgets/ProgressBar.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
5757
barCount = Math.Max(0, barCount);
5858
}
5959

60-
if (barCount < 0)
61-
{
62-
yield break;
63-
}
64-
6560
yield return new Segment(new string(bar, barCount), style);
6661

6762
if (ShowValue)
@@ -99,14 +94,13 @@ IEnumerable<Segment> GetPulseSegments()
9994
{
10095
// For 1-bit and 3-bit colors, fall back to
10196
// a simpler versions with only two colors.
102-
if (options.ColorSystem == ColorSystem.NoColors ||
103-
options.ColorSystem == ColorSystem.Legacy)
97+
if (options.ColorSystem is ColorSystem.NoColors or ColorSystem.Legacy)
10498
{
10599
// First half of the pulse
106100
var segments = Enumerable.Repeat(new Segment(bar, new Style(style.Foreground)), PULSESIZE / 2);
107101

108102
// Second half of the pulse
109-
var legacy = options.ColorSystem == ColorSystem.NoColors || options.ColorSystem == ColorSystem.Legacy;
103+
var legacy = options.ColorSystem is ColorSystem.NoColors or ColorSystem.Legacy;
110104
var bar2 = legacy ? " " : bar;
111105
segments = segments.Concat(Enumerable.Repeat(new Segment(bar2, new Style(style.Background)), PULSESIZE - (PULSESIZE / 2)));
112106

0 commit comments

Comments
 (0)