khalidabuhakmeh / ConsoleTables

Print out a nicely formatted table in a console application C#
MIT License
944 stars 158 forks source link

New table formats: Markdown comaptible and Alternative #9

Closed nikitaignatov closed 8 years ago

nikitaignatov commented 8 years ago

I needed a slightly different format, so added ability to choose default, markdown and alternative. The markdown can be used with github readme files like this:

Id Name Date
72c0f4cc73eb4fd3b2b4a6896d020e66 Khalid Abuhkameh 17-04-2016 23:21:38
72c0f4cc73eb4fd3b2b4a6896d020e66 Khalid Abuhkameh 17-04-2016 23:21:38
72c0f4cc73eb4fd3b2b4a6896d020e66 Khalid Abuhkameh 17-04-2016 23:21:38

Usage of the new format:

Console.WriteLine("\nFORMAT: Default:\n");
ConsoleTable.From<Something>(rows).Write();

Console.WriteLine("\nFORMAT: MarkDown:\n");
ConsoleTable.From<Something>(rows).Write(Format.MarkDown);

Console.WriteLine("\nFORMAT: Alternative:\n");
ConsoleTable.From<Something>(rows).Write(Format.Alternative);

Examples of the output:

FORMAT: Default:

 -----------------------------------------------------------------------------
 | Id                               | Name             | Date                |
 -----------------------------------------------------------------------------
 | 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
 -----------------------------------------------------------------------------
 | 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
 -----------------------------------------------------------------------------
 | 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
 -----------------------------------------------------------------------------
 | 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
 -----------------------------------------------------------------------------
 | 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
 -----------------------------------------------------------------------------

 Count: 10

FORMAT: MarkDown:

| Id                               | Name             | Date                |
|----------------------------------|------------------|---------------------|
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |

FORMAT: Alternative:

+----------------------------------+------------------+---------------------+
| Id                               | Name             | Date                |
+----------------------------------+------------------+---------------------+
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
+----------------------------------+------------------+---------------------+
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
+----------------------------------+------------------+---------------------+
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
+----------------------------------+------------------+---------------------+
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
+----------------------------------+------------------+---------------------+
| 72c0f4cc73eb4fd3b2b4a6896d020e66 | Khalid Abuhkameh | 17-04-2016 23:21:38 |
+----------------------------------+------------------+---------------------+