Skip to content

MaximilianMcC/ascii-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ascii-table

Library thing to make an ascii table in the terminal.

Features:

  • Can be drawn at any x position
  • Can have any width
  • Constructor for making it centered
  • Overflowing information is trimmed
  • Easy as to use

Documentation

A basic table is generated by providing headings, populating it, then ending it. The whole thing works off of string arrays.

AsciiTable table = new AsciiTable("First name", "Last name", "Favorite color");
table.AddRow("Corey", "Lawson", "Green");
table.AddRow("Christina", "Conner", "Yellow");
table.AddRow("Steven", "Bass", "Magenta");
table.AddRow("Mamie", "McCoy", "Orange");
table.End();

Preview of the above code Making the new table object will draw the headers for you, then the table can be populated with AddRow. Using End will draw the bottom of the table, completing it. You can also add data as a string array if thats easier:

AsciiTable table = new AsciiTable(new string[] { "Country", "Capital City" });
table.AddRow(new string[] { "New Zealand", "Wellington"});
table.AddRow(new string[] { "Canada", "Ottawa"});
table.AddRow(new string[] { "United Kingdom", "London"});
table.End();

Preview of the above code

Custom weights

Custom header weights can be supplied. These weights dedicate how much width a header has in the table. By default all headings will be evenly spaced. Here is an example of making a table where the Address takes up the largest amount of space, and the Zip Code and Age takes up the smallest.

AsciiTable table = new AsciiTable(
    new string[] { "Name", "Age", "Address", "Zip code" },
    new int[] { 2, 1, 3, 1 }
);
table.AddRow("Jody", "34", "8226 Davis Streets", "8039");
table.AddRow("Douglas", "27", "63 Sodor Road", "1476");
table.AddRow("Kelvin", "19", "110 Block Bypass", "5284");
table.End();

Preview of the above code

Custom position and width

A custom X position and custom width can be provided. These allow you to draw the table wherever you want, and in in whatever size you would like it. By default the table is drawn in the centre of the screen with a little bit of padding. This will draw a table on the right side of the console that is 45 characters long

AsciiTable table = new AsciiTable(
    new string[] { "Year level", "Average grade" },
    new int[] { 1, 2, },
    Console.WindowWidth / 2,
    45
);
table.AddRow("9", "Merit");
table.AddRow("10", "Achieved");
table.AddRow("11", "Excellence");
table.AddRow("12", "Merit");
table.AddRow("13", "Achieved");
table.End();

Preview of the above code

Planned features

  • Use objects instead of strings
  • Colored data
  • More OOP approach (making reusable tables)
  • Formatted info, for example printing booleans as checkboxes or something
  • Auto/Dynamic weights to make as much info fit
  • Other line styles (pure ascii, thick box drawing, etc)

Feedback

Make an issue on the repo or flick us a message on Discord (@MTMB)

About

Library thing to make an ascii table in the terminal

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages