Giter Club home page Giter Club logo

consoletableext's Introduction

ConsoleTableExt Build status

A library to print out a nicely formatted table in a console application C# rewrite based on khalidabuhakmeh/ConsoleTables

Nuget

Install-Package ConsoleTableExt

Demo

https://github.com/minhhungit/ConsoleTableExt/tree/master/Src/ConsoleTableApp

How to use:

From [DataTable] type and Default format:

ConsoleTableBuilder
   .From(GetSampleTableData())
   .ExportAndWriteLine();

From [DataTable] type and Minimal format:

ConsoleTableBuilder
   .From(GetSampleTableData())
   .WithFormat(ConsoleTableBuilderFormat.Minimal)
   .ExportAndWriteLine();

From [List] type and Alternative format:

ConsoleTableBuilder
   .From(GetSampleListData())
   .WithFormat(ConsoleTableBuilderFormat.Alternative)
   .ExportAndWriteLine();

From [List] type and MarkDown format w/ custom column name:

ConsoleTableBuilder
   .From(GetSampleListData())
   .WithFormat(ConsoleTableBuilderFormat.MarkDown)
   .WithColumn(new List<string>{ "N A M E" , "[Position]", "Office", "<Age>", "Something else I don't care"})
   .ExportAndWriteLine();

Custom:

var arrayBuilder = ConsoleTableBuilder.From(new List<object[]>
{
    new object[] {"luong", "son", "ba", null, "phim", null, null, null, 2, null},
    new object[] {"chuc", "anh", "dai", "nhac", null, null, null }
});


arrayBuilder
   .AddRow(new List<object> {1, "this", "is", "new", "row", "use", "<List>", null, null, null})
   .AddRow(new object[] {"2", "new row", "use", "array[] values", null, null})
   .WithOptions(new ConsoleTableBuilderOption
   {
       MetaRowPosition = MetaRowPosition.Bottom,
       MetaRowFormat = "\n=> This table has {3} rows and {2} columns\n=> [{0}] - [test value {1}]",
       MetaRowParams = new object[]
       {
           "test value 1",
           2,
           AppConstants.MetaRow.COLUMN_COUNT,
           AppConstants.MetaRow.ROW_COUNT 
       },
       TrimColumn = true,
       Delimiter = "¡",
       DividerString = "»",
   })
   .WithFormat(ConsoleTableBuilderFormat.MarkDown)
   .WithColumn(new List<string> {"THIS", "IS", "ADVANCED", "OPTIONS"})
   .ExportAndWriteLine();

Sample data:

static DataTable SampleTableData()
{
   DataTable table = new DataTable();
   table.Columns.Add("Name", typeof(string));
   table.Columns.Add("Position", typeof(string));
   table.Columns.Add("Office", typeof(string));
   table.Columns.Add("Age", typeof(int));
   table.Columns.Add("Start Date", typeof(DateTime));

   table.Rows.Add("Airi Satou", "Accountant", "Tokyo", 33, new DateTime(2017, 05, 09));
   table.Rows.Add("Angelica Ramos", "Chief Executive Officer (CEO)", "New York", 47, new DateTime(2017, 01, 12));
   table.Rows.Add("Ashton Cox", "Junior Technical Author", "London", 46, new DateTime(2017, 04, 02));
   table.Rows.Add("Bradley Greer", "Software Engineer", "San Francisco", 28, new DateTime(2017, 11, 15));

   return table;
}

static List<List<object>> SampleListData = new List<List<object>>
{
   new List<object>{ "Sakura Yamamoto", "Support Engineer", "London", 46},
   new List<object>{ "Serge Baldwin", "Data Coordinator", "San Francisco", 28, "something else" },
   new List<object>{ "Shad Decker", "Regional Director", "Edinburgh"},
};

consoletableext's People

Contributors

minhhungit avatar

Watchers

James Cloos avatar Vlad Vizitu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.