1 # ansi-escapes [![Build Status](https://travis-ci.org/sindresorhus/ansi-escapes.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-escapes)
3 > [ANSI escape codes](http://www.termsys.demon.co.uk/vtansi.htm) for manipulating the terminal
8 $ npm install ansi-escapes
14 const ansiEscapes = require('ansi-escapes');
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'
25 Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
29 Set the position of the cursor relative to its current position.
33 Move cursor up a specific amount of rows. Default is `1`.
37 Move cursor down a specific amount of rows. Default is `1`.
39 ### cursorForward(count)
41 Move cursor forward a specific amount of columns. Default is `1`.
43 ### cursorBackward(count)
45 Move cursor backward a specific amount of columns. Default is `1`.
49 Move cursor to the left side.
51 ### cursorSavePosition
55 ### cursorRestorePosition
57 Restore saved cursor position.
65 Move cursor to the next line.
69 Move cursor to the previous line.
81 Erase from the current cursor position up the specified amount of rows.
85 Erase from the current cursor position to the end of the current line.
89 Erase from the current cursor position to the start of the current line.
93 Erase the entire current line.
97 Erase the screen from the current line down to the bottom of the screen.
101 Erase the screen from the current line up to the top of the screen.
105 Erase the screen and move the cursor the top left position.
109 Scroll display up one line.
113 Scroll display down one line.
117 Clear the terminal screen. (Viewport)
121 Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
125 Output a beeping sound.
129 Create a clickable link.
131 [Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
133 ### image(filePath, options?)
137 *Currently only supported on iTerm2 >=3*
139 See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
145 Buffer of an image. Usually read in with `fs.readFile()`.
154 Type: `string | number`
156 The width and height are given as a number followed by a unit, or the word "auto".
158 - `N`: N character cells.
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.
163 ##### preserveAspectRatio
168 ### iTerm.setCwd(path?)
171 Default: `process.cwd()`
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).
175 ### iTerm.annotation(message, options?)
177 Creates an escape code to display an "annotation" in iTerm2.
179 An annotation looks like this when shown:
181 <img src="https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png" width="500">
183 See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
189 The message to display within the annotation.
191 The `|` character is disallowed and will be stripped.
200 Default: The remainder of the line
202 Nonzero number of columns to annotate.
207 Default: Cursor position
209 Starting X coordinate.
211 Must be used with `y` and `length`.
216 Default: Cursor position
218 Starting Y coordinate.
220 Must be used with `x` and `length`.
227 Create a "hidden" annotation.
229 Annotations created this way can be shown using the "Show Annotations" iTerm command.
233 - [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
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>
243 Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.