#elastic #aligned #whitespace #table #tabs

app tabwriter-bin

Command line tool for elastic tabstops

1 unstable release

0.1.1 Oct 2, 2018

#6 in #whitespace

Download history 3/week @ 2018-10-02 10/week @ 2018-10-09 13/week @ 2018-10-16 2/week @ 2018-10-23 1/week @ 2018-10-30 10/week @ 2018-11-06 3/week @ 2018-11-13 2/week @ 2018-11-20 2/week @ 2018-11-27 5/week @ 2018-12-04

2 downloads per month

Unlicense/MIT

25KB
404 lines

tabwriter is a crate that implements elastic tabstops. It provides both a library for wrapping Rust Writers and a small program that exposes the same functionality at the command line.

Build status

Dual-licensed under MIT or the UNLICENSE.

Simple example of library

use tabwriter::TabWriter;

let mut tw = TabWriter::new(vec![]);
tw.write_str("
Bruce Springsteen\tBorn to Run
Bob Seger\tNight Moves
Metallica\tBlack
The Boss\tDarkness on the Edge of Town
").unwrap();
tw.flush().unwrap();

let written = String::from_utf8(tw.into_inner().unwrap()).unwrap();

assert_eq!(written.as_slice(), "
Bruce Springsteen  Born to Run
Bob Seger          Night Moves
Metallica          Black
The Boss           Darkness on the Edge of Town
");

You can see an example of real use in my CSV toolkit.

Simple example of command line utility

[andrew@Liger tabwriter] cat sample | sed 's/   /\\t/g'
a\tb\tc
abc\tmnopqrstuv\txyz
abcmnoxyz\tmore text

a\tb\tc
[andrew@Liger tabwriter] ./target/tabwriter < sample
a          b           c
abc        mnopqrstuv  xyz
abcmnoxyz  more text

a   b   c

Notice that once a column block is broken, alignment starts over again.

Documentation

The API is fully documented with some examples: http://burntsushi.net/rustdoc/tabwriter/.

Installation

This crate works with Cargo. Assuming you have Rust and Cargo installed, simply check out the source and run tests:

git clone git://github.com/BurntSushi/tabwriter
cd tabwriter
cargo test

You can also add tabwriter as a dependency to your project's Cargo.toml:

[dependencies]
tabwriter = "1"

Dealing with ANSI escape codes

If you want tabwriter to be aware of ANSI escape codes, then compile it with the ansi_formatting feature enabled.

Dependencies

~3.5MB
~67K SLoC