Add support for markdown tables

Closes #85

* Split Border into BoxBorder and TableBorder
* Change how different table parts are composed
* Add markdown table border
This commit is contained in:
Patrik Svensson
2020-09-30 23:37:28 +02:00
committed by Patrik Svensson
parent 697273917e
commit 93ec7401c8
73 changed files with 2117 additions and 1076 deletions

View File

@ -0,0 +1,48 @@
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents the different parts of a box border.
/// </summary>
public enum BoxBorderPart
{
/// <summary>
/// The top left part of a box.
/// </summary>
TopLeft,
/// <summary>
/// The top part of a box.
/// </summary>
Top,
/// <summary>
/// The top right part of a box.
/// </summary>
TopRight,
/// <summary>
/// The left part of a box.
/// </summary>
Left,
/// <summary>
/// The right part of a box.
/// </summary>
Right,
/// <summary>
/// The bottom left part of a box.
/// </summary>
BottomLeft,
/// <summary>
/// The bottom part of a box.
/// </summary>
Bottom,
/// <summary>
/// The bottom right part of a box.
/// </summary>
BottomRight,
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents an old school ASCII border.
/// </summary>
public sealed class AsciiBoxBorder : BoxBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return part switch
{
BoxBorderPart.TopLeft => "+",
BoxBorderPart.Top => "-",
BoxBorderPart.TopRight => "+",
BoxBorderPart.Left => "|",
BoxBorderPart.Right => "|",
BoxBorderPart.BottomLeft => "+",
BoxBorderPart.Bottom => "-",
BoxBorderPart.BottomRight => "+",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a double border.
/// </summary>
public sealed class DoubleBoxBorder : BoxBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return part switch
{
BoxBorderPart.TopLeft => "╔",
BoxBorderPart.Top => "═",
BoxBorderPart.TopRight => "╗",
BoxBorderPart.Left => "║",
BoxBorderPart.Right => "║",
BoxBorderPart.BottomLeft => "╚",
BoxBorderPart.Bottom => "═",
BoxBorderPart.BottomRight => "╝",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,30 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a heavy border.
/// </summary>
public sealed class HeavyBoxBorder : BoxBorder
{
/// <inheritdoc/>
public override BoxBorder? SafeBorder => BoxBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return part switch
{
BoxBorderPart.TopLeft => "┏",
BoxBorderPart.Top => "━",
BoxBorderPart.TopRight => "┓",
BoxBorderPart.Left => "┃",
BoxBorderPart.Right => "┃",
BoxBorderPart.BottomLeft => "┗",
BoxBorderPart.Bottom => "━",
BoxBorderPart.BottomRight => "┛",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,14 @@
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents an invisible border.
/// </summary>
public sealed class NoBoxBorder : BoxBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return " ";
}
}
}

View File

@ -0,0 +1,30 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a rounded border.
/// </summary>
public sealed class RoundedBoxBorder : BoxBorder
{
/// <inheritdoc/>
public override BoxBorder? SafeBorder => BoxBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return part switch
{
BoxBorderPart.TopLeft => "╭",
BoxBorderPart.Top => "─",
BoxBorderPart.TopRight => "╮",
BoxBorderPart.Left => "│",
BoxBorderPart.Right => "│",
BoxBorderPart.BottomLeft => "╰",
BoxBorderPart.Bottom => "─",
BoxBorderPart.BottomRight => "╯",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,27 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a square border.
/// </summary>
public sealed class SquareBoxBorder : BoxBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(BoxBorderPart part)
{
return part switch
{
BoxBorderPart.TopLeft => "┌",
BoxBorderPart.Top => "─",
BoxBorderPart.TopRight => "┐",
BoxBorderPart.Left => "│",
BoxBorderPart.Right => "│",
BoxBorderPart.BottomLeft => "└",
BoxBorderPart.Bottom => "─",
BoxBorderPart.BottomRight => "┘",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -1,9 +1,9 @@
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents the different border parts.
/// Represents the different parts of a table border.
/// </summary>
public enum BorderPart
public enum TableBorderPart
{
/// <summary>
/// The top left part of a header.

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents another old school ASCII border.
/// </summary>
public sealed class Ascii2TableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "+",
TableBorderPart.HeaderTop => "-",
TableBorderPart.HeaderTopSeparator => "+",
TableBorderPart.HeaderTopRight => "+",
TableBorderPart.HeaderLeft => "|",
TableBorderPart.HeaderSeparator => "|",
TableBorderPart.HeaderRight => "|",
TableBorderPart.HeaderBottomLeft => "|",
TableBorderPart.HeaderBottom => "-",
TableBorderPart.HeaderBottomSeparator => "+",
TableBorderPart.HeaderBottomRight => "|",
TableBorderPart.CellLeft => "|",
TableBorderPart.CellSeparator => "|",
TableBorderPart.CellRight => "|",
TableBorderPart.FooterBottomLeft => "+",
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "+",
TableBorderPart.FooterBottomRight => "+",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents an old school ASCII border with a double header border.
/// </summary>
public sealed class AsciiDoubleHeadTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "+",
TableBorderPart.HeaderTop => "-",
TableBorderPart.HeaderTopSeparator => "+",
TableBorderPart.HeaderTopRight => "+",
TableBorderPart.HeaderLeft => "|",
TableBorderPart.HeaderSeparator => "|",
TableBorderPart.HeaderRight => "|",
TableBorderPart.HeaderBottomLeft => "|",
TableBorderPart.HeaderBottom => "=",
TableBorderPart.HeaderBottomSeparator => "+",
TableBorderPart.HeaderBottomRight => "|",
TableBorderPart.CellLeft => "|",
TableBorderPart.CellSeparator => "|",
TableBorderPart.CellRight => "|",
TableBorderPart.FooterBottomLeft => "+",
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "+",
TableBorderPart.FooterBottomRight => "+",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents an old school ASCII border.
/// </summary>
public sealed class AsciiTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "+",
TableBorderPart.HeaderTop => "-",
TableBorderPart.HeaderTopSeparator => "-",
TableBorderPart.HeaderTopRight => "+",
TableBorderPart.HeaderLeft => "|",
TableBorderPart.HeaderSeparator => "|",
TableBorderPart.HeaderRight => "|",
TableBorderPart.HeaderBottomLeft => "|",
TableBorderPart.HeaderBottom => "-",
TableBorderPart.HeaderBottomSeparator => "+",
TableBorderPart.HeaderBottomRight => "|",
TableBorderPart.CellLeft => "|",
TableBorderPart.CellSeparator => "|",
TableBorderPart.CellRight => "|",
TableBorderPart.FooterBottomLeft => "+",
TableBorderPart.FooterBottom => "-",
TableBorderPart.FooterBottomSeparator => "-",
TableBorderPart.FooterBottomRight => "+",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a border with a double edge.
/// </summary>
public sealed class DoubleEdgeTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "╔",
TableBorderPart.HeaderTop => "═",
TableBorderPart.HeaderTopSeparator => "╤",
TableBorderPart.HeaderTopRight => "╗",
TableBorderPart.HeaderLeft => "║",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => "║",
TableBorderPart.HeaderBottomLeft => "╟",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "┼",
TableBorderPart.HeaderBottomRight => "╢",
TableBorderPart.CellLeft => "║",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => "║",
TableBorderPart.FooterBottomLeft => "╚",
TableBorderPart.FooterBottom => "═",
TableBorderPart.FooterBottomSeparator => "╧",
TableBorderPart.FooterBottomRight => "╝",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a double border.
/// </summary>
public sealed class DoubleTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "╔",
TableBorderPart.HeaderTop => "═",
TableBorderPart.HeaderTopSeparator => "╦",
TableBorderPart.HeaderTopRight => "╗",
TableBorderPart.HeaderLeft => "║",
TableBorderPart.HeaderSeparator => "║",
TableBorderPart.HeaderRight => "║",
TableBorderPart.HeaderBottomLeft => "╠",
TableBorderPart.HeaderBottom => "═",
TableBorderPart.HeaderBottomSeparator => "╬",
TableBorderPart.HeaderBottomRight => "╣",
TableBorderPart.CellLeft => "║",
TableBorderPart.CellSeparator => "║",
TableBorderPart.CellRight => "║",
TableBorderPart.FooterBottomLeft => "╚",
TableBorderPart.FooterBottom => "═",
TableBorderPart.FooterBottomSeparator => "╩",
TableBorderPart.FooterBottomRight => "╝",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a border with a heavy edge.
/// </summary>
public sealed class HeavyEdgeTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "┏",
TableBorderPart.HeaderTop => "━",
TableBorderPart.HeaderTopSeparator => "┯",
TableBorderPart.HeaderTopRight => "┓",
TableBorderPart.HeaderLeft => "┃",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => "┃",
TableBorderPart.HeaderBottomLeft => "┠",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "┼",
TableBorderPart.HeaderBottomRight => "┨",
TableBorderPart.CellLeft => "┃",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => "┃",
TableBorderPart.FooterBottomLeft => "┗",
TableBorderPart.FooterBottom => "━",
TableBorderPart.FooterBottomSeparator => "┷",
TableBorderPart.FooterBottomRight => "┛",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a border with a heavy header.
/// </summary>
public sealed class HeavyHeadTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "┏",
TableBorderPart.HeaderTop => "━",
TableBorderPart.HeaderTopSeparator => "┳",
TableBorderPart.HeaderTopRight => "┓",
TableBorderPart.HeaderLeft => "┃",
TableBorderPart.HeaderSeparator => "┃",
TableBorderPart.HeaderRight => "┃",
TableBorderPart.HeaderBottomLeft => "┡",
TableBorderPart.HeaderBottom => "━",
TableBorderPart.HeaderBottomSeparator => "╇",
TableBorderPart.HeaderBottomRight => "┩",
TableBorderPart.CellLeft => "│",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => "│",
TableBorderPart.FooterBottomLeft => "└",
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "┴",
TableBorderPart.FooterBottomRight => "┘",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a heavy border.
/// </summary>
public sealed class HeavyTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "┏",
TableBorderPart.HeaderTop => "━",
TableBorderPart.HeaderTopSeparator => "┳",
TableBorderPart.HeaderTopRight => "┓",
TableBorderPart.HeaderLeft => "┃",
TableBorderPart.HeaderSeparator => "┃",
TableBorderPart.HeaderRight => "┃",
TableBorderPart.HeaderBottomLeft => "┣",
TableBorderPart.HeaderBottom => "━",
TableBorderPart.HeaderBottomSeparator => "╋",
TableBorderPart.HeaderBottomRight => "┫",
TableBorderPart.CellLeft => "┃",
TableBorderPart.CellSeparator => "┃",
TableBorderPart.CellRight => "┃",
TableBorderPart.FooterBottomLeft => "┗",
TableBorderPart.FooterBottom => "━",
TableBorderPart.FooterBottomSeparator => "┻",
TableBorderPart.FooterBottomRight => "┛",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a horizontal border.
/// </summary>
public sealed class HorizontalTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "─",
TableBorderPart.HeaderTop => "─",
TableBorderPart.HeaderTopSeparator => "─",
TableBorderPart.HeaderTopRight => "─",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => " ",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => "─",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "─",
TableBorderPart.HeaderBottomRight => "─",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => " ",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => "─",
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "─",
TableBorderPart.FooterBottomRight => "─",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Text;
using Spectre.Console.Internal;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a Markdown border.
/// </summary>
public sealed class MarkdownTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => "|",
TableBorderPart.HeaderSeparator => "|",
TableBorderPart.HeaderRight => "|",
TableBorderPart.HeaderBottomLeft => "|",
TableBorderPart.HeaderBottom => "-",
TableBorderPart.HeaderBottomSeparator => "|",
TableBorderPart.HeaderBottomRight => "|",
TableBorderPart.CellLeft => "|",
TableBorderPart.CellSeparator => "|",
TableBorderPart.CellRight => "|",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
/// <inheritdoc/>
public override string GetColumnRow(TablePart part, IReadOnlyList<int> widths, IReadOnlyList<IColumn> columns)
{
if (part != TablePart.Separator)
{
return base.GetColumnRow(part, widths, columns);
}
var (left, center, separator, right) = GetTableParts(part);
var builder = new StringBuilder();
builder.Append(left);
foreach (var (columnIndex, _, lastColumn, columnWidth) in widths.Enumerate())
{
var padding = columns[columnIndex].Padding;
if (padding.Left > 0)
{
// Left padding
builder.Append(" ".Multiply(padding.Left));
}
var justification = columns[columnIndex].Alignment;
if (justification == null)
{
// No alignment
builder.Append(center.Multiply(columnWidth));
}
else if (justification.Value == Justify.Left)
{
// Left
builder.Append(':');
builder.Append(center.Multiply(columnWidth - 1));
}
else if (justification.Value == Justify.Center)
{
// Centered
builder.Append(':');
builder.Append(center.Multiply(columnWidth - 2));
builder.Append(':');
}
else if (justification.Value == Justify.Right)
{
// Right
builder.Append(center.Multiply(columnWidth - 1));
builder.Append(':');
}
// Right padding
if (padding.Right > 0)
{
builder.Append(" ".Multiply(padding.Right));
}
if (!lastColumn)
{
builder.Append(separator);
}
}
builder.Append(right);
return builder.ToString();
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a minimal border with a double header border.
/// </summary>
public sealed class MinimalDoubleHeadTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => " ",
TableBorderPart.HeaderBottom => "═",
TableBorderPart.HeaderBottomSeparator => "╪",
TableBorderPart.HeaderBottomRight => " ",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a minimal border with a heavy header.
/// </summary>
public sealed class MinimalHeavyHeadTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Minimal;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => " ",
TableBorderPart.HeaderBottom => "━",
TableBorderPart.HeaderBottomSeparator => "┿",
TableBorderPart.HeaderBottomRight => " ",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a minimal border.
/// </summary>
public sealed class MinimalTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => " ",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "┼",
TableBorderPart.HeaderBottomRight => " ",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,17 @@
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents an invisible border.
/// </summary>
public sealed class NoTableBorder : TableBorder
{
/// <inheritdoc/>
public override bool Visible => false;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return " ";
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a rounded border.
/// </summary>
public sealed class RoundedTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Square;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "╭",
TableBorderPart.HeaderTop => "─",
TableBorderPart.HeaderTopSeparator => "┬",
TableBorderPart.HeaderTopRight => "╮",
TableBorderPart.HeaderLeft => "│",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => "│",
TableBorderPart.HeaderBottomLeft => "├",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "┼",
TableBorderPart.HeaderBottomRight => "┤",
TableBorderPart.CellLeft => "│",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => "│",
TableBorderPart.FooterBottomLeft => "╰",
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "┴",
TableBorderPart.FooterBottomRight => "╯",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a simple border with heavy lines.
/// </summary>
public sealed class SimpleHeavyTableBorder : TableBorder
{
/// <inheritdoc/>
public override TableBorder? SafeBorder => TableBorder.Simple;
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => " ",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => "━",
TableBorderPart.HeaderBottom => "━",
TableBorderPart.HeaderBottomSeparator => "━",
TableBorderPart.HeaderBottomRight => "━",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => " ",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a simple border.
/// </summary>
public sealed class SimpleTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => " ",
TableBorderPart.HeaderTop => " ",
TableBorderPart.HeaderTopSeparator => " ",
TableBorderPart.HeaderTopRight => " ",
TableBorderPart.HeaderLeft => " ",
TableBorderPart.HeaderSeparator => " ",
TableBorderPart.HeaderRight => " ",
TableBorderPart.HeaderBottomLeft => "─",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "─",
TableBorderPart.HeaderBottomRight => "─",
TableBorderPart.CellLeft => " ",
TableBorderPart.CellSeparator => " ",
TableBorderPart.CellRight => " ",
TableBorderPart.FooterBottomLeft => " ",
TableBorderPart.FooterBottom => " ",
TableBorderPart.FooterBottomSeparator => " ",
TableBorderPart.FooterBottomRight => " ",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents a square border.
/// </summary>
public sealed class SquareTableBorder : TableBorder
{
/// <inheritdoc/>
protected override string GetBorderPart(TableBorderPart part)
{
return part switch
{
TableBorderPart.HeaderTopLeft => "┌",
TableBorderPart.HeaderTop => "─",
TableBorderPart.HeaderTopSeparator => "┬",
TableBorderPart.HeaderTopRight => "┐",
TableBorderPart.HeaderLeft => "│",
TableBorderPart.HeaderSeparator => "│",
TableBorderPart.HeaderRight => "│",
TableBorderPart.HeaderBottomLeft => "├",
TableBorderPart.HeaderBottom => "─",
TableBorderPart.HeaderBottomSeparator => "┼",
TableBorderPart.HeaderBottomRight => "┤",
TableBorderPart.CellLeft => "│",
TableBorderPart.CellSeparator => "│",
TableBorderPart.CellRight => "│",
TableBorderPart.FooterBottomLeft => "└",
TableBorderPart.FooterBottom => "─",
TableBorderPart.FooterBottomSeparator => "┴",
TableBorderPart.FooterBottomRight => "┘",
_ => throw new InvalidOperationException("Unknown border part."),
};
}
}
}

View File

@ -0,0 +1,23 @@
namespace Spectre.Console.Rendering
{
/// <summary>
/// Represents different parts of a table.
/// </summary>
public enum TablePart
{
/// <summary>
/// The top of a table.
/// </summary>
Top,
/// <summary>
/// The separator between the header and the cells.
/// </summary>
Separator,
/// <summary>
/// The bottom of a table.
/// </summary>
Bottom,
}
}