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