• Home
Name Date Size #Lines LOC

..--

test/12-May-2024-1611

LICENSED12-May-20241.1 KiB2420

README.mdD12-May-20242.1 KiB7243

ansistyles.jsD12-May-2024978 3920

package.jsonD12-May-20241.4 KiB5958

README.md

1# ansistyles [![build status](https://secure.travis-ci.org/thlorenz/ansistyles.png)](http://next.travis-ci.org/thlorenz/ansistyles)
2
3Functions that surround a string with ansistyle codes so it prints in style.
4
5In case you need colors, like `red`, have a look at [ansicolors](https://github.com/thlorenz/ansicolors).
6
7## Installation
8
9    npm install ansistyles
10
11## Usage
12
13```js
14var styles = require('ansistyles');
15
16console.log(styles.bright('hello world'));    // prints hello world in 'bright' white
17console.log(styles.underline('hello world')); // prints hello world underlined
18console.log(styles.inverse('hello world'));   // prints hello world black on white
19```
20
21## Combining with ansicolors
22
23Get the ansicolors module:
24
25    npm install ansicolors
26
27```js
28var styles = require('ansistyles')
29  , colors = require('ansicolors');
30
31  console.log(
32    // prints hello world underlined in blue on a green background
33    colors.bgGreen(colors.blue(styles.underline('hello world')))
34  );
35```
36
37## Tests
38
39Look at the [tests](https://github.com/thlorenz/ansistyles/blob/master/test/ansistyles.js) to see more examples and/or run them via:
40
41    npm explore ansistyles && npm test
42
43## More Styles
44
45As you can see from [here](https://github.com/thlorenz/ansistyles/blob/master/ansistyles.js#L4-L15), more styles are available,
46but didn't have any effect on the terminals that I tested on Mac Lion and Ubuntu Linux.
47
48I included them for completeness, but didn't show them in the examples because they seem to have no effect.
49
50### reset
51
52A style reset function is also included, please note however that this is not nestable.
53
54Therefore the below only underlines `hell` only, but not `world`.
55
56```js
57console.log(styles.underline('hell' + styles.reset('o') + ' world'));
58```
59
60It is essentially the same as:
61
62```js
63console.log(styles.underline('hell') + styles.reset('') + 'o world');
64```
65
66
67
68## Alternatives
69
70**ansistyles** tries to meet simple use cases with a very simple API. However, if you need a more powerful ansi formatting tool,
71I'd suggest to look at the [features](https://github.com/TooTallNate/ansi.js#features) of the [ansi module](https://github.com/TooTallNate/ansi.js).
72