1# ansi-escapes [![Build Status](https://travis-ci.org/sindresorhus/ansi-escapes.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-escapes) 2 3> [ANSI escape codes](http://www.termsys.demon.co.uk/vtansi.htm) for manipulating the terminal 4 5 6## Install 7 8``` 9$ npm install ansi-escapes 10``` 11 12 13## Usage 14 15```js 16const ansiEscapes = require('ansi-escapes'); 17 18// Moves the cursor two rows up and to the left 19process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft); 20//=> '\u001B[2A\u001B[1000D' 21``` 22 23 24## API 25 26### cursorTo(x, [y]) 27 28Set the absolute position of the cursor. `x0` `y0` is the top left of the screen. 29 30### cursorMove(x, [y]) 31 32Set the position of the cursor relative to its current position. 33 34### cursorUp(count) 35 36Move cursor up a specific amount of rows. Default is `1`. 37 38### cursorDown(count) 39 40Move cursor down a specific amount of rows. Default is `1`. 41 42### cursorForward(count) 43 44Move cursor forward a specific amount of rows. Default is `1`. 45 46### cursorBackward(count) 47 48Move cursor backward a specific amount of rows. Default is `1`. 49 50### cursorLeft 51 52Move cursor to the left side. 53 54### cursorSavePosition 55 56Save cursor position. 57 58### cursorRestorePosition 59 60Restore saved cursor position. 61 62### cursorGetPosition 63 64Get cursor position. 65 66### cursorNextLine 67 68Move cursor to the next line. 69 70### cursorPrevLine 71 72Move cursor to the previous line. 73 74### cursorHide 75 76Hide cursor. 77 78### cursorShow 79 80Show cursor. 81 82### eraseLines(count) 83 84Erase from the current cursor position up the specified amount of rows. 85 86### eraseEndLine 87 88Erase from the current cursor position to the end of the current line. 89 90### eraseStartLine 91 92Erase from the current cursor position to the start of the current line. 93 94### eraseLine 95 96Erase the entire current line. 97 98### eraseDown 99 100Erase the screen from the current line down to the bottom of the screen. 101 102### eraseUp 103 104Erase the screen from the current line up to the top of the screen. 105 106### eraseScreen 107 108Erase the screen and move the cursor the top left position. 109 110### scrollUp 111 112Scroll display up one line. 113 114### scrollDown 115 116Scroll display down one line. 117 118### clearScreen 119 120Clear the terminal screen. (Viewport) 121 122### clearTerminal 123 124Clear the whole terminal, including scrollback buffer. (Not just the visible part of it) 125 126### beep 127 128Output a beeping sound. 129 130### link(text, url) 131 132Create a clickable link. 133 134[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support. 135 136### image(input, [options]) 137 138Display an image. 139 140*Currently only supported on iTerm2 >=3* 141 142See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module. 143 144#### input 145 146Type: `Buffer` 147 148Buffer of an image. Usually read in with `fs.readFile()`. 149 150#### options 151 152##### width 153##### height 154 155Type: `string` `number` 156 157The width and height are given as a number followed by a unit, or the word "auto". 158 159- `N`: N character cells. 160- `Npx`: N pixels. 161- `N%`: N percent of the session's width or height. 162- `auto`: The image's inherent size will be used to determine an appropriate dimension. 163 164##### preserveAspectRatio 165 166Type: `boolean`<br> 167Default: `true` 168 169### iTerm.setCwd([path]) 170 171Type: `string`<br> 172Default: `process.cwd()` 173 174[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 176 177## Related 178 179- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal 180 181 182## License 183 184MIT © [Sindre Sorhus](https://sindresorhus.com) 185