ansi-escapes
Advanced tools
Comparing version 4.2.1 to 4.3.0
@@ -28,2 +28,36 @@ /// <reference types="node"/> | ||
} | ||
interface AnnotationOptions { | ||
/** | ||
Nonzero number of columns to annotate. | ||
Default: The remainder of the line. | ||
*/ | ||
readonly length?: number; | ||
/** | ||
Starting X coordinate. | ||
Must be used with `y` and `length`. | ||
Default: The cursor position | ||
*/ | ||
readonly x?: number; | ||
/** | ||
Starting Y coordinate. | ||
Must be used with `x` and `length`. | ||
Default: Cursor position. | ||
*/ | ||
readonly y?: number; | ||
/** | ||
Create a "hidden" annotation. | ||
Annotations created this way can be shown using the "Show Annotations" iTerm command. | ||
*/ | ||
readonly isHidden?: boolean; | ||
} | ||
} | ||
@@ -197,2 +231,14 @@ | ||
setCwd(cwd: string): string; | ||
/** | ||
An annotation looks like this when shown: | ||
![screenshot of iTerm annotation](https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png) | ||
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information. | ||
@param message - The message to display within the annotation. The `|` character is disallowed and will be stripped. | ||
@returns An escape code which will create an annotation when printed in iTerm2. | ||
*/ | ||
annotation(message: string, options?: ansiEscapes.AnnotationOptions): string; | ||
}; | ||
@@ -199,0 +245,0 @@ |
27
index.js
@@ -131,3 +131,28 @@ 'use strict'; | ||
ansiEscapes.iTerm = { | ||
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}` | ||
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`, | ||
annotation: (message, options = {}) => { | ||
let ret = `${OSC}1337;`; | ||
const hasX = typeof options.x !== 'undefined'; | ||
const hasY = typeof options.y !== 'undefined'; | ||
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) { | ||
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined'); | ||
} | ||
message = message.replace(/\|/g, ''); | ||
ret += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation='; | ||
if (options.length > 0) { | ||
ret += | ||
(hasX ? | ||
[message, options.length, options.x, options.y] : | ||
[options.length, message]).join('|'); | ||
} else { | ||
ret += message; | ||
} | ||
return ret + BEL; | ||
} | ||
}; |
{ | ||
"name": "ansi-escapes", | ||
"version": "4.2.1", | ||
"version": "4.3.0", | ||
"description": "ANSI escape codes for manipulating the terminal", | ||
@@ -48,3 +48,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"type-fest": "^0.5.2" | ||
"type-fest": "^0.8.1" | ||
}, | ||
@@ -54,5 +54,5 @@ "devDependencies": { | ||
"ava": "^2.1.0", | ||
"tsd": "^0.7.1", | ||
"xo": "^0.24.0" | ||
"tsd": "^0.11.0", | ||
"xo": "^0.25.3" | ||
} | ||
} |
@@ -5,3 +5,2 @@ # ansi-escapes [![Build Status](https://travis-ci.org/sindresorhus/ansi-escapes.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-escapes) | ||
## Install | ||
@@ -13,3 +12,2 @@ | ||
## Usage | ||
@@ -25,3 +23,2 @@ | ||
## API | ||
@@ -171,3 +168,3 @@ | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -177,3 +174,3 @@ | ||
Type: `string`<br> | ||
Type: `string`\ | ||
Default: `process.cwd()` | ||
@@ -183,3 +180,58 @@ | ||
### iTerm.annotation(message, options?) | ||
Creates an escape code to display an "annotation" in iTerm2. | ||
An annotation looks like this when shown: | ||
<img src="https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png" width="500"> | ||
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information. | ||
#### message | ||
Type: `string` | ||
The message to display within the annotation. | ||
The `|` character is disallowed and will be stripped. | ||
#### options | ||
Type: `object` | ||
##### length | ||
Type: `number`\ | ||
Default: The remainder of the line | ||
Nonzero number of columns to annotate. | ||
##### x | ||
Type: `number`\ | ||
Default: Cursor position | ||
Starting X coordinate. | ||
Must be used with `y` and `length`. | ||
##### y | ||
Type: `number`\ | ||
Default: Cursor position | ||
Starting Y coordinate. | ||
Must be used with `x` and `length`. | ||
##### isHidden | ||
Type: `boolean`\ | ||
Default: `false` | ||
Create a "hidden" annotation. | ||
Annotations created this way can be shown using the "Show Annotations" iTerm command. | ||
## Related | ||
@@ -186,0 +238,0 @@ |
16441
313
247
+ Addedtype-fest@0.8.1(transitive)
- Removedtype-fest@0.5.2(transitive)
Updatedtype-fest@^0.8.1