Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 51 additions & 73 deletions src/ConsoleTables.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Dictionary<string, object>> data = new Dictionary<string, Dictionary<string, object>>()
static void Main(string[] args)
{
{"A", new Dictionary<string, object>()
{
{ "A", true },
{ "B", false },
{ "C", true },
}},
{"B", new Dictionary<string, object>()
{
{ "A", false },
{ "B", true },
{ "C", false },
}},
{"C", new Dictionary<string, object>()
{
{ "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<TableData>
{
new TableData("A", new Dictionary<string, object> { { "A", true }, { "B", false }, { "C", true } }),
new TableData("B", new Dictionary<string, object> { { "A", false }, { "B", true }, { "C", false } }),
new TableData("C", new Dictionary<string, object> { { "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; }
}