diff --git a/src/ConsoleTables.Sample/Program.cs b/src/ConsoleTables.Sample/Program.cs index 07205c5..f614e4f 100644 --- a/src/ConsoleTables.Sample/Program.cs +++ b/src/ConsoleTables.Sample/Program.cs @@ -2,94 +2,72 @@ using System.Collections.Generic; using System.Linq; -namespace ConsoleTables.Sample; - -static class Program +namespace ConsoleTables.Sample { - static void TestDictionaryTable() + static class Program { - Dictionary> data = new Dictionary>() + static void Main(string[] args) { - {"A", new Dictionary() - { - { "A", true }, - { "B", false }, - { "C", true }, - }}, - {"B", new Dictionary() - { - { "A", false }, - { "B", true }, - { "C", false }, - }}, - {"C", new Dictionary() - { - { "A", false }, - { "B", false }, - { "C", true }, - }} - }; - var table = ConsoleTable.FromDictionary(data); + TestDictionaryTable(); + SetupAndWriteTables(); + ConfigureAlignment(); + WriteTableWithoutCount(); - Console.WriteLine(table.ToString()); - } - - static void Main(string[] args) - { - TestDictionaryTable(); - var table = new ConsoleTable("one", "two", "three"); - table.AddRow(1, 2, 3) - .AddRow("this line should be longer 哈哈哈哈", "yes it is", "oh"); + Console.ReadKey(); + } - Console.WriteLine("\nFORMAT: Default:\n"); - table.Write(); - - Console.WriteLine("\nFORMAT: MarkDown:\n"); - table.Write(Format.MarkDown); - - Console.WriteLine("\nFORMAT: Alternative:\n"); - table.Write(Format.Alternative); - Console.WriteLine(); - - Console.WriteLine("\nFORMAT: Minimal:\n"); - table.Write(Format.Minimal); - Console.WriteLine(); - - table = new ConsoleTable("I've", "got", "nothing"); - table.Write(); - Console.WriteLine(); + static void TestDictionaryTable() + { + var data = new List + { + new TableData("A", new Dictionary { { "A", true }, { "B", false }, { "C", true } }), + new TableData("B", new Dictionary { { "A", false }, { "B", true }, { "C", false } }), + new TableData("C", new Dictionary { { "A", false }, { "B", false }, { "C", true } }) + }; - var rows = Enumerable.Repeat(new Something(), 10); + var dictionary = data.ToDictionary(d => d.Key, d => d.Values); + var table = ConsoleTable.FromDictionary(dictionary); + Console.WriteLine(table.ToString()); + } - ConsoleTable.From(rows).Write(); + static void SetupAndWriteTables() + { + var table = new ConsoleTable("one", "two", "three"); + table.AddRow(1, 2, 3) + .AddRow("this line should be longer 哈哈哈哈", "yes it is", "oh"); - rows = Enumerable.Repeat(new Something(), 0); - ConsoleTable.From(rows).Write(); + table.Write(); + } - Console.WriteLine("\nNumberAlignment = Alignment.Right\n"); - rows = Enumerable.Repeat(new Something(), 2); - ConsoleTable - .From(rows) - .Configure(o => o.NumberAlignment = Alignment.Right) - .Write(); + static void ConfigureAlignment() + { + var rows = Enumerable.Repeat(new Something(), 2); + ConsoleTable.From(rows) + .Configure(o => o.NumberAlignment = Alignment.Right) + .Write(); + } - var noCount = - new ConsoleTable(new ConsoleTableOptions + static void WriteTableWithoutCount() + { + var noCount = new ConsoleTable(new ConsoleTableOptions { Columns = new[] { "one", "two", "three" }, EnableCount = false }); - noCount.AddRow(1, 2, 3).Write(); + noCount.AddRow(1, 2, 3).Write(); + } + } + + public class Something + { + public string Id { get; } = Guid.NewGuid().ToString("N"); + public string Name { get; private set; } = "Khalid Abuhkameh"; + public DateTime Date { get; } - Console.ReadKey(); + public Something() + { + Date = DateTime.UtcNow; + } } } - -public class Something -{ - public string Id { get; set; } = Guid.NewGuid().ToString("N"); - public string Name { get; set; } = "Khalid Abuhkameh"; - public DateTime Date { get; set; } = DateTime.Now; - public int NumberOfChildren { get; set; } -} \ No newline at end of file