1 | # ansi-escapes
|
---|
2 |
|
---|
3 | > [ANSI escape codes](http://www.termsys.demon.co.uk/vtansi.htm) for manipulating the terminal
|
---|
4 |
|
---|
5 | ## Install
|
---|
6 |
|
---|
7 | ```
|
---|
8 | $ npm install ansi-escapes
|
---|
9 | ```
|
---|
10 |
|
---|
11 | ## Usage
|
---|
12 |
|
---|
13 | ```js
|
---|
14 | const ansiEscapes = require('ansi-escapes');
|
---|
15 |
|
---|
16 | // Moves the cursor two rows up and to the left
|
---|
17 | process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
|
---|
18 | //=> '\u001B[2A\u001B[1000D'
|
---|
19 | ```
|
---|
20 |
|
---|
21 | ## API
|
---|
22 |
|
---|
23 | ### cursorTo(x, y?)
|
---|
24 |
|
---|
25 | Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
|
---|
26 |
|
---|
27 | ### cursorMove(x, y?)
|
---|
28 |
|
---|
29 | Set the position of the cursor relative to its current position.
|
---|
30 |
|
---|
31 | ### cursorUp(count)
|
---|
32 |
|
---|
33 | Move cursor up a specific amount of rows. Default is `1`.
|
---|
34 |
|
---|
35 | ### cursorDown(count)
|
---|
36 |
|
---|
37 | Move cursor down a specific amount of rows. Default is `1`.
|
---|
38 |
|
---|
39 | ### cursorForward(count)
|
---|
40 |
|
---|
41 | Move cursor forward a specific amount of columns. Default is `1`.
|
---|
42 |
|
---|
43 | ### cursorBackward(count)
|
---|
44 |
|
---|
45 | Move cursor backward a specific amount of columns. Default is `1`.
|
---|
46 |
|
---|
47 | ### cursorLeft
|
---|
48 |
|
---|
49 | Move cursor to the left side.
|
---|
50 |
|
---|
51 | ### cursorSavePosition
|
---|
52 |
|
---|
53 | Save cursor position.
|
---|
54 |
|
---|
55 | ### cursorRestorePosition
|
---|
56 |
|
---|
57 | Restore saved cursor position.
|
---|
58 |
|
---|
59 | ### cursorGetPosition
|
---|
60 |
|
---|
61 | Get cursor position.
|
---|
62 |
|
---|
63 | ### cursorNextLine
|
---|
64 |
|
---|
65 | Move cursor to the next line.
|
---|
66 |
|
---|
67 | ### cursorPrevLine
|
---|
68 |
|
---|
69 | Move cursor to the previous line.
|
---|
70 |
|
---|
71 | ### cursorHide
|
---|
72 |
|
---|
73 | Hide cursor.
|
---|
74 |
|
---|
75 | ### cursorShow
|
---|
76 |
|
---|
77 | Show cursor.
|
---|
78 |
|
---|
79 | ### eraseLines(count)
|
---|
80 |
|
---|
81 | Erase from the current cursor position up the specified amount of rows.
|
---|
82 |
|
---|
83 | ### eraseEndLine
|
---|
84 |
|
---|
85 | Erase from the current cursor position to the end of the current line.
|
---|
86 |
|
---|
87 | ### eraseStartLine
|
---|
88 |
|
---|
89 | Erase from the current cursor position to the start of the current line.
|
---|
90 |
|
---|
91 | ### eraseLine
|
---|
92 |
|
---|
93 | Erase the entire current line.
|
---|
94 |
|
---|
95 | ### eraseDown
|
---|
96 |
|
---|
97 | Erase the screen from the current line down to the bottom of the screen.
|
---|
98 |
|
---|
99 | ### eraseUp
|
---|
100 |
|
---|
101 | Erase the screen from the current line up to the top of the screen.
|
---|
102 |
|
---|
103 | ### eraseScreen
|
---|
104 |
|
---|
105 | Erase the screen and move the cursor the top left position.
|
---|
106 |
|
---|
107 | ### scrollUp
|
---|
108 |
|
---|
109 | Scroll display up one line.
|
---|
110 |
|
---|
111 | ### scrollDown
|
---|
112 |
|
---|
113 | Scroll display down one line.
|
---|
114 |
|
---|
115 | ### clearScreen
|
---|
116 |
|
---|
117 | Clear the terminal screen. (Viewport)
|
---|
118 |
|
---|
119 | ### clearTerminal
|
---|
120 |
|
---|
121 | Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
|
---|
122 |
|
---|
123 | ### beep
|
---|
124 |
|
---|
125 | Output a beeping sound.
|
---|
126 |
|
---|
127 | ### link(text, url)
|
---|
128 |
|
---|
129 | Create a clickable link.
|
---|
130 |
|
---|
131 | [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
|
---|
132 |
|
---|
133 | ### image(filePath, options?)
|
---|
134 |
|
---|
135 | Display an image.
|
---|
136 |
|
---|
137 | *Currently only supported on iTerm2 >=3*
|
---|
138 |
|
---|
139 | See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
|
---|
140 |
|
---|
141 | #### input
|
---|
142 |
|
---|
143 | Type: `Buffer`
|
---|
144 |
|
---|
145 | Buffer of an image. Usually read in with `fs.readFile()`.
|
---|
146 |
|
---|
147 | #### options
|
---|
148 |
|
---|
149 | Type: `object`
|
---|
150 |
|
---|
151 | ##### width
|
---|
152 | ##### height
|
---|
153 |
|
---|
154 | Type: `string | number`
|
---|
155 |
|
---|
156 | The width and height are given as a number followed by a unit, or the word "auto".
|
---|
157 |
|
---|
158 | - `N`: N character cells.
|
---|
159 | - `Npx`: N pixels.
|
---|
160 | - `N%`: N percent of the session's width or height.
|
---|
161 | - `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
---|
162 |
|
---|
163 | ##### preserveAspectRatio
|
---|
164 |
|
---|
165 | Type: `boolean`\
|
---|
166 | Default: `true`
|
---|
167 |
|
---|
168 | ### iTerm.setCwd(path?)
|
---|
169 |
|
---|
170 | Type: `string`\
|
---|
171 | Default: `process.cwd()`
|
---|
172 |
|
---|
173 | [Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
|
---|
174 |
|
---|
175 | ### iTerm.annotation(message, options?)
|
---|
176 |
|
---|
177 | Creates an escape code to display an "annotation" in iTerm2.
|
---|
178 |
|
---|
179 | An annotation looks like this when shown:
|
---|
180 |
|
---|
181 | <img src="https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png" width="500">
|
---|
182 |
|
---|
183 | See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
|
---|
184 |
|
---|
185 | #### message
|
---|
186 |
|
---|
187 | Type: `string`
|
---|
188 |
|
---|
189 | The message to display within the annotation.
|
---|
190 |
|
---|
191 | The `|` character is disallowed and will be stripped.
|
---|
192 |
|
---|
193 | #### options
|
---|
194 |
|
---|
195 | Type: `object`
|
---|
196 |
|
---|
197 | ##### length
|
---|
198 |
|
---|
199 | Type: `number`\
|
---|
200 | Default: The remainder of the line
|
---|
201 |
|
---|
202 | Nonzero number of columns to annotate.
|
---|
203 |
|
---|
204 | ##### x
|
---|
205 |
|
---|
206 | Type: `number`\
|
---|
207 | Default: Cursor position
|
---|
208 |
|
---|
209 | Starting X coordinate.
|
---|
210 |
|
---|
211 | Must be used with `y` and `length`.
|
---|
212 |
|
---|
213 | ##### y
|
---|
214 |
|
---|
215 | Type: `number`\
|
---|
216 | Default: Cursor position
|
---|
217 |
|
---|
218 | Starting Y coordinate.
|
---|
219 |
|
---|
220 | Must be used with `x` and `length`.
|
---|
221 |
|
---|
222 | ##### isHidden
|
---|
223 |
|
---|
224 | Type: `boolean`\
|
---|
225 | Default: `false`
|
---|
226 |
|
---|
227 | Create a "hidden" annotation.
|
---|
228 |
|
---|
229 | Annotations created this way can be shown using the "Show Annotations" iTerm command.
|
---|
230 |
|
---|
231 | ## Related
|
---|
232 |
|
---|
233 | - [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
---|
234 |
|
---|
235 | ---
|
---|
236 |
|
---|
237 | <div align="center">
|
---|
238 | <b>
|
---|
239 | <a href="https://tidelift.com/subscription/pkg/npm-ansi-escapes?utm_source=npm-ansi-escapes&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
---|
240 | </b>
|
---|
241 | <br>
|
---|
242 | <sub>
|
---|
243 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
---|
244 | </sub>
|
---|
245 | </div>
|
---|