Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to match latest Spectre Console code #10

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/_build.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -12,9 +12,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CP.Nuke.BuildTools" Version="1.0.29" />
<PackageReference Include="CP.Nuke.BuildTools" Version="1.0.32" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageReference Include="Nuke.Common" Version="7.0.5" />
<PackageReference Include="Nuke.Common" Version="7.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,21 @@ public static BreakdownChart Compact(this BreakdownChart chart, bool compact)
chart.Compact = compact;
return chart;
}
}

/// <summary>
/// Sets the <see cref="BreakdownChart.ValueColor"/>.
/// </summary>
/// <param name="chart">The breakdown chart.</param>
/// <param name="color">The <see cref="Color"/> to set.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static BreakdownChart WithValueColor(this BreakdownChart chart, Color color)
{
if (chart is null)
{
throw new ArgumentNullException(nameof(chart));
}

chart.ValueColor = color;
return chart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ public static Progress Columns(this Progress progress, params ProgressColumn[] c
return progress;
}

/// <summary>
/// Sets an optional hook to intercept rendering.
/// </summary>
/// <param name="progress">The <see cref="Progress"/> instance.</param>
/// <param name="renderHook">The custom render function.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Progress UseRenderHook(this Progress progress, Func<IRenderable, IReadOnlyList<ProgressTask>, IRenderable> renderHook)
{
if (progress is null)
{
throw new ArgumentNullException(nameof(progress));
}

progress.RenderHook = renderHook;
return progress;
}

/// <summary>
/// Sets whether or not auto refresh is enabled.
/// If disabled, you will manually have to refresh the progress.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,38 @@ public static Table HideHeaders(this Table table)
return table;
}

/// <summary>
/// Shows row separators.
/// </summary>
/// <param name="table">The table.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table ShowRowSeparators(this Table table)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}

table.ShowRowSeparators = true;
return table;
}

/// <summary>
/// Hides row separators.
/// </summary>
/// <param name="table">The table.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static Table HideRowSeparators(this Table table)
{
if (table is null)
{
throw new ArgumentNullException(nameof(table));
}

table.ShowRowSeparators = false;
return table;
}

/// <summary>
/// Shows table footers.
/// </summary>
Expand Down Expand Up @@ -446,4 +478,4 @@ public static Table Caption(this Table table, TableTitle caption)
table.Caption = caption;
return table;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public Progress(IAnsiConsole console)
};
}

/// <summary>
/// Gets or sets a optional custom render function.
/// </summary>
public Func<IRenderable, IReadOnlyList<ProgressTask>, IRenderable> RenderHook { get; set; } = (renderable, _) => renderable;

/// <summary>
/// Gets or sets a value indicating whether or not task list should auto refresh.
/// Defaults to <c>true</c>.
Expand Down Expand Up @@ -162,7 +167,7 @@ private ProgressRenderer CreateRenderer()
if (interactive)
{
var columns = new List<ProgressColumn>(Columns);
return new DefaultProgressRenderer(_console, columns, RefreshRate, HideCompleted);
return new DefaultProgressRenderer(_console, columns, RefreshRate, HideCompleted, RenderHook);
}

return FallbackRenderer ?? new FallbackProgressRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Spectre.Console.Rx;

internal sealed class DefaultProgressRenderer(IAnsiConsole console, List<ProgressColumn> columns, TimeSpan refreshRate, bool hideCompleted) : ProgressRenderer
internal sealed class DefaultProgressRenderer(IAnsiConsole console, List<ProgressColumn> columns, TimeSpan refreshRate, bool hideCompleted, Func<IRenderable, IReadOnlyList<ProgressTask>, IRenderable> renderHook) : ProgressRenderer
{
private readonly IAnsiConsole _console = console ?? throw new ArgumentNullException(nameof(console));
private readonly List<ProgressColumn> _columns = columns ?? throw new ArgumentNullException(nameof(columns));
Expand Down Expand Up @@ -81,13 +81,20 @@ public override void Update(ProgressContext context)
}

// Add rows
foreach (var task in context.GetTasks().Where(tsk => !(hideCompleted && tsk.IsFinished)))
var tasks = context.GetTasks();

var layout = new Grid();
layout.AddColumn();

foreach (var task in tasks.Where(tsk => !(hideCompleted && tsk.IsFinished)))
{
var columns = _columns.Select(column => column.Render(renderContext, task, delta));
grid.AddRow(columns.ToArray());
}

_live.SetRenderable(new Padder(grid, new Padding(0, 1)));
layout.AddRow(grid);

_live.SetRenderable(new Padder(renderHook(layout, tasks), new Padding(0, 1)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,24 @@ public enum TableBorderPart
/// The bottom right part of a footer.
/// </summary>
FooterBottomRight,
}

/// <summary>
/// The left part of a row.
/// </summary>
RowLeft,

/// <summary>
/// The center part of a row.
/// </summary>
RowCenter,

/// <summary>
/// The separator part of a row.
/// </summary>
RowSeparator,

/// <summary>
/// The right part of a row.
/// </summary>
RowRight,
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class Ascii2TableBorder : TableBorder
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "+",
TableBorderPart.FooterBottomRight => "+",
TableBorderPart.RowLeft => "|",
TableBorderPart.RowCenter => "-",
TableBorderPart.RowSeparator => "+",
TableBorderPart.RowRight => "|",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class AsciiDoubleHeadTableBorder : TableBorder
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "+",
TableBorderPart.FooterBottomRight => "+",
TableBorderPart.RowLeft => "|",
TableBorderPart.RowCenter => "-",
TableBorderPart.RowSeparator => "+",
TableBorderPart.RowRight => "|",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class AsciiTableBorder : TableBorder
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "-",
TableBorderPart.FooterBottomRight => "+",
TableBorderPart.RowLeft => "|",
TableBorderPart.RowCenter => "-",
TableBorderPart.RowSeparator => "+",
TableBorderPart.RowRight => "|",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class DoubleEdgeTableBorder : TableBorder
TableBorderPart.FooterBottom => "═",
TableBorderPart.FooterBottomSeparator => "╧",
TableBorderPart.FooterBottomRight => "╝",
TableBorderPart.RowLeft => "╟",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => "╢",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class DoubleTableBorder : TableBorder
TableBorderPart.FooterBottom => "═",
TableBorderPart.FooterBottomSeparator => "╩",
TableBorderPart.FooterBottomRight => "╝",
TableBorderPart.RowLeft => "╠",
TableBorderPart.RowCenter => "═",
TableBorderPart.RowSeparator => "╬",
TableBorderPart.RowRight => "╣",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public sealed class HeavyEdgeTableBorder : TableBorder
TableBorderPart.FooterBottom => "━",
TableBorderPart.FooterBottomSeparator => "┷",
TableBorderPart.FooterBottomRight => "┛",
TableBorderPart.RowLeft => "┠",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => "┨",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public sealed class HeavyHeadTableBorder : TableBorder
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "┴",
TableBorderPart.FooterBottomRight => "┘",
TableBorderPart.RowLeft => "├",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => "┤",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public sealed class HeavyTableBorder : TableBorder
TableBorderPart.FooterBottom => "━",
TableBorderPart.FooterBottomSeparator => "┻",
TableBorderPart.FooterBottomRight => "┛",
TableBorderPart.RowLeft => "┣",
TableBorderPart.RowCenter => "━",
TableBorderPart.RowSeparator => "╋",
TableBorderPart.RowRight => "┫",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class HorizontalTableBorder : TableBorder
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "─",
TableBorderPart.FooterBottomRight => "─",
TableBorderPart.RowLeft => "─",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "─",
TableBorderPart.RowRight => "─",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace Spectre.Console.Rx.Rendering;
/// </summary>
public sealed class MarkdownTableBorder : TableBorder
{
/// <inheritdoc />
public override bool SupportsRowSeparator => false;

/// <inheritdoc/>
public override string GetPart(TableBorderPart part) => part switch
{
Expand All @@ -33,6 +36,10 @@ public sealed class MarkdownTableBorder : TableBorder
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
TableBorderPart.RowLeft => " ",
TableBorderPart.RowCenter => " ",
TableBorderPart.RowSeparator => " ",
TableBorderPart.RowRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};

Expand All @@ -58,7 +65,7 @@ public override string GetColumnRow(TablePart part, IReadOnlyList<int> widths, I
{
var padding = columns[columnIndex].Padding;

if (padding != null && padding.Value.Left > 0)
if (padding?.Left > 0)
{
// Left padding
builder.Append(" ".Repeat(padding.Value.Left));
Expand Down Expand Up @@ -91,7 +98,7 @@ public override string GetColumnRow(TablePart part, IReadOnlyList<int> widths, I
}

// Right padding
if (padding != null && padding.Value.Right > 0)
if (padding?.Right > 0)
{
builder.Append(" ".Repeat(padding.Value.Right));
}
Expand All @@ -105,4 +112,4 @@ public override string GetColumnRow(TablePart part, IReadOnlyList<int> widths, I
builder.Append(right);
return builder.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class MinimalDoubleHeadTableBorder : TableBorder
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
TableBorderPart.RowLeft => " ",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public sealed class MinimalHeavyHeadTableBorder : TableBorder
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
TableBorderPart.RowLeft => " ",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class MinimalTableBorder : TableBorder
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
TableBorderPart.RowLeft => " ",
TableBorderPart.RowCenter => "─",
TableBorderPart.RowSeparator => "┼",
TableBorderPart.RowRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
Loading
Loading