Tables

Automated table rendering with Unicode support and custom styling

Overview
Create beautiful ASCII/Unicode tables for terminal output

The table module provides:

  • Automatic column width calculation
  • Unicode box-drawing characters
  • Header and data row support
  • Custom alignment and padding
  • Colored cells and borders
Basic Table
Create a simple table with headers and rows
Basic Table Example
use zfish::table::Table; // Create table with headers let mut table = Table::new(vec!["Name", "Age", "City"]); // Add data rows table.add_row(vec!["Alice", "25", "New York"]); table.add_row(vec!["Bob", "30", "London"]); table.add_row(vec!["Charlie", "28", "Tokyo"]); // Print the table table.print();
Output
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Name    │ Age │ City     │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Alice   │ 25  │ New York │
│ Bob     │ 30  │ London   │
│ Charlie │ 28  │ Tokyo    │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
Styled Table
Customize table appearance with colors and styles
Styled Table Example
use zfish::table::Table; use zfish::style::Color; // Create table with headers let mut table = Table::new(vec!["Product", "Price", "Stock"]); table.set_box_style(BoxStyle::Double); // Add colored rows table.add_row(&["Laptop", "$999", "In Stock"]); table.add_row(&["Mouse", "$25", "Low Stock"]); table.add_row(&["Keyboard", "$75", "Out of Stock"]); // Set border color table.set_border_color(Color::Blue); table.print();
Output
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Product  │ Price │ Stock        │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Laptop   │ $999  │ In Stock     │
│ Mouse    │ $25   │ Low Stock    │
│ Keyboard │ $75   │ Out of Stock │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
Column Alignment
Align columns left, center, or right
Column Alignment Example
use zfish::table::{Table, Alignment}; // Create table with headers let mut table = Table::new(vec!["Item", "Quantity", "Price"]); // Set column alignments table.set_column_alignment(0, Alignment::Left); table.set_column_alignment(1, Alignment::Center); table.set_column_alignment(2, Alignment::Right); // Add rows table.add_row(vec!["Apple", "10", "$1.50"]); table.add_row(vec!["Banana", "5", "$0.80"]); table.add_row(vec!["Orange", "8", "$1.20"]); table.print();
Output
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Item   │ Quantity │ Price │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ Apple  │    10    │ $1.50 │
│ Banana │     5    │ $0.80 │
│ Orange │     8    │ $1.20 │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
Custom Box Style
Use different box-drawing character sets
ASCII Box Style
use zfish::table::{Table, BoxStyle}; // Create table with headers let mut table = Table::new(vec!["Header 1", "Header 2", "Header 3"]); // Use ASCII style instead of Unicode table.set_box_style(BoxStyle::Ascii); table.add_row(vec!["Data 1", "Data 2", "Data 3"]); table.print();
Output
+----------+----------+----------+
| Header 1 | Header 2 | Header 3 |
+----------+----------+----------+
| Data 1   | Data 2   | Data 3   |
+----------+----------+----------+
Unicode Support
Proper handling of Unicode characters and emoji
Unicode Support Example
use zfish::table::Table; // Create table with headers let mut table = Table::new(vec!["Emoji", "Name", "Category"]); table.add_row(vec!["šŸš€", "Rocket", "Transport"]); table.add_row(vec!["šŸŽØ", "Palette", "Art"]); table.add_row(vec!["🐟", "Fish", "Animal"]); table.add_row(vec!["你儽", "Hello (Chinese)", "Language"]); table.print();
Output
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Emoji │ Name             │ Category  │
ā”œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¤
│ šŸš€    │ Rocket           │ Transport │
│ šŸŽØ    │ Palette          │ Art       │
│ 🐟    │ Fish             │ Animal    │
│ 你儽  │ Hello (Chinese)  │ Language  │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
Manual Box Drawing
Draw custom boxes and borders
Manual Box Drawing
use zfish::table::draw_box; use zfish::style::Color; // Draw a colored box draw_box( "Hello, ZFish!", Color::Green, Some(60), true ); // Draw a simple box draw_box( "Simple message", Color::Blue, None, false );
Output
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│                      Hello, ZFish!                         │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ Simple message   │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
API Reference
Available methods and options

Table Methods

new()Create a new table
add_row(&[&str])Add a row to the table
set_header_style(color)Style the header row
set_column_alignment(col, align)Set column alignment
set_border_color(color)Set border color
set_box_style(style)Set box-drawing style
print()Print the table

Box Styles

UnicodeAsciiRoundedDoubleBold