lipgloss-table
A table component for Terminal UIs, styled with Lip Gloss. This crate is part of the lipgloss-rs ecosystem and aims for 1:1 API and rendering parity with Charm's Go implementation.
- Headers, rows, borders, and separators
- Per-cell styling with
lipgloss::Style - Intelligent column sizing (expand/shrink) with Unicode-aware width
- Optional wrapping or truncation with ellipsis
- Fixed column widths via style, padding/margins support
Installation
Use the batteries-included facade (recommended):
[]
= { = "0.1.0", = ["tables"] }
Or depend directly on the component (add lipgloss for styling):
[]
= "0.1.0"
= "0.1.0"
Quick start
use Table;
let mut t = new
.headers
.row
.row;
println!;
Styling cells
Apply styles per cell with a function. Use HEADER_ROW for header styling.
use ;
use ;
let style_fn = ;
let mut t = new
.headers
.row
.row
.style_func;
println!;
For complex logic, capture state with a boxed closure:
use ;
use ;
let highlight = from;
let mut t = new
.headers
.row
.row
.style_func_boxed;
println!;
Predefined helpers are available:
use ;
let mut t = new
.headers
.row
.row
.style_func;
println!;
Borders and separators
Enable/disable borders and separators:
use ;
use Table;
let mut bordered = new
.headers
.row
.border
.border_style
.border_row;
let mut minimal = new
.headers
.row
.border_top
.border_bottom
.border_left
.border_right
.border_header
.border_column;
println!;
Width, wrapping, and truncation
- Set
width(i32)to constrain total table width. Columns are resized with an intelligent expand/shrink algorithm. - Enable
wrap(true)to wrap cell content; usewrap(false)to truncate with ellipsis. - Set
height(i32)andoffset(usize)for paging/scrolling.
use Table;
let mut wrap_demo = new
.headers
.row
.width
.wrap;
let mut trunc_demo = new
.headers
.row
.width
.wrap;
println!;
Fixed column widths and padding
Column widths are inferred from content and style. You can set fixed widths and spacing via per-cell styles in your style function. The widest explicit width per column is respected.
use Style;
use ;
let style_fn = ;
let mut t = new
.headers
.row
.row
.style_func
.width;
println!;
Data sources and filtering
You can supply your own data source by implementing Data, or use the built-in StringData. Filter rows without copying using Filter:
use ;
let data = new;
let filtered = new.filter; // keep even rows
let mut t = new
.headers
.data
.width;
println!;
Demos
Run demos from the repository root:
Notes
- Width/height calculations are Unicode- and ANSI-aware via
lipgloss::width. - Borders are rendered using
lipgloss::Borderpresets (rounded, thick, block, etc.). - Height-constrained rendering uses an overflow indicator row when data exceeds available space.
Documentation
- API docs:
https://docs.rs/lipgloss-table - Project:
https://github.com/whit3rabbit/lipgloss-rs
License
MIT