Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

colflow

Reflow line-oriented text from stdin into multiple visual columns. Designed for ultrawide monitors (32:9, 21:9) where a single column of build output or log lines wastes most of the horizontal space. Instead of scrolling down through thousands of lines, colflow packs them side-by-side so more context fits in one screen.

Install

cargo install --path .

Usage examples

# View a build log in 3 columns, with colour, via less
make 2>&1 | colflow -n 3 | less -R

# Browse the filesystem in 4 columns
find / -type f 2>/dev/null | colflow -n 4

# Watch the kernel ring buffer spread across the terminal
dmesg | colflow

# Use a visible column rule and strip colour
journalctl -b | colflow -s '' --no-color | less

Options

colflow [OPTIONS]

  -n, --columns <N>          Number of columns (default: auto from width / min-col-width)
  -w, --width <COLS>         Total output width in cells (default: terminal width or 200)
  -m, --min-col-width <COLS> Minimum column width for auto column count (default: 40)
  -g, --gap <COLS>           Cells of gap between columns (default: 2)
  -s, --separator <STR>      String drawn in the gap (default: two spaces)
      --no-color             Strip ANSI colour/style sequences from input
      --truncate             Truncate long lines with '…' instead of wrapping
  -h, --help
  -V, --version

Design notes

Newspaper flow

All input lines are first wrapped into visual rows of column_width cells. The resulting rows are then divided into N roughly equal chunks and assigned to columns left-to-right. Column 1 gets rows 0..R, column 2 gets R..2R, and so on. Each chunk is then emitted side-by-side, row by row. This matches how a newspaper lays out a long article across columns: you read down column 1 to the bottom of the page, then back up to the top of column 2.

Why SGR carry matters

Terminal colour is stateful. An ESC[31m (red) escape applies to every character printed after it until reset. When a coloured line wraps across two visual rows, the second row must reopen the same colour or it will either appear in the wrong colour (leaked state) or in the default colour (dropped state).

colflow maintains a running SgrState while scanning each logical line. At every wrap boundary it appends ESC[0m (reset) to the row that just finished, and prepends the accumulated SGR prefix to the next row. This keeps colour correct without interpreting what the colours actually mean.

What is deliberately not supported

  • Full-screen TUI apps: tools that use cursor-movement sequences (ESC[H, ESC[2J, etc.) need a pty, not a pipe. colflow is for line-oriented output.
  • Follow / live tailing (tail -f style): batch-only in v1.
  • Word-boundary wrapping: lines wrap at cell boundaries, not word boundaries. Long tokens (URLs, paths) may be split mid-token.
  • Right-to-left text: BiDi reordering is not implemented.

Future work

  • --follow: stream new lines to the terminal as they arrive, re-flowing each column in place (requires a pty or alternate-screen approach).
  • Word-boundary wrapping: break at the last space before the column edge.
  • A shell wrapper that interposes a pty so programs that detect non-TTY stdout (e.g. grep --color=auto) still emit colour.
  • Configurable tab stop width.

About

Columnize shell output

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages