BL1NDX3N0N / QuickTables

A library for quickly creating table-formatted text.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QuickTables

A library for quickly creating table-formatted text.

This was one of my first projects as a kid and felt it would be fun to upload here for all to play with and nitpick. Parts of the codebase are poorly designed and am deciding to leave it as such.

Features

  • Creating table formatted text.

Creating a table

Table examples.

Creating customizable tables is fast and easy.

Some of the things you can do with a table inlude:

  • Adding columns.
  • Adding rows.
  • Choosing a header style.
  • Choosing a footer style.
  • Choosing a guide character.

Example #1

Table table = new Table("[Namespace:]", "[Class:]", "[Method:]");

table.Add("Root\\CIMV2", "Win32_Processor", "Name");
table.Add("Root\\CIMV2", "Win32_TemperatureProbe", "CurrentReading");
table.Add("Root\\CIMV2", "Win32_BIOS", "Version");
table.Add("Root\\CIMV2", "Win32_PhysicalMemory", "PositionInRow");
table.Add("Root\\CIMV2", "Win32_PhysicalMemory", "Model");
table.Add("Root\\CIMV2", "Win32_PhysicalMemory", "MaxVoltage");
table.Add("Root\\CIMV2", "Win32_SerialPort", "DeviceID");

// Spacing between columns.
table.ColumnMargin = 2;

// Character to display between cells in a row. Used for added readability.
table.GroupingCharacter = '·';

// Table styling.
table.Header.BorderStyle = HeaderBorderStyle.Column;
table.Footer.BorderStyle = FooterBorderStyle.Dual;
table.Footer.StatsType = FooterStatsType.Advanced;

table.Print();

Example #2

List<string> failedComponents = new List<string>();

// Imagine having a method that returns WMI information but some
// of the paths you try to get a value from don't exist or return null.
// You would add that bad path to this list during runtime. But for right
// now, we will just do it manually for the sake of the example.
failedComponents.Add("Root\\CIMV2 Win32_Processor Name");
failedComponents.Add("Root\\CIMV2 Win32_TemperatureProbe CurrentReading");
failedComponents.Add("Root\\CIMV2 Win32_BIOS Version");
failedComponents.Add("Root\\CIMV2 Win32_PhysicalMemory PositionInRow");
failedComponents.Add("Root\\CIMV2 Win32_PhysicalMemory Model");
failedComponents.Add("Root\\CIMV2 Win32_PhysicalMemory MaxVoltage");
failedComponents.Add("Root\\CIMV2 Win32_SerialPort DeviceID");

Table table = new Table("[Namespace:]", "[Class:]", "[Method:]");

for (int i = 0; i < failedComponents.Count(); i++)
{
    table.Add(failedComponents[i].Split(' ').ToArray());
}

// Spacing between columns.
table.ColumnMargin = 2;

// Character to display between cells in a row. Used for added readability.
table.GroupingCharacter = '·';

// Table styling.
table.Header.BorderStyle = HeaderBorderStyle.Column;
table.Footer.BorderStyle = FooterBorderStyle.Dual;
table.Footer.StatsType = FooterStatsType.Advanced;

Console.WriteLine(table.ToString());

Output for examples #1 & #2

[Namespace:]  [Class:]                [Method:]
────────────  ──────────────────────  ──────────────
Root\CIMV2····Win32_Processor·········Name
Root\CIMV2····Win32_TemperatureProbe··CurrentReading
Root\CIMV2····Win32_BIOS··············Version
Root\CIMV2····Win32_PhysicalMemory····PositionInRow
Root\CIMV2····Win32_PhysicalMemory····Model
Root\CIMV2····Win32_PhysicalMemory····MaxVoltage
Root\CIMV2····Win32_SerialPort········DeviceID
────────────────────────────────────────────────────
Showing [7] entries in [0 ms].
────────────────────────────────────────────────────

About

A library for quickly creating table-formatted text.

License:MIT License


Languages

Language:C# 100.0%