Code Monkey home page Code Monkey logo

truwrap's Introduction

truwrap v0.1.22

Project status Build Status Dependency Status devDependency Status npm

Work in progress.

Smarter text wrapping for modern xterms that support 24bit SGR color.

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.

CLI usage

To install using npm:

npm install truwrap -g

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

cat README.md | truwrap --left 12 --right 12 --mode soft

Options

> truwrap --help

truwrap v0.1.22

  Reads unformatted text from stdin and typographically applies paragraph wrapping it for the currently active tty.

  CLI Usage:
  Text stream (i.e cat, echo) | 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      Width. Overrides right margin.
  -m, --mode       Wrapping mode: hard (break long lines), soft (keep white space) [default: "hard"]
  -e, --encoding   Set encoding. [default: "utf8"]
  -s, --stamp      Print arguments rather than stdin. printf-style options supported.
  -t, --table      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

Programmatic usage

Basic use

npm install truwrap --save

... and then ...

	var truwrap = require('truwrap')

	var writer = truwrap({
		left: 2
		right: -2
		mode: 'soft'
		encoding: 'utf8'
		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.

Related

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

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

truwrap's People

Contributors

markgriffiths avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.