mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-14 16:02:50 +08:00
Minor refactors (#1081)
This commit is contained in:
parent
404b052a5f
commit
018f4ebd17
@ -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;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde
|
||||
/// <summary>
|
||||
/// Gets or sets the calendar's highlight <see cref="Style"/>.
|
||||
/// </summary>
|
||||
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<CalendarEvent>(() => MarkAsDirty());
|
||||
_calendarEvents = new ListWithCallback<CalendarEvent>(MarkAsDirty);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
@ -49,8 +49,8 @@ public sealed class Grid : JustInTimeRenderable, IExpandable, IAlignable
|
||||
{
|
||||
_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>
|
||||
|
@ -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<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())
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user