ansi-escapes
Advanced tools
Comparing version 6.0.0 to 6.1.0
13
index.js
@@ -8,4 +8,11 @@ import process from 'node:process'; | ||
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal'; | ||
/* global window */ | ||
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined'; | ||
const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal'; | ||
const isWindows = !isBrowser && process.platform === 'win32'; | ||
const cwdFunction = isBrowser ? () => { | ||
throw new Error('`process.cwd()` only works in Node.js, not the browser.'); | ||
} : process.cwd; | ||
const ansiEscapes = {}; | ||
@@ -86,3 +93,3 @@ | ||
ansiEscapes.clearTerminal = process.platform === 'win32' | ||
ansiEscapes.clearTerminal = isWindows | ||
? `${ansiEscapes.eraseScreen}${ESC}0f` | ||
@@ -131,3 +138,3 @@ // 1. Erases the screen (Only done in case `2` is not supported) | ||
ansiEscapes.iTerm = { | ||
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`, | ||
setCwd: (cwd = cwdFunction()) => `${OSC}50;CurrentDir=${cwd}${BEL}`, | ||
@@ -134,0 +141,0 @@ annotation(message, options = {}) { |
{ | ||
"name": "ansi-escapes", | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"description": "ANSI escape codes for manipulating the terminal", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -21,2 +21,16 @@ # ansi-escapes | ||
**You can also use it in the browser with Xterm.js:** | ||
```js | ||
import ansiEscapes from 'ansi-escapes'; | ||
import {Terminal} from 'xterm'; | ||
import 'xterm/css/xterm.css'; | ||
const terminal = new Terminal({…}); | ||
// Moves the cursor two rows up and to the left | ||
terminal.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft); | ||
//=> '\u001B[2A\u001B[1000D' | ||
``` | ||
## API | ||
@@ -23,0 +37,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16651
317
248