solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
prettytable.h File Reference

Generic pretty table printer library for C. More...

#include <stdbool.h>
#include <stdio.h>
Include dependency graph for prettytable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  prettytable_style
 
struct  prettytable_config
 

Typedefs

typedef const char *(* prettytable_header_fn) (void *user_data, int col)
 
typedef const char *(* prettytable_cell_fn) (void *user_data, int row, int col)
 
typedef int(* prettytable_strlen_fn) (void *user_data, const char *text)
 

Functions

int prettytable_print (const prettytable_config *config)
 
void prettytable_config_init (prettytable_config *config)
 

Variables

const prettytable_style PRETTYTABLE_STYLE_BOX
 

Detailed Description

Generic pretty table printer library for C.

A fast, minimal library for printing formatted tables with box-drawing characters. Uses callback functions to support any data source.

Example usage:

const char* get_cell(void* data, int row, int col) { MyData* d = (MyData*)data; return d->cells[row][col]; }

const char* get_header(void* data, int col) { const char* headers[] = {"ID", "Name", "Age"}; return headers[col]; }

prettytable_config cfg = { .num_rows = 3, .num_cols = 3, .get_header = get_header, .get_cell = get_cell, .user_data = &my_data };

prettytable_print(&cfg);

Definition in file prettytable.h.

Typedef Documentation

◆ prettytable_cell_fn

typedef const char *(* prettytable_cell_fn) (void *user_data, int row, int col)

Callback to get cell value.

Parameters
user_dataUser-provided context data
rowRow index (0-based)
colColumn index (0-based)
Returns
Cell text (must not be NULL, use "" for empty)

Definition at line 56 of file prettytable.h.

◆ prettytable_header_fn

typedef const char *(* prettytable_header_fn) (void *user_data, int col)

Callback to get header text for a column.

Parameters
user_dataUser-provided context data
colColumn index (0-based)
Returns
Header text (must not be NULL, use "" for empty)

Definition at line 47 of file prettytable.h.

◆ prettytable_strlen_fn

typedef int(* prettytable_strlen_fn) (void *user_data, const char *text)

Optional callback to get custom cell length (for wide chars, etc.) If NULL, strlen() is used.

Parameters
user_dataUser-provided context data
textCell text
Returns
Display width of the text

Definition at line 65 of file prettytable.h.

Function Documentation

◆ prettytable_config_init()

void prettytable_config_init ( prettytable_config config)

Initialize config with default values.

Parameters
configConfig to initialize

Definition at line 68 of file prettytable.c.

References PRETTYTABLE_STYLE_BOX.

◆ prettytable_print()

int prettytable_print ( const prettytable_config config)

Print a formatted table.

Parameters
configTable configuration
Returns
0 on success, -1 on error

Definition at line 158 of file prettytable.c.

References PRETTYTABLE_STYLE_BOX.

Variable Documentation

◆ PRETTYTABLE_STYLE_BOX

const prettytable_style PRETTYTABLE_STYLE_BOX
extern

Predefined border styles.

Definition at line 12 of file prettytable.c.

Referenced by prettytable_config_init(), and prettytable_print().