using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices.ComTypes; using System.Text; using System.Threading.Tasks; 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( (data) => new Markup(data), (data) => data ))); } return table; } public void PrintTable() { 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( (data) => new Markup(data), (data) => data ))); } AnsiConsole.Write(table); } } }