sty

0.6.1 • Public • Published

Sty – Colorization and more for Node.js console output

Installation

You've got Node.js and npm, right? Then:

npm install sty

You'll also want CoffeeScript:

npm install coffee-script

Quick start

Using CoffeeScript:

sty = require 'sty'
console.log "#{sty.red 'WARNING:'} Color is #{sty.green 'awesome!'}"

Nesting works as you'd expect:

console.log "#{sty.bgblack sty.bold "#{sty.red 'U'}S#{sty.cyan 'A'}"}"

You can also use some pseudo-HTML, through sty.parse:

console.log sty.parse 'You are being <b>attacked</b> by the <b><yellow>great dragon</yellow>!</b>'

Forget valid XML; you can move tags around freely:

console.log sty.parse '<b>W<u>h</b>o</u>a'

Tags that aren't supported by sty are ignored (that is, sty.parse '<foo>' is just '<foo>').

If you find yourself using console.log sty.parse a lot, you should probably try styout.

Advanced usage

If you want to use ANSI codes directly, each is a valid sty function name; so, for instance, sty[1] is identical to sty.bold. You can also use these numbers as HTML tags, prefixed by a or A; for instance, you can get a blink effect with <A5>:

console.log sty.parse 'I saw the best minds of my generation destroyed by madness, starving hysterical naked.'

More documentation

For a complete list of every function/tag name in sty, run demo.coffee (coffee demo.coffee) after installation.

Disabling Sty

Sty automatically disables fancy output when the console doesn't support it (that is, when Node's tty.isatty(process.stdout) is false). You can also manually use sty.disable() and sty.enable() to switch styling on/off.

License and credits

Copyright (c) 2010 Trevor Burnham and made available under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

This distribution includes a slightly modified version of Bob Righter's node-xml, also under the MIT license.

Thanks go to Chris Lloyd for colored.js, which inspired this project.

Readme

Keywords

none

Package Sidebar

Install

npm i sty

Weekly Downloads

1,666

Version

0.6.1

License

none

Last publish

Collaborators

  • TrevorBurnham
  • trevorburnham