Skip to content

Commit

Permalink
Minor refactors (#1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisha-Aguilera authored May 14, 2023
1 parent 404b052 commit 018f4eb
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/Spectre.Console/Extensions/CalendarExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static Calendar HighlightStyle(this Calendar calendar, Style? style)
throw new ArgumentNullException(nameof(calendar));
}

calendar.HightlightStyle = style ?? Style.Plain;
calendar.HighlightStyle = style ?? Style.Plain;
return calendar;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console/Widgets/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public CultureInfo? Culture
/// <summary>
/// Gets or sets the calendar's highlight <see cref="Style"/>.
/// </summary>
public Style HightlightStyle
public Style HighlightStyle
{
get => _highlightStyle;
set => MarkAsDirty(() => _highlightStyle = value);
Expand Down Expand Up @@ -155,7 +155,7 @@ public Calendar(int year, int month, int day)
_culture = CultureInfo.InvariantCulture;
_highlightStyle = Color.Blue;
_showHeader = true;
_calendarEvents = new ListWithCallback<CalendarEvent>(() => MarkAsDirty());
_calendarEvents = new ListWithCallback<CalendarEvent>(MarkAsDirty);
}

/// <inheritdoc/>
Expand Down
4 changes: 2 additions & 2 deletions src/Spectre.Console/Widgets/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public Grid()
{
_expand = false;
_alignment = null;
_columns = new ListWithCallback<GridColumn>(() => MarkAsDirty());
_rows = new ListWithCallback<GridRow>(() => MarkAsDirty());
_columns = new ListWithCallback<GridColumn>(MarkAsDirty);
_rows = new ListWithCallback<GridRow>(MarkAsDirty);
}

/// <summary>
Expand Down
20 changes: 6 additions & 14 deletions src/Spectre.Console/Widgets/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public Paragraph Append(string text, Style? style = null)

foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
{
var current = part;

if (first)
{
var line = _lines.LastOrDefault();
Expand All @@ -79,13 +77,13 @@ public Paragraph Append(string text, Style? style = null)
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));
}
Expand All @@ -95,13 +93,13 @@ public Paragraph Append(string text, Style? style = null)
{
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));
}
Expand Down Expand Up @@ -198,13 +196,11 @@ private List<SegmentLine> SplitLines(int maxWidth)
var lines = new List<SegmentLine>();
var line = new SegmentLine();

var newLine = true;

using var iterator = new SegmentLineIterator(_lines);
var queue = new Queue<Segment>();
while (true)
{
var current = (Segment?)null;
Segment? current;
if (queue.Count == 0)
{
if (!iterator.MoveNext())
Expand All @@ -224,13 +220,12 @@ private List<SegmentLine> SplitLines(int maxWidth)
throw new InvalidOperationException("Iterator returned empty segment.");
}

newLine = false;
var newLine = false;

if (current.IsLineBreak)
{
lines.Add(line);
line = new SegmentLine();
newLine = true;
continue;
}

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

segments.ForEach(s => queue.Enqueue(s));
continue;
Expand Down Expand Up @@ -276,8 +270,6 @@ private List<SegmentLine> SplitLines(int maxWidth)
continue;
}

newLine = false;

line.Add(current);
}

Expand Down
10 changes: 2 additions & 8 deletions src/Spectre.Console/Widgets/ProgressBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
barCount = Math.Max(0, barCount);
}

if (barCount < 0)
{
yield break;
}

yield return new Segment(new string(bar, barCount), style);

if (ShowValue)
Expand Down Expand Up @@ -99,14 +94,13 @@ IEnumerable<Segment> GetPulseSegments()
{
// 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)));

Expand Down

0 comments on commit 018f4eb

Please sign in to comment.