tabular: plain text tables in Rust

Builds plain, automatically-aligned tables of monospaced text. This is basically what you want if you are implementing ls.

Example

```rust use tabular::{Table, Row}; use std::path::Path;

fn ls(dir: &Path) -> ::std::io::Result<()> { let mut table = Table::new("{:>} {:<}{:<} {:<}"); for entryresult in ::std::fs::readdir(dir)? { let entry = entry_result?; let metadata = entry.metadata()?;

    table.add_row(Row::new()
         .with_cell(metadata.len())
         .with_cell(if metadata.permissions().readonly() {"r"} else {""})
         .with_cell(if metadata.is_dir() {"d"} else {""})
         .with_cell(entry.path().display()));
}

print!("{}", table);

Ok(())

}

ls(Path::new(&"target")).unwrap(); ```

produces something like

1198 target/.rustc_info.json 1120 d target/doc 672 d target/debug

Usage

It's on crates.io, so you can add

toml [dependencies] tabular = "0.1.0"

to your Cargo.toml.

Feature unicode-width is enabled be default; it depends on the unicode-width crate. You can turn it off with:

toml [dependencies] tabular = { version = "0.1.0", default-features = false }

Note that without unicode-width, alignment will be based on the count of the std::str::Chars iterator.

This crate supports Rust version 1.18.0 and later.

See also

You may also want: