using System; using System.Collections.Generic; using System.Linq; using DiscordBotCore.Others; using Spectre.Console; using Spectre.Console.Rendering; namespace DiscordBot.Utilities { public class TableData { public List Columns; public List[]> Rows; public TableData() { Columns = new List(); Rows = new List[]>(); } public TableData(List columns) { Columns = columns; Rows = new List[]>(); } public bool IsEmpty => Rows.Count == 0; public bool HasRoundBorders { get; set; } = true; public bool DisplayLinesBetweenRows { get; set; } = false; public void AddRow(OneOf[] row) { Rows.Add(row); } public Table AsTable() { var table = new Table(); table.Border(this.HasRoundBorders ? TableBorder.Rounded : TableBorder.Square); table.AddColumns(this.Columns.ToArray()); table.ShowRowSeparators = DisplayLinesBetweenRows; foreach (var row in this.Rows) { table.AddRow(row.Select(element => element.Match( (string data) => new Markup(data), (IRenderable data) => data ))); } table.Alignment(Justify.Center); return table; } public void PrintTable() { if (IsEmpty) return; AnsiConsole.Write(this.AsTable()); } } }