All Projects → PhilippHochmann → ctable

PhilippHochmann / ctable

Licence: GPL-3.0 License
C library to print nicely formatted tables

Programming Languages

c
50402 projects - #5 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to ctable

Terminaltables
Generate simple tables in terminals from a nested list of strings.
Stars: ✭ 685 (+5169.23%)
Mutual labels:  console, ascii, table
Libfort
C/C++ library to create formatted ASCII tables for console applications
Stars: ✭ 255 (+1861.54%)
Mutual labels:  console, ascii, table
Ascii canvas
ASCII canvas for drawing in console
Stars: ✭ 11 (-15.38%)
Mutual labels:  console, ascii
Video To Ascii
It is a simple python package to play videos in the terminal using characters as pixels
Stars: ✭ 960 (+7284.62%)
Mutual labels:  console, ascii
Ervy
Bring charts to terminal.
Stars: ✭ 1,530 (+11669.23%)
Mutual labels:  console, ascii
Csconsoleformat
.NET C# library for advanced formatting of console output [Apache]
Stars: ✭ 296 (+2176.92%)
Mutual labels:  console, ascii
Sadconsole
A .NET ascii/ansi console engine written in C# for MonoGame and XNA. Create your own text roguelike (or other) games!
Stars: ✭ 853 (+6461.54%)
Mutual labels:  console, ascii
Asciichart
Nice-looking lightweight console ASCII line charts ╭┈╯ for NodeJS, browsers and terminal, no dependencies
Stars: ✭ 1,107 (+8415.38%)
Mutual labels:  console, ascii
Go Pretty
Pretty print tables and more in golang!
Stars: ✭ 777 (+5876.92%)
Mutual labels:  ascii, table
Tcharts.js
📉 Lightweight and fast terminal ASCII charts for nodejs and browser.
Stars: ✭ 172 (+1223.08%)
Mutual labels:  console, ascii
Criterion
Microbenchmarking for Modern C++
Stars: ✭ 140 (+976.92%)
Mutual labels:  console, table
termtable
Simple and highly customizable library to display tables in the terminal.
Stars: ✭ 41 (+215.38%)
Mutual labels:  ascii, table
ascii chart
Nice-looking lightweight console ASCII line charts ╭┈╯. Port of kroitor/asciichart.
Stars: ✭ 24 (+84.62%)
Mutual labels:  console, ascii
Markdown Table
Markdown tables, with alignment
Stars: ✭ 164 (+1161.54%)
Mutual labels:  ascii, table
table
Produces a string that represents slice data in a text table, inspired by gajus/table.
Stars: ✭ 130 (+900%)
Mutual labels:  ascii, table
Lenz
Console based MAP 🗺 : with lots of features 🤩
Stars: ✭ 51 (+292.31%)
Mutual labels:  console, ascii
Simpletable
Simple tables in terminal with Go
Stars: ✭ 288 (+2115.38%)
Mutual labels:  ascii, table
Ascii Tables
Quickly format table in ASCII. Great for code comments, or Github Markdown!
Stars: ✭ 416 (+3100%)
Mutual labels:  ascii, table
Console.table
Adds console.table method that prints an array of objects as a table in console
Stars: ✭ 125 (+861.54%)
Mutual labels:  console, table
outfancy
Python3 library to print tables in Terminal.
Stars: ✭ 47 (+261.54%)
Mutual labels:  ascii, table

build License: GPL v3

To do

  • Write documentation
  • More assertions and checks (bad calls should not lead to segfaults)
  • Remove MAX_COLS restriction (currently 11)

ctable

Library to print nicely formatted tables to stdout. Supports...

  • Cells spanning over multiple columns or rows
  • ANSI color sequences
  • Newlines in cell content
  • Alignment of numbers under decimal dot

Currently not supported...

  • wchars
  • Special chars like \t

How to use it

Include src/table.h to use it. Invoke make to run tests.

First, get a new table with get_empty_table(). Its current column and current row are set to 0. Cell insertions into the table always occur at the current column and current row. After a cell insertion, the current column advances. When styling a cell, call a setting-changing function before the cell insertion.

Example

Generated by running the tests:
Example Image
Generated by running the tests of ccalc:
Example Image

Functions

Data and printing

The following functions are used to obtain a new table, print it, and free it after use.

Table get_empty_table()

Returns a new table without any lines or set cells. All cells are styled to be left-aligned. Insertion begins at the upper left corner. You don't need to look into a Table directly, it suffices to use the following functions to manipulate it.

void print_table(Table *table)

Prints a table to stdout. This function is equivalent to fprint_table(table, stdout).

void fprint_table(Table *table, FILE *stream)

Prints a table to a specified stream.

void free_table(Table *table)

Frees all dynamic memory allocated for this table. It may not be used any more.

Control

The following functions change the position of next cell insertion.

void set_position(Table *table, size_t x, size_t y)

Sets position of next cell insertion. x = 0 is leftmost column, y = 0 is first row. Passing a large value for y may malloc a lot of rows, so use with care!

void next_row(Table *table)

Sets position of next cell insertion to the first column of next row relative to current insertion position.

Cell insertion

These functions insert a cell at the current position and advances the position to the next column (in the same row). When MAX_COLS many cells have been inserted into a row, next_row needs to be called. An inserted cell can not be changed any more.

void add_empty_cell(Table *table)

Adds an empty cell without any content.

void add_cell(Table *table, char *text)

Adds a cell with a specified text. You have to ensure that the passed pointer is still valid when the table is printed. If you don't want to maintain the buffer yourself, use add_cell_fmt.

void add_cell_gc(Table *table, char *text)

The same as add_cell, but frees the passed pointer on free_table, so use with care!

void add_cell_fmt(Table *table, char *fmt, ...)

Adds a cell with a text specified as if printed by printf. Buffer allocation and cleanup will be taken care of.

void add_cell_vfmt(Table *table, char *fmt, va_list args)

Flavor of add_cell_fmt that allows for va_lists, e.g. for a wrapper function.

void add_cells_from_array(Table *table, size_t width, size_t height, char **array)

Adds multiple cells with contents specified by a memory-contiguous 2D-Array. Insertion begins at current position, next position of insertion will be right to set cells in the same row. Strings will not be copied, so take care that pointers within the array are valid when the table is printed!

Cell styling

These functions style the cell that is added by next insertion (in the following called current cell). Already set cells can not be styled any more.

BorderStyle Description
BORDER_SINGLE A single line
BORDER_DOUBLE A double line
BORDER_NONE No line, useful for removing a line for a specific cell
TextAlignment Description
ALIGN_LEFT left-aligned
ALIGN_RIGHT right-aligned
ALIGN_CENTER centered (rounded to the left)
ALIGN_NUMBERS aligned under decimal dot and padding zeros

void set_default_alignments(Table *table, size_t num_alignments, TextAlignment *alignments)

Sets the default text alignment for each column.

void override_alignment(Table *table, TextAlignment alignment)

Overrides text alignment for current cell.

void override_alignment_of_row(Table *table, TextAlignment alignment)

Overrides text alignment for all cells of current row.

void set_hline(Table *table, BorderStyle style)

Inserts a horizontal line above the current row.

void set_vline(Table *table, size_t index, BorderStyle style)

Inserts a vertical line left to current column,

void make_boxed(Table *table, BorderStyle style)

Encloses the table in its current state by a box. Make sure to call next_row after last row to include it in box.

void set_all_vlines(Table *table, BorderStyle style)

Inserts vertical lines between all currently non-empty columns.

void override_left_border(Table *table, BorderStyle style)

Sets the left border of the current cell independently of default value for current column.

void override_above_border(Table *table, BorderStyle style)

Sets the above border for the current cell independently of default value for current row.

void set_span(Table *table, size_t span_x, size_t span_y)

Sets span for current cell. span_x denotes the number of columns to span over, span_y denotes the number of rows to span over.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].