cols
Smart adaptive formatting of columnar data for Rust.
cols is designed for CLI tools that need terminal-aware table output with
tree rendering, multiple output formats, and built-in filtering. Think
lsblk, lsmem, or pstree.
Documentation | API Reference | Crates.io
Quick start
[]
= "0.2"
use ;
let mut table = new;
table.add_column;
table.add_column;
let l1 = table.new_line;
table.line_mut.data_set.data_set;
let l2 = table.new_line;
table.line_mut.data_set.data_set;
let output = print_table_to_string.unwrap;
NAME SIZE
sda 100G
sdb 50G
Tree rendering
use ;
let mut table = new;
table.add_column;
table.add_column;
let root = table.new_line;
table.line_mut.data_set.data_set;
let c1 = table.new_line;
table.line_mut.data_set.data_set;
let gc = table.new_line;
table.line_mut.data_set.data_set;
let c2 = table.new_line;
table.line_mut.data_set.data_set;
NAME SIZE
root 100
├─child1 50
│ └─grandchild 20
└─child2 30
Multiple output modes
The same table can be rendered in seven formats without rebuilding it:
use OutputMode;
table.output_mode_set;
Normal — human-readable with column alignment and padding.
Raw — compact, separator-delimited.
Export — NAME="value" pairs.
ShellVar — like Export with shell-safe column names.
JSON — typed JSON array of objects.
CSV — RFC 4180 with automatic quoting.
Markdown — pipe-delimited with alignment support.
Features
- Adaptive column widths with fixed, fractional, or content-sized hints
- Tree rendering with Unicode or ASCII connectors
- 7 output modes: Normal, Raw, Export, JSON, ShellVar, CSV, Markdown
- Group brackets for M:N member/child relationships
- Filter expressions with boolean logic, comparisons, regex, and integer suffixes (K/M/G/T)
- Sorting with custom comparators
- Column alignment: left, center, right (column default with per-cell override)
- Streaming mode: output rows incrementally without buffering the whole table
- Builder API:
Column::new("NAME").width_fixed(10).right(true).truncate(true)
Examples
The examples/ directory contains runnable demos:
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.