mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
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:

committed by
Patrik Svensson

parent
697273917e
commit
93ec7401c8
48
src/Spectre.Console/Rendering/Borders/BoxBorderPart.cs
Normal file
48
src/Spectre.Console/Rendering/Borders/BoxBorderPart.cs
Normal 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,
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
14
src/Spectre.Console/Rendering/Borders/Boxes/NoBoxBorder.cs
Normal file
14
src/Spectre.Console/Rendering/Borders/Boxes/NoBoxBorder.cs
Normal 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 " ";
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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 " ";
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -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."),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
23
src/Spectre.Console/Rendering/TablePart.cs
Normal file
23
src/Spectre.Console/Rendering/TablePart.cs
Normal 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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user