https://github.com/xavierjefferson/snork.asciitable
https://github.com/xavierjefferson/snork.asciitable
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/xavierjefferson/snork.asciitable
- Owner: xavierjefferson
- License: gpl-3.0
- Created: 2022-09-18T04:16:25.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-06T22:39:23.000Z (over 2 years ago)
- Last Synced: 2025-03-14T01:47:38.927Z (2 months ago)
- Language: C#
- Size: 1.27 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Ascii Table Generator
This library generates tables in Ascii from raw data, enumerables, and instances of System.Data.DataTable. Within cells, it has text wrapping capability based on this author's [Snork.TextWrap](https://github.com/xavierjefferson/Snork.TextWrap) library.
[](https://www.nuget.org/packages/Snork.AsciiTable/)
## Table of Contents
- [Example 1 - Populate table in code](#example-1)
- [Example 2 - Populate table from enumerable](#example-2)
- [API](#api)### Example 1 - Populate table in code
var table = new AsciiTableGenerator("A Title");
table.SetHeading("", "Name", "Age");
table.Add(1, "Bob", 52).Add(2, "John", 34).Add(3, "Jim", 83);
Console.Write(table.ToString());### Example 1 output:
.----------------.
| A Title |
|----------------|
| | Name | Age |
|---|------|-----|
| 1 | Bob | 52 |
| 2 | John | 34 |
| 3 | Jim | 83 |
'----------------'### Example 2 - Populate table from enumerable
class MyClass {
public string Column1 { get; set; }
public string Column2 { get; set; }
}
var items = new List
{
new MyClass { Column1 = "Bozo", Column2 = "TheClown" },
new MyClass { Column1 = "Popeye", Column2 = "TheSailor" }
};
var table = AsciiTableGenerator.FromEnumerable(items);
Console.Write(table.ToString());### Example 2 Output:
.---------------------.
| Column1 | Column2 |
|---------|-----------|
| Bozo | TheClown |
| Popeye | TheSailor |
'---------------------'## API
```csharp
public class Snork.AsciiTable.AsciiTableGenerator```
Properties
| Type | Name | Summary |
| --- | --- | --- |
| `Options` | Options | |Methods
| Return Type | Name | Summary |
| --- | --- | --- |
| `AsciiTableGenerator` | Add(`IEnumerable` row) | Add a row of data |
| `AsciiTableGenerator` | Add(`Object[]` row) | Add a row of data |
| `AsciiTableGenerator` | AddRange(`IEnumerable>` rows) | Add a range of rows |
| `AsciiTableGenerator` | Clear() | Clear current table data and reset settings to defaults |
| `AsciiTableGenerator` | ClearRows() | Clear current table data |
| `AsciiTableGenerator` | DisplayBorder(`Boolean` value) | Setting for whether or not to display the border around the cells |
| `AsciiTableGenerator` | DisplayRowSeparators(`Boolean` value) | Display row separators between each row of data, for improved visibility |
| `List` | GetCaptions() | Get list of captions for all columns |
| `List>` | GetRows() | Get current table data as list of list |
| `String` | GetTitle() | Get the current title |
| `AsciiTableGenerator` | SetBorder(`Nullable` horizontalEdge = null, `Nullable` verticalEdge = null, `Nullable` topCorner = null, `Nullable` bottomCorner = null) | Set the border characters for rendering, if no arguments are passed it will be reset to defaults. If a single edge arg is passed, it will be used for all borders. |
| `AsciiTableGenerator` | SetCaptionAlignment(`Int32` index, `CellAlignmentEnum` alignment) | Set the alignment of caption for a given column |
| `AsciiTableGenerator` | SetCaptions(`List` captions) | Set captions for all columns |
| `AsciiTableGenerator` | SetCaptions(`String[]` captions) | Set captions for all columns |
| `AsciiTableGenerator` | SetCellAlignment(`Int32` index, `CellAlignmentEnum` cellAlignment) | Set alignment for cells in a given column |
| `AsciiTableGenerator` | SetColumnWidth(`Int32` index, `ColumnWidthTypeEnum` columnWidthType, `Nullable` width = null) | Set width for a given column, by index. ColumnWidthType can be Fixed or Auto |
| `AsciiTableGenerator` | SetDisplayCaptions(`Boolean` value) | Setting for whether captions are displayed or not |
| `AsciiTableGenerator` | SetTextWrapperOptions(`Int32` index, `Action` action) | Set text wrapping options for a particular column with options from [Snork.TextWrap library] (https://github.com/xavierjefferson/Snork.TextWrap) |
| `AsciiTableGenerator` | SetTitle(`String` name) | Set title for the table. Will be rendered in single cell that spans all columns |
| `AsciiTableGenerator` | SetTitleAlignment(`CellAlignmentEnum` alignment) | Set alignment for title cell |
| `String` | ToString() | Render the table |Static Methods
| Return Type | Name | Summary |
| --- | --- | --- |
| `AsciiTableGenerator` | FromDataTable(`DataTable` table, `Options` options = null, `Boolean` autoCaptions = True) | Create an AsciiTableGenerator instance with a datatable as its source |
| `AsciiTableGenerator` | FromEnumerable(`IEnumerable` data, `Options` options = null, `Boolean` autoCaptions = True) | Create an AsciiTableGenerator instance with an enumerable of some type as its source |## `CellAlignmentEnum`
```csharp
public enum Snork.AsciiTable.CellAlignmentEnum
: Enum, IComparable, IFormattable, IConvertible```
Enum
| Value | Name | Summary |
| --- | --- | --- |
| `0` | NotSpecified | |
| `1` | Left | |
| `2` | Right | |
| `3` | Center | |## `ColumnWidthTypeEnum`
```csharp
public enum Snork.AsciiTable.ColumnWidthTypeEnum
: Enum, IComparable, IFormattable, IConvertible```
Enum
| Value | Name | Summary |
| --- | --- | --- |
| `0` | Auto | |
| `1` | Fixed | |## `Options`
```csharp
public class Snork.AsciiTable.Options```
Properties
| Type | Name | Summary |
| --- | --- | --- |
| `Char` | BottomCorner | |
| `CellAlignmentEnum` | CaptionCellAlignment | Cell alignment for captions |
| `Boolean` | DisplayBorder | Show border around table |
| `Boolean` | DisplayCaptions | Show captions with a row separator |
| `Boolean` | DisplayRowSeparators | Add row separators between each row of data |
| `Char` | HorizontalEdge | |
| `String` | LinePrefix | Prefix to add to each line on render |
| `String` | Title | Table title. Defaults to null |
| `CellAlignmentEnum` | TitleCellAlignment | Cell alignment for title, if set |
| `Char` | TopCorner | |
| `Char` | VerticalEdge | |