README.md
1# Console Control Strings
2
3A library of cross-platform tested terminal/console command strings for
4doing things like color and cursor positioning. This is a subset of both
5ansi and vt100. All control codes included work on both Windows & Unix-like
6OSes, except where noted.
7
8## Usage
9
10```js
11var consoleControl = require('console-control-strings')
12
13console.log(consoleControl.color('blue','bgRed', 'bold') + 'hi there' + consoleControl.color('reset'))
14process.stdout.write(consoleControl.goto(75, 10))
15```
16
17## Why Another?
18
19There are tons of libraries similar to this one. I wanted one that was:
20
211. Very clear about compatibility goals.
222. Could emit, for instance, a start color code without an end one.
233. Returned strings w/o writing to streams.
244. Was not weighed down with other unrelated baggage.
25
26## Functions
27
28### var code = consoleControl.up(_num = 1_)
29
30Returns the escape sequence to move _num_ lines up.
31
32### var code = consoleControl.down(_num = 1_)
33
34Returns the escape sequence to move _num_ lines down.
35
36### var code = consoleControl.forward(_num = 1_)
37
38Returns the escape sequence to move _num_ lines righ.
39
40### var code = consoleControl.back(_num = 1_)
41
42Returns the escape sequence to move _num_ lines left.
43
44### var code = consoleControl.nextLine(_num = 1_)
45
46Returns the escape sequence to move _num_ lines down and to the beginning of
47the line.
48
49### var code = consoleControl.previousLine(_num = 1_)
50
51Returns the escape sequence to move _num_ lines up and to the beginning of
52the line.
53
54### var code = consoleControl.eraseData()
55
56Returns the escape sequence to erase everything from the current cursor
57position to the bottom right of the screen. This is line based, so it
58erases the remainder of the current line and all following lines.
59
60### var code = consoleControl.eraseLine()
61
62Returns the escape sequence to erase to the end of the current line.
63
64### var code = consoleControl.goto(_x_, _y_)
65
66Returns the escape sequence to move the cursor to the designated position.
67Note that the origin is _1, 1_ not _0, 0_.
68
69### var code = consoleControl.gotoSOL()
70
71Returns the escape sequence to move the cursor to the beginning of the
72current line. (That is, it returns a carriage return, `\r`.)
73
74### var code = consoleControl.beep()
75
76Returns the escape sequence to cause the termianl to beep. (That is, it
77returns unicode character `\x0007`, a Control-G.)
78
79### var code = consoleControl.hideCursor()
80
81Returns the escape sequence to hide the cursor.
82
83### var code = consoleControl.showCursor()
84
85Returns the escape sequence to show the cursor.
86
87### var code = consoleControl.color(_colors = []_)
88
89### var code = consoleControl.color(_color1_, _color2_, _…_, _colorn_)
90
91Returns the escape sequence to set the current terminal display attributes
92(mostly colors). Arguments can either be a list of attributes or an array
93of attributes. The difference between passing in an array or list of colors
94and calling `.color` separately for each one, is that in the former case a
95single escape sequence will be produced where as in the latter each change
96will have its own distinct escape sequence. Each attribute can be one of:
97
98* Reset:
99 * **reset** – Reset all attributes to the terminal default.
100* Styles:
101 * **bold** – Display text as bold. In some terminals this means using a
102 bold font, in others this means changing the color. In some it means
103 both.
104 * **italic** – Display text as italic. This is not available in most Windows terminals.
105 * **underline** – Underline text. This is not available in most Windows Terminals.
106 * **inverse** – Invert the foreground and background colors.
107 * **stopBold** – Do not display text as bold.
108 * **stopItalic** – Do not display text as italic.
109 * **stopUnderline** – Do not underline text.
110 * **stopInverse** – Do not invert foreground and background.
111* Colors:
112 * **white**
113 * **black**
114 * **blue**
115 * **cyan**
116 * **green**
117 * **magenta**
118 * **red**
119 * **yellow**
120 * **grey** / **brightBlack**
121 * **brightRed**
122 * **brightGreen**
123 * **brightYellow**
124 * **brightBlue**
125 * **brightMagenta**
126 * **brightCyan**
127 * **brightWhite**
128* Background Colors:
129 * **bgWhite**
130 * **bgBlack**
131 * **bgBlue**
132 * **bgCyan**
133 * **bgGreen**
134 * **bgMagenta**
135 * **bgRed**
136 * **bgYellow**
137 * **bgGrey** / **bgBrightBlack**
138 * **bgBrightRed**
139 * **bgBrightGreen**
140 * **bgBrightYellow**
141 * **bgBrightBlue**
142 * **bgBrightMagenta**
143 * **bgBrightCyan**
144 * **bgBrightWhite**
145
146