@visulima/ansi 4.0.0-alpha.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +306 -0
- package/LICENSE.md +0 -20
- package/README.md +41 -10
- package/dist/alternative-screen.d.ts +71 -70
- package/dist/alternative-screen.js +1 -8
- package/dist/background.d.ts +72 -0
- package/dist/background.js +1 -0
- package/dist/charset.d.ts +52 -0
- package/dist/charset.js +1 -0
- package/dist/clear.d.ts +74 -73
- package/dist/clear.js +1 -10
- package/dist/clipboard.d.ts +76 -0
- package/dist/clipboard.js +1 -0
- package/dist/constants.d.ts +18 -10
- package/dist/constants.js +1 -0
- package/dist/cursor.d.ts +421 -406
- package/dist/cursor.js +1 -3
- package/dist/cwd.d.ts +26 -0
- package/dist/cwd.js +1 -0
- package/dist/erase.d.ts +193 -192
- package/dist/erase.js +1 -47
- package/dist/finalterm.d.ts +47 -0
- package/dist/finalterm.js +1 -0
- package/dist/focus.d.ts +20 -0
- package/dist/focus.js +1 -0
- package/dist/hyperlink.d.ts +25 -25
- package/dist/hyperlink.js +1 -5
- package/dist/image.d.ts +70 -70
- package/dist/image.js +1 -40
- package/dist/index.d.ts +38 -35
- package/dist/index.js +1 -26
- package/dist/iterm2.d.ts +285 -58
- package/dist/iterm2.js +1 -12
- package/dist/keypad.d.ts +27 -0
- package/dist/keypad.js +1 -0
- package/dist/kitty-graphics.d.ts +17 -0
- package/dist/kitty-graphics.js +1 -0
- package/dist/mode.d.ts +585 -584
- package/dist/mode.js +1 -245
- package/dist/mouse.d.ts +227 -226
- package/dist/mouse.js +1 -106
- package/dist/notification.d.ts +30 -0
- package/dist/notification.js +1 -0
- package/dist/packem_shared/IT2_AUTO-K3GubKy7.js +1 -0
- package/dist/packem_shared/ITerm2File-BkLc5ipB.js +1 -0
- package/dist/packem_shared/cursor-BXG1O_IE.js +1 -0
- package/dist/packem_shared/restoreCursor-CyaXIMQf.js +2 -0
- package/dist/passthrough.d.ts +74 -73
- package/dist/passthrough.js +1 -29
- package/dist/paste.d.ts +23 -0
- package/dist/paste.js +1 -0
- package/dist/progress.d.ts +37 -36
- package/dist/progress.js +1 -0
- package/dist/reset.d.ts +25 -24
- package/dist/reset.js +1 -4
- package/dist/screen.d.ts +226 -225
- package/dist/screen.js +1 -27
- package/dist/scroll.d.ts +64 -63
- package/dist/scroll.js +1 -18
- package/dist/sixel.d.ts +19 -0
- package/dist/sixel.js +1 -0
- package/dist/status.d.ts +521 -520
- package/dist/status.js +1 -95
- package/dist/strip.d.ts +26 -1
- package/dist/strip.js +1 -13
- package/dist/termcap.d.ts +36 -35
- package/dist/termcap.js +1 -25
- package/dist/title.d.ts +176 -175
- package/dist/title.js +1 -19
- package/dist/urxvt.d.ts +15 -0
- package/dist/urxvt.js +1 -0
- package/dist/window-ops.d.ts +399 -398
- package/dist/window-ops.js +1 -61
- package/dist/xterm.d.ts +167 -84
- package/dist/xterm.js +1 -33
- package/package.json +60 -9
- package/dist/helpers.d.ts +0 -14
- package/dist/iterm2/iterm2-properties.d.ts +0 -135
- package/dist/iterm2/iterm2-sequences.d.ts +0 -96
- package/dist/packem_shared/IT2_AUTO-DyYWsxno.js +0 -6
- package/dist/packem_shared/ITerm2File-CUZDBk99.js +0 -137
- package/dist/packem_shared/constants-CE7WkXh_.js +0 -9
- package/dist/packem_shared/cursor-ChpV7cgs.js +0 -72
- package/dist/packem_shared/resetProgressBar-D9r2s7eV.js +0 -18
- package/dist/packem_shared/restoreCursor-GfYEeJqN.js +0 -323
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a sequence that sets the terminal's default foreground (text) color.
|
|
3
|
+
*
|
|
4
|
+
* The color may be any string the terminal understands for `OSC 10`, such as an
|
|
5
|
+
* X11 color name (`"red"`), a hex value (`"#ff0000"`), or an `XParseColor`
|
|
6
|
+
* string (`"rgb:ff/00/00"`, `"rgba:ff/00/00/ff"`).
|
|
7
|
+
*
|
|
8
|
+
* Sequence: `OSC 10 ; color BEL`
|
|
9
|
+
* @param color The color to set the foreground to.
|
|
10
|
+
* @returns The `OSC 10` escape sequence.
|
|
11
|
+
* @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands}
|
|
12
|
+
*/
|
|
13
|
+
declare const setForegroundColor: (color: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Sequence that queries the terminal's current default foreground color.
|
|
16
|
+
*
|
|
17
|
+
* Sequence: `OSC 10 ; ? BEL`
|
|
18
|
+
*/
|
|
19
|
+
declare const requestForegroundColor: string;
|
|
20
|
+
/**
|
|
21
|
+
* Sequence that resets the terminal's default foreground color to its default.
|
|
22
|
+
*
|
|
23
|
+
* Sequence: `OSC 110 BEL`
|
|
24
|
+
*/
|
|
25
|
+
declare const resetForegroundColor: string;
|
|
26
|
+
/**
|
|
27
|
+
* Returns a sequence that sets the terminal's default background color.
|
|
28
|
+
*
|
|
29
|
+
* The color may be any string the terminal understands for `OSC 11` (X11 color
|
|
30
|
+
* name, hex value, or `XParseColor` string).
|
|
31
|
+
*
|
|
32
|
+
* Sequence: `OSC 11 ; color BEL`
|
|
33
|
+
* @param color The color to set the background to.
|
|
34
|
+
* @returns The `OSC 11` escape sequence.
|
|
35
|
+
*/
|
|
36
|
+
declare const setBackgroundColor: (color: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Sequence that queries the terminal's current default background color.
|
|
39
|
+
*
|
|
40
|
+
* Sequence: `OSC 11 ; ? BEL`
|
|
41
|
+
*/
|
|
42
|
+
declare const requestBackgroundColor: string;
|
|
43
|
+
/**
|
|
44
|
+
* Sequence that resets the terminal's default background color to its default.
|
|
45
|
+
*
|
|
46
|
+
* Sequence: `OSC 111 BEL`
|
|
47
|
+
*/
|
|
48
|
+
declare const resetBackgroundColor: string;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a sequence that sets the terminal's cursor color.
|
|
51
|
+
*
|
|
52
|
+
* The color may be any string the terminal understands for `OSC 12` (X11 color
|
|
53
|
+
* name, hex value, or `XParseColor` string).
|
|
54
|
+
*
|
|
55
|
+
* Sequence: `OSC 12 ; color BEL`
|
|
56
|
+
* @param color The color to set the cursor to.
|
|
57
|
+
* @returns The `OSC 12` escape sequence.
|
|
58
|
+
*/
|
|
59
|
+
declare const setCursorColor: (color: string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Sequence that queries the terminal's current cursor color.
|
|
62
|
+
*
|
|
63
|
+
* Sequence: `OSC 12 ; ? BEL`
|
|
64
|
+
*/
|
|
65
|
+
declare const requestCursorColor: string;
|
|
66
|
+
/**
|
|
67
|
+
* Sequence that resets the terminal's cursor color to its default.
|
|
68
|
+
*
|
|
69
|
+
* Sequence: `OSC 112 BEL`
|
|
70
|
+
*/
|
|
71
|
+
declare const resetCursorColor: string;
|
|
72
|
+
export { requestBackgroundColor, requestCursorColor, requestForegroundColor, resetBackgroundColor, resetCursorColor, resetForegroundColor, setBackgroundColor, setCursorColor, setForegroundColor };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{OSC as r,BEL as o,stripOscTerminators as e}from"./constants.js";const t=$=>`${r}10;${e($)}${o}`,C=`${r}10;?${o}`,u=`${r}110${o}`,l=$=>`${r}11;${e($)}${o}`,n=`${r}11;?${o}`,d=`${r}111${o}`,g=$=>`${r}12;${e($)}${o}`,c=`${r}12;?${o}`,a=`${r}112${o}`;export{n as requestBackgroundColor,c as requestCursorColor,C as requestForegroundColor,d as resetBackgroundColor,a as resetCursorColor,u as resetForegroundColor,l as setBackgroundColor,g as setCursorColor,t as setForegroundColor};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a Select Character Set (SCS) sequence that designates `charset` into
|
|
3
|
+
* one of the G0–G3 character-set slots.
|
|
4
|
+
*
|
|
5
|
+
* `gset` is one of the designator characters (see {@link G0}, {@link G1},
|
|
6
|
+
* {@link G2}, {@link G3} for 94-character sets, or `"-"`, `"."`, `"/"` for the
|
|
7
|
+
* 96-character G1–G3 slots). `charset` selects the final character of the set,
|
|
8
|
+
* e.g. {@link USASCII} (`"B"`), {@link DEC_SPECIAL_GRAPHICS} (`"0"`) or
|
|
9
|
+
* {@link UNITED_KINGDOM} (`"A"`).
|
|
10
|
+
*
|
|
11
|
+
* Sequence: `ESC gset charset`
|
|
12
|
+
* @param gset The G-set designator character.
|
|
13
|
+
* @param charset The final character identifying the character set.
|
|
14
|
+
* @returns The SCS escape sequence.
|
|
15
|
+
* @see {@link https://vt100.net/docs/vt510-rm/SCS.html}
|
|
16
|
+
*/
|
|
17
|
+
declare const selectCharacterSet: (gset: string, charset: string) => string;
|
|
18
|
+
/** Alias for {@link selectCharacterSet} (Select Character Set). */
|
|
19
|
+
declare const SCS: typeof selectCharacterSet;
|
|
20
|
+
/** G0 designator for a 94-character set. */
|
|
21
|
+
declare const G0: string;
|
|
22
|
+
/** G1 designator for a 94-character set. */
|
|
23
|
+
declare const G1: string;
|
|
24
|
+
/** G2 designator for a 94-character set. */
|
|
25
|
+
declare const G2: string;
|
|
26
|
+
/** G3 designator for a 94-character set. */
|
|
27
|
+
declare const G3: string;
|
|
28
|
+
/** DEC Special Character and Line Drawing Set (final character `0`). */
|
|
29
|
+
declare const DEC_SPECIAL_GRAPHICS: string;
|
|
30
|
+
/** United Kingdom character set (final character `A`). */
|
|
31
|
+
declare const UNITED_KINGDOM: string;
|
|
32
|
+
/** United States (USASCII) character set (final character `B`). */
|
|
33
|
+
declare const USASCII: string;
|
|
34
|
+
/** Locking Shift 0 (LS0 / SI): invoke G0 into GL. Sequence: `SI` (`\u000F`). */
|
|
35
|
+
declare const LS0: string;
|
|
36
|
+
/** Alias for {@link LS0} (Shift In). */
|
|
37
|
+
declare const SI: string;
|
|
38
|
+
/** Locking Shift 1 (LS1 / SO): invoke G1 into GL. Sequence: `SO` (`\u000E`). */
|
|
39
|
+
declare const LS1: string;
|
|
40
|
+
/** Alias for {@link LS1} (Shift Out). */
|
|
41
|
+
declare const SO: string;
|
|
42
|
+
/** Locking Shift 1 Right (LS1R): invoke G1 into GR. Sequence: `ESC ~`. */
|
|
43
|
+
declare const LS1R: string;
|
|
44
|
+
/** Locking Shift 2 (LS2): invoke G2 into GL. Sequence: `ESC n`. */
|
|
45
|
+
declare const LS2: string;
|
|
46
|
+
/** Locking Shift 2 Right (LS2R): invoke G2 into GR. Sequence: `ESC }`. */
|
|
47
|
+
declare const LS2R: string;
|
|
48
|
+
/** Locking Shift 3 (LS3): invoke G3 into GL. Sequence: `ESC o`. */
|
|
49
|
+
declare const LS3: string;
|
|
50
|
+
/** Locking Shift 3 Right (LS3R): invoke G3 into GR. Sequence: `ESC |`. */
|
|
51
|
+
declare const LS3R: string;
|
|
52
|
+
export { DEC_SPECIAL_GRAPHICS, G0, G1, G2, G3, LS0, LS1, LS1R, LS2, LS2R, LS3, LS3R, SCS, SI, SO, UNITED_KINGDOM, USASCII, selectCharacterSet };
|
package/dist/charset.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ESC as S}from"./constants.js";const C=(L,$)=>`${S}${L}${$}`,e=C,o="(",r=")",A="*",E="+",R="0",c="A",D="B",I="",_=I,t="",a=t,m=`${S}~`,n=`${S}n`,p=`${S}}`,s=`${S}o`,N=`${S}|`;export{R as DEC_SPECIAL_GRAPHICS,o as G0,r as G1,A as G2,E as G3,I as LS0,t as LS1,m as LS1R,n as LS2,p as LS2R,s as LS3,N as LS3R,e as SCS,_ as SI,a as SO,c as UNITED_KINGDOM,D as USASCII,C as selectCharacterSet};
|
package/dist/clear.d.ts
CHANGED
|
@@ -1,77 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
* Moves the cursor to the top-left (0,0 in 0-indexed terms) and erases from the cursor to the end of the screen.
|
|
3
|
+
*
|
|
4
|
+
* This sequence is a combination of:
|
|
5
|
+
* 1. {@link cursorTo}(0, 0): Moves the cursor to the first row, first column.
|
|
6
|
+
* (Equivalent to `CSI 1;1H` as `cursorTo` uses 0-indexed arguments which are converted to 1-indexed for the sequence).
|
|
7
|
+
* 2. {@link eraseDisplay}({@link EraseDisplayMode.ToEnd}): Erases from the cursor position to the end of the screen (`CSI 0J` or `CSI J`).
|
|
8
|
+
*
|
|
9
|
+
* Effective combined sequence: `CSI 1;1H CSI J` (or `CSI 1;1H CSI 0J`).
|
|
10
|
+
* @see {@link cursorTo}
|
|
11
|
+
* @see {@link eraseDisplay}
|
|
12
|
+
* @see {@link EraseDisplayMode.ToEnd}
|
|
13
|
+
*/
|
|
14
|
+
declare const clearScreenFromTopLeft: string;
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
* Erases the entire current line and moves the cursor to the beginning of that line (column 1).
|
|
17
|
+
*
|
|
18
|
+
* This sequence is a combination of:
|
|
19
|
+
* 1. {@link eraseInLine}({@link EraseLineMode.EntireLine}): Erases the entire current line (`CSI 2K`).
|
|
20
|
+
* 2. `CSI G`: Moves the cursor to column 1 of the current line (Cursor Horizontal Absolute).
|
|
21
|
+
* Alternatively, a carriage return (`\r`) could achieve a similar cursor move to the start of the line on many systems.
|
|
22
|
+
*
|
|
23
|
+
* Effective combined sequence: `CSI 2K CSI G`.
|
|
24
|
+
* @see {@link eraseInLine}
|
|
25
|
+
* @see {@link EraseLineMode.EntireLine}
|
|
26
|
+
*/
|
|
27
|
+
declare const clearLineAndHomeCursor: string;
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
* Homes the cursor to the top-left position (row 1, column 1) and erases the entire screen.
|
|
30
|
+
*
|
|
31
|
+
* This sequence is a combination of:
|
|
32
|
+
* 1. `CSI H`: Moves the cursor to the home position (top-left, equivalent to `CSI 1;1H`).
|
|
33
|
+
* 2. {@link eraseDisplay}({@link EraseDisplayMode.EntireScreen}): Erases the entire screen (`CSI 2J`).
|
|
34
|
+
*
|
|
35
|
+
* Effective combined sequence: `CSI H CSI 2J`.
|
|
36
|
+
* @remarks This is a very common sequence for clearing the visible terminal window.
|
|
37
|
+
* @see `cursorPosition` from `./cursor` (which `CSI H` relates to)
|
|
38
|
+
* @see {@link eraseDisplay}
|
|
39
|
+
* @see {@link EraseDisplayMode.EntireScreen}
|
|
40
|
+
*/
|
|
41
|
+
declare const clearScreenAndHomeCursor: string;
|
|
42
42
|
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
* Clears the entire terminal display, including the scrollback buffer on supported terminals,
|
|
44
|
+
* and attempts to reset the terminal to its initial (or a more pristine) state.
|
|
45
|
+
*
|
|
46
|
+
* This is generally a more comprehensive and forceful clear operation than just erasing the
|
|
47
|
+
* visible screen content (like {@link clearScreenAndHomeCursor}).
|
|
48
|
+
*
|
|
49
|
+
* The exact behavior and sequences used can vary by terminal and operating system:
|
|
50
|
+
*
|
|
51
|
+
* - **On Windows:**
|
|
52
|
+
* It typically uses `CSI 2J` (erase entire screen) followed by `CSI 0f`.
|
|
53
|
+
* `CSI 0f` (or `CSI ;f`, `CSI 0;0f`) is an SGR sequence that also often acts as a cursor home command,
|
|
54
|
+
* though its standardization can be less consistent than `CSI H`.
|
|
55
|
+
* The primary goal is to clear the screen and move the cursor to the top-left.
|
|
56
|
+
*
|
|
57
|
+
* - **On other platforms (e.g., Linux, macOS with XTerm-like terminals):**
|
|
58
|
+
* A more robust combination is used:
|
|
59
|
+
* 1. {@link eraseDisplay}({@link EraseDisplayMode.EntireScreen}) (`CSI 2J`): Erases the entire visible screen.
|
|
60
|
+
* 2. {@link eraseDisplay}({@link EraseDisplayMode.EntireScreenAndScrollback}) (`CSI 3J`): Erases the scrollback buffer (XTerm-specific, but widely supported).
|
|
61
|
+
* 3. `CSI H`: Moves the cursor to the home position (top-left).
|
|
62
|
+
* 4. `ESC c` (RIS - Reset to Initial State): This is the most powerful reset sequence. It typically resets the terminal
|
|
63
|
+
* to its power-on state, clearing character sets, SGR attributes, modes, and more.
|
|
64
|
+
* @returns A string containing the ANSI escape sequence(s) for resetting the terminal.
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { resetTerminal } from '@visulima/ansi/clear';
|
|
68
|
+
*
|
|
69
|
+
* process.stdout.write(resetTerminal);
|
|
70
|
+
* // The terminal attempts a full reset.
|
|
71
|
+
* ```
|
|
72
|
+
* @see {@link eraseDisplay}
|
|
73
|
+
* @see {@link EraseDisplayMode.EntireScreen}
|
|
74
|
+
* @see {@link EraseDisplayMode.EntireScreenAndScrollback}
|
|
75
|
+
* @see {@link https://vt100.net/docs/vt510-rm/RIS.html} RIS documentation.
|
|
76
|
+
*/
|
|
77
|
+
declare const resetTerminal: string;
|
|
78
|
+
export { clearLineAndHomeCursor, clearScreenAndHomeCursor, clearScreenFromTopLeft, resetTerminal };
|
package/dist/clear.js
CHANGED
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { u as cursorTo, A as isWindows } from './packem_shared/cursor-ChpV7cgs.js';
|
|
3
|
-
import { eraseInLine, eraseDisplay, EraseDisplayMode, EraseLineMode } from './erase.js';
|
|
4
|
-
|
|
5
|
-
const clearScreenFromTopLeft = cursorTo(0, 0) + eraseDisplay(EraseDisplayMode.ToEnd);
|
|
6
|
-
const clearLineAndHomeCursor = `${eraseInLine(EraseLineMode.EntireLine)}${CSI}G`;
|
|
7
|
-
const clearScreenAndHomeCursor = `${CSI}H${eraseDisplay(EraseDisplayMode.EntireScreen)}`;
|
|
8
|
-
const resetTerminal = isWindows ? `${eraseDisplay(EraseDisplayMode.EntireScreen)}${CSI}0f` : `${eraseDisplay(EraseDisplayMode.EntireScreen)}${eraseDisplay(EraseDisplayMode.EntireScreenAndScrollback)}${CSI}H${ESC}c`;
|
|
9
|
-
|
|
10
|
-
export { clearLineAndHomeCursor, clearScreenAndHomeCursor, clearScreenFromTopLeft, resetTerminal };
|
|
1
|
+
import{CSI as n,ESC as o}from"./constants.js";import{u as i,A as s}from"./packem_shared/cursor-BXG1O_IE.js";import{eraseInLine as c,eraseDisplay as e,EraseDisplayMode as r,EraseLineMode as a}from"./erase.js";const E=i(0,0)+e(r.ToEnd),S=`${c(a.EntireLine)}${n}G`,l=`${n}H${e(r.EntireScreen)}`,d=s?`${e(r.EntireScreen)}${n}0f`:`${e(r.EntireScreen)}${e(r.EntireScreenAndScrollback)}${n}H${o}c`;export{S as clearLineAndHomeCursor,l as clearScreenAndHomeCursor,E as clearScreenFromTopLeft,d as resetTerminal};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selection targets for OSC 52 clipboard operations.
|
|
3
|
+
*
|
|
4
|
+
* - `c` is the system clipboard (the common default).
|
|
5
|
+
* - `p` is the primary selection (X11 middle-click paste buffer).
|
|
6
|
+
* - `q` is the secondary selection.
|
|
7
|
+
* - `s` is the "select" selection.
|
|
8
|
+
* - `0` to `7` are numbered cut buffers.
|
|
9
|
+
*
|
|
10
|
+
* Multiple targets may be combined (e.g. `"cp"`) to write the same data to
|
|
11
|
+
* several selections at once.
|
|
12
|
+
* @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html}
|
|
13
|
+
*/
|
|
14
|
+
type ClipboardSelection = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "c" | "p" | "q" | "s" | (string & {});
|
|
15
|
+
/**
|
|
16
|
+
* Writes data to the terminal's clipboard using the OSC 52 escape sequence.
|
|
17
|
+
*
|
|
18
|
+
* Sequence: `OSC 52 ; selection ; base64-data ST`
|
|
19
|
+
*
|
|
20
|
+
* OSC 52 is the only clipboard mechanism that works over SSH/tmux, because the
|
|
21
|
+
* write travels in-band over the terminal stream rather than touching a local
|
|
22
|
+
* clipboard API. The terminal emulator must have clipboard writes enabled
|
|
23
|
+
* (e.g. `set-clipboard` in xterm, `allow-passthrough` plus `set-clipboard` in
|
|
24
|
+
* tmux); many enable it by default.
|
|
25
|
+
* @param data The text to place on the clipboard.
|
|
26
|
+
* @param selection The selection target(s). Defaults to `"c"` (system clipboard).
|
|
27
|
+
* @param terminator The OSC terminator to use. Defaults to {@link BEL}; pass
|
|
28
|
+
* {@link ST} (`ESC backslash`) for terminals that require the canonical String Terminator.
|
|
29
|
+
* @returns The OSC 52 escape sequence.
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* import { setClipboard } from "@visulima/ansi/clipboard";
|
|
33
|
+
*
|
|
34
|
+
* // Copy a generated token to the user's local clipboard from a remote shell.
|
|
35
|
+
* process.stdout.write(setClipboard("my-secret-token"));
|
|
36
|
+
* ```
|
|
37
|
+
* @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html}
|
|
38
|
+
*/
|
|
39
|
+
declare const setClipboard: (data: string, selection?: ClipboardSelection, terminator?: string) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Requests the current contents of the terminal's clipboard via OSC 52.
|
|
42
|
+
*
|
|
43
|
+
* Sequence: `OSC 52 ; selection ; ? ST`
|
|
44
|
+
*
|
|
45
|
+
* The terminal responds with `OSC 52 ; selection ; base64-data ST` if it
|
|
46
|
+
* permits clipboard reads (frequently disabled for security). Decode the
|
|
47
|
+
* Base64 payload from the response to obtain the clipboard text.
|
|
48
|
+
* @param selection The selection target to query. Defaults to `"c"` (system clipboard).
|
|
49
|
+
* @param terminator The OSC terminator to use. Defaults to {@link BEL}; pass {@link ST} for terminals that require it.
|
|
50
|
+
* @returns The OSC 52 query escape sequence.
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { requestClipboard } from "@visulima/ansi/clipboard";
|
|
54
|
+
*
|
|
55
|
+
* process.stdout.write(requestClipboard());
|
|
56
|
+
* ```
|
|
57
|
+
* @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html}
|
|
58
|
+
*/
|
|
59
|
+
declare const requestClipboard: (selection?: ClipboardSelection, terminator?: string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Clears the terminal's clipboard for the given selection via OSC 52.
|
|
62
|
+
*
|
|
63
|
+
* Sequence: `OSC 52 ; selection ; ST` (an empty payload clears the selection).
|
|
64
|
+
* @param selection The selection target to clear. Defaults to `"c"` (system clipboard).
|
|
65
|
+
* @param terminator The OSC terminator to use. Defaults to {@link BEL}; pass {@link ST} for terminals that require it.
|
|
66
|
+
* @returns The OSC 52 clear escape sequence.
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { clearClipboard } from "@visulima/ansi/clipboard";
|
|
70
|
+
*
|
|
71
|
+
* process.stdout.write(clearClipboard());
|
|
72
|
+
* ```
|
|
73
|
+
* @see {@link https://invisible-island.net/xterm/ctlseqs/ctlseqs.html}
|
|
74
|
+
*/
|
|
75
|
+
declare const clearClipboard: (selection?: ClipboardSelection, terminator?: string) => string;
|
|
76
|
+
export { ClipboardSelection, clearClipboard, requestClipboard, setClipboard };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{OSC as e,BEL as n}from"./constants.js";const f=r=>{const o=new TextEncoder().encode(r),t=o.toBase64;if(typeof t=="function")return t.call(o);if(typeof btoa=="function"){let i="";for(const c of o)i+=String.fromCodePoint(c);return btoa(i)}const a=globalThis.Buffer;if(a===void 0)throw new Error("No Base64 encoder available: Uint8Array.prototype.toBase64, btoa and Buffer are all missing.");return a.from(o).toString("base64")},l=(r,o="c",t=n)=>`${e}52;${o};${f(r)}${t}`,$=(r="c",o=n)=>`${e}52;${r};?${o}`,b=(r="c",o=n)=>`${e}52;${r};${o}`;export{b as clearClipboard,$ as requestClipboard,l as setClipboard};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
/** Escape character (\u001B). */
|
|
2
|
-
|
|
2
|
+
declare const ESC: string;
|
|
3
3
|
/** Control Sequence Introducer (ESC [). */
|
|
4
|
-
|
|
4
|
+
declare const CSI: string;
|
|
5
5
|
/** Operating System Command (ESC ]). */
|
|
6
|
-
|
|
6
|
+
declare const OSC: string;
|
|
7
7
|
/** Bell character (\u0007). Often used to terminate OSC sequences. */
|
|
8
|
-
|
|
8
|
+
declare const BEL: string;
|
|
9
9
|
/** Separator used in some ANSI sequences, typically a semicolon. */
|
|
10
|
-
|
|
10
|
+
declare const SEP: string;
|
|
11
11
|
/** Device Control String (ESC P). */
|
|
12
|
-
|
|
12
|
+
declare const DCS: string;
|
|
13
13
|
/** String Terminator (ESC \\). Used to terminate DCS, SOS, PM, APC sequences. */
|
|
14
|
-
|
|
14
|
+
declare const ST: string;
|
|
15
15
|
/** Application Program Command (ESC _). */
|
|
16
|
-
|
|
16
|
+
declare const APC: string;
|
|
17
17
|
/** Start of String (ESC X). */
|
|
18
|
-
|
|
18
|
+
declare const SOS: string;
|
|
19
19
|
/** Privacy Message (ESC ^). */
|
|
20
|
-
|
|
20
|
+
declare const PM: string;
|
|
21
|
+
/**
|
|
22
|
+
* Strips OSC terminators (BEL, ESC) from a caller-supplied value so it cannot
|
|
23
|
+
* inject or prematurely terminate an escape sequence when interpolated into one.
|
|
24
|
+
* @param value The untrusted string to sanitize.
|
|
25
|
+
* @returns `value` with all BEL and ESC characters removed.
|
|
26
|
+
*/
|
|
27
|
+
declare const stripOscTerminators: (value: string) => string;
|
|
28
|
+
export { APC, BEL, CSI, DCS, ESC, OSC, PM, SEP, SOS, ST, stripOscTerminators };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const B="\x1B",S="\x1B[",r="\x1B]",C="\x07",e=";",s="\x1BP",t="\x1B\\",P="\x1B_",c="\x1BX",l="\x1B^",o=x=>x.replaceAll(/[\u0007\u001B]/g,"");export{P as APC,C as BEL,S as CSI,s as DCS,B as ESC,r as OSC,l as PM,e as SEP,c as SOS,t as ST,o as stripOscTerminators};
|