JSPM

  • Created
  • Published
  • Downloads 38
  • Score
    100M100P100Q70659F
  • License MIT

Smarter terminal text wrapping (handles 24bit color)

Package Exports

  • truwrap

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (truwrap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Truwrap

A node module and CLI for text wrapping, panels & tables that supports 24bit color SGR codes.

Project status npm Status Chat on Gitter
Build Status Dependency Status devDependency Status

Install

Global version, for CLI use

npm install --global truwrap

Module, for programmatic use

npm install --save truwrap

Many current tty text wrapping solutions have issues with the 'long' and currently 'non-standard' RGB SGR codes (i.e ^[[38;2;204;51;66m). This meant that, while it's possible to have wonderful, rich, full gamut colours and the aesthetic data visualisations it entails, it comes at the price of painful typography and corrupted console displays as text is broken up, unnaturally wrapped and becoming unreadable as the SGR codes are dashed against the rocks of 1980's shortsightedness, confusing your terminal and ever so slightly breaking the heart of design aware coders and administrators everywhere.

Clearly this is unnacceptable!

Previously, the only solution was to take a last, long whistful look at how great console colour could be, before going back to the, at best, 256 colours of the xterm pallette, with it's lack of useful greens and overly dark purples, or, for some, the even more cruelly devastating 16 colours of the ansi pallette, before heading to the stationary cupboard for a bit of a cry.

But weep no more!

Developed as part of our internal data visualisation system, where having the fidelity of 24 bit colour and embedded images (currently OS X iTerm 3 only) was a huge advantage.

Usable within your own node.js cli projects and an npm module or directly from the command line as a shell scripting command.

Screengrab

CLI usage

Synopsis

truwrap [OPTIONS]

Options:
-h, --help       Display this help.
-v, --version    Return the current version. -vv Return name & version.
-V, --verbose    Be verbose. -VV Be loquacious.
-o, --stderr     Use stderr rather than stdout
-l, --left       Left margin [default: 2]
-r, --right      Right margin [default: 2]
-w, --width      Set total width. Overrides terminal windows’ width.
-m, --mode       Wrapping mode: hard (break long lines), soft (keep white space)
-s, --stamp      Print arguments rather than stdin. printf-style options supported.
-p, --panel      Render a table into the available console width.
-d, --delimiter  The column delimiter when rendering a table. [default: "|"]
-x, --regex      Character run selection regex. Overrides --mode

To use simply pipe in a body of text to wrap according to the supplied options.

cat readme.md | truwrap --left 6 --right 6 --mode soft

Example Screengrab

Programmatic usage

var truwrap = require('truwrap')

var writer = truwrap({
  left: 2,
  right: 2,
  mode: 'soft',
  outStream: process.stderr
})

var contentWidth = writer.getWidth()

writer.write("Some text to write...", "...and some more.")
writer.write("A new paragraph, if not implicitly present.")
writer.end()

Advanced use

To add. Containers, Tables, Panels and Images.

For advanced 24bit colour handling see MarkGriffiths/trucolor and npm trucolor.

Initially a port of substack/node-wordwrap to format yargs help output that contained (the very long) ansi 24bit color SGR codes.