mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52: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));
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
}
|
}
|
||||||
|
|
||||||
calendar.HightlightStyle = style ?? Style.Plain;
|
calendar.HighlightStyle = style ?? Style.Plain;
|
||||||
return calendar;
|
return calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the calendar's highlight <see cref="Style"/>.
|
/// Gets or sets the calendar's highlight <see cref="Style"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Style HightlightStyle
|
public Style HighlightStyle
|
||||||
{
|
{
|
||||||
get => _highlightStyle;
|
get => _highlightStyle;
|
||||||
set => MarkAsDirty(() => _highlightStyle = value);
|
set => MarkAsDirty(() => _highlightStyle = value);
|
||||||
@ -155,7 +155,7 @@ public sealed class Calendar : JustInTimeRenderable, IHasCulture, IHasTableBorde
|
|||||||
_culture = CultureInfo.InvariantCulture;
|
_culture = CultureInfo.InvariantCulture;
|
||||||
_highlightStyle = Color.Blue;
|
_highlightStyle = Color.Blue;
|
||||||
_showHeader = true;
|
_showHeader = true;
|
||||||
_calendarEvents = new ListWithCallback<CalendarEvent>(() => MarkAsDirty());
|
_calendarEvents = new ListWithCallback<CalendarEvent>(MarkAsDirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
@ -49,8 +49,8 @@ public sealed class Grid : JustInTimeRenderable, IExpandable, IAlignable
|
|||||||
{
|
{
|
||||||
_expand = false;
|
_expand = false;
|
||||||
_alignment = null;
|
_alignment = null;
|
||||||
_columns = new ListWithCallback<GridColumn>(() => MarkAsDirty());
|
_columns = new ListWithCallback<GridColumn>(MarkAsDirty);
|
||||||
_rows = new ListWithCallback<GridRow>(() => MarkAsDirty());
|
_rows = new ListWithCallback<GridRow>(MarkAsDirty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -68,8 +68,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
|
|
||||||
foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
|
foreach (var (_, first, last, part) in text.SplitLines().Enumerate())
|
||||||
{
|
{
|
||||||
var current = part;
|
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
var line = _lines.LastOrDefault();
|
var line = _lines.LastOrDefault();
|
||||||
@ -79,13 +77,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
line = _lines.Last();
|
line = _lines.Last();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(current))
|
if (string.IsNullOrEmpty(part))
|
||||||
{
|
{
|
||||||
line.Add(Segment.Empty);
|
line.Add(Segment.Empty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var span in current.SplitWords())
|
foreach (var span in part.SplitWords())
|
||||||
{
|
{
|
||||||
line.Add(new Segment(span, style ?? Style.Plain));
|
line.Add(new Segment(span, style ?? Style.Plain));
|
||||||
}
|
}
|
||||||
@ -95,13 +93,13 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
{
|
{
|
||||||
var line = new SegmentLine();
|
var line = new SegmentLine();
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(current))
|
if (string.IsNullOrEmpty(part))
|
||||||
{
|
{
|
||||||
line.Add(Segment.Empty);
|
line.Add(Segment.Empty);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var span in current.SplitWords())
|
foreach (var span in part.SplitWords())
|
||||||
{
|
{
|
||||||
line.Add(new Segment(span, style ?? Style.Plain));
|
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 lines = new List<SegmentLine>();
|
||||||
var line = new SegmentLine();
|
var line = new SegmentLine();
|
||||||
|
|
||||||
var newLine = true;
|
|
||||||
|
|
||||||
using var iterator = new SegmentLineIterator(_lines);
|
using var iterator = new SegmentLineIterator(_lines);
|
||||||
var queue = new Queue<Segment>();
|
var queue = new Queue<Segment>();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var current = (Segment?)null;
|
Segment? current;
|
||||||
if (queue.Count == 0)
|
if (queue.Count == 0)
|
||||||
{
|
{
|
||||||
if (!iterator.MoveNext())
|
if (!iterator.MoveNext())
|
||||||
@ -224,13 +220,12 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
throw new InvalidOperationException("Iterator returned empty segment.");
|
throw new InvalidOperationException("Iterator returned empty segment.");
|
||||||
}
|
}
|
||||||
|
|
||||||
newLine = false;
|
var newLine = false;
|
||||||
|
|
||||||
if (current.IsLineBreak)
|
if (current.IsLineBreak)
|
||||||
{
|
{
|
||||||
lines.Add(line);
|
lines.Add(line);
|
||||||
line = new SegmentLine();
|
line = new SegmentLine();
|
||||||
newLine = true;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +241,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
{
|
{
|
||||||
lines.Add(line);
|
lines.Add(line);
|
||||||
line = new SegmentLine();
|
line = new SegmentLine();
|
||||||
newLine = true;
|
|
||||||
|
|
||||||
segments.ForEach(s => queue.Enqueue(s));
|
segments.ForEach(s => queue.Enqueue(s));
|
||||||
continue;
|
continue;
|
||||||
@ -276,8 +270,6 @@ public sealed class Paragraph : Renderable, IHasJustification, IOverflowable
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
newLine = false;
|
|
||||||
|
|
||||||
line.Add(current);
|
line.Add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +57,6 @@ internal sealed class ProgressBar : Renderable, IHasCulture
|
|||||||
barCount = Math.Max(0, barCount);
|
barCount = Math.Max(0, barCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barCount < 0)
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
yield return new Segment(new string(bar, barCount), style);
|
yield return new Segment(new string(bar, barCount), style);
|
||||||
|
|
||||||
if (ShowValue)
|
if (ShowValue)
|
||||||
@ -99,14 +94,13 @@ internal sealed class ProgressBar : Renderable, IHasCulture
|
|||||||
{
|
{
|
||||||
// For 1-bit and 3-bit colors, fall back to
|
// For 1-bit and 3-bit colors, fall back to
|
||||||
// a simpler versions with only two colors.
|
// a simpler versions with only two colors.
|
||||||
if (options.ColorSystem == ColorSystem.NoColors ||
|
if (options.ColorSystem is ColorSystem.NoColors or ColorSystem.Legacy)
|
||||||
options.ColorSystem == ColorSystem.Legacy)
|
|
||||||
{
|
{
|
||||||
// First half of the pulse
|
// First half of the pulse
|
||||||
var segments = Enumerable.Repeat(new Segment(bar, new Style(style.Foreground)), PULSESIZE / 2);
|
var segments = Enumerable.Repeat(new Segment(bar, new Style(style.Foreground)), PULSESIZE / 2);
|
||||||
|
|
||||||
// Second half of the pulse
|
// 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;
|
var bar2 = legacy ? " " : bar;
|
||||||
segments = segments.Concat(Enumerable.Repeat(new Segment(bar2, new Style(style.Background)), PULSESIZE - (PULSESIZE / 2)));
|
segments = segments.Concat(Enumerable.Repeat(new Segment(bar2, new Style(style.Background)), PULSESIZE - (PULSESIZE / 2)));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user