@visulima/ansi 4.0.0-alpha.1 → 4.0.0-alpha.2
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 +16 -0
- package/README.md +32 -14
- package/package.json +9 -7
- package/dist/alternative-screen.d.ts +0 -74
- package/dist/alternative-screen.js +0 -8
- package/dist/clear.d.ts +0 -77
- package/dist/clear.js +0 -16
- package/dist/constants.d.ts +0 -20
- package/dist/cursor.d.ts +0 -437
- package/dist/cursor.js +0 -3
- package/dist/erase.d.ts +0 -206
- package/dist/erase.js +0 -47
- package/dist/helpers.d.ts +0 -14
- package/dist/hyperlink.d.ts +0 -27
- package/dist/hyperlink.js +0 -5
- package/dist/image.d.ts +0 -73
- package/dist/image.js +0 -43
- package/dist/index.d.ts +0 -36
- package/dist/index.js +0 -26
- package/dist/iterm2/iterm2-properties.d.ts +0 -135
- package/dist/iterm2/iterm2-sequences.d.ts +0 -96
- package/dist/iterm2.d.ts +0 -58
- package/dist/iterm2.js +0 -12
- package/dist/mode.d.ts +0 -726
- package/dist/mode.js +0 -245
- package/dist/mouse.d.ts +0 -230
- package/dist/mouse.js +0 -106
- package/dist/packem_shared/IT2_AUTO-BGxGtZAE.js +0 -6
- package/dist/packem_shared/ITerm2File-DzWaT6j3.js +0 -137
- package/dist/packem_shared/constants-CE7WkXh_.js +0 -9
- package/dist/packem_shared/cursor-CHPvxMal.js +0 -71
- package/dist/packem_shared/resetProgressBar-kV21u2hs.js +0 -18
- package/dist/packem_shared/restoreCursor-GfYEeJqN.js +0 -323
- package/dist/passthrough.d.ts +0 -77
- package/dist/passthrough.js +0 -29
- package/dist/progress.d.ts +0 -41
- package/dist/reset.d.ts +0 -26
- package/dist/reset.js +0 -4
- package/dist/screen.d.ts +0 -234
- package/dist/screen.js +0 -27
- package/dist/scroll.d.ts +0 -67
- package/dist/scroll.js +0 -18
- package/dist/status.d.ts +0 -524
- package/dist/status.js +0 -98
- package/dist/strip.d.ts +0 -23
- package/dist/strip.js +0 -12
- package/dist/termcap.d.ts +0 -38
- package/dist/termcap.js +0 -25
- package/dist/title.d.ts +0 -185
- package/dist/title.js +0 -18
- package/dist/window-ops.d.ts +0 -418
- package/dist/window-ops.js +0 -61
- package/dist/xterm.d.ts +0 -94
- package/dist/xterm.js +0 -33
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
Buffer
|
|
22
|
-
} = __cjs_getBuiltinModule("node:buffer");
|
|
23
|
-
|
|
24
|
-
const formatITerm2FileProperties = (properties) => {
|
|
25
|
-
const options = [];
|
|
26
|
-
if (properties.name) {
|
|
27
|
-
options.push(`name=${properties.name}`);
|
|
28
|
-
}
|
|
29
|
-
if (properties.size !== void 0) {
|
|
30
|
-
options.push(`size=${properties.size}`);
|
|
31
|
-
}
|
|
32
|
-
if (properties.width !== void 0) {
|
|
33
|
-
options.push(`width=${properties.width.toString()}`);
|
|
34
|
-
}
|
|
35
|
-
if (properties.height !== void 0) {
|
|
36
|
-
options.push(`height=${properties.height.toString()}`);
|
|
37
|
-
}
|
|
38
|
-
if (properties.ignoreAspectRatio) {
|
|
39
|
-
options.push("preserveAspectRatio=0");
|
|
40
|
-
}
|
|
41
|
-
if (properties.inline) {
|
|
42
|
-
options.push("inline=1");
|
|
43
|
-
}
|
|
44
|
-
if (properties.doNotMoveCursor) {
|
|
45
|
-
options.push("doNotMoveCursor=1");
|
|
46
|
-
}
|
|
47
|
-
return options.join(";");
|
|
48
|
-
};
|
|
49
|
-
class ITerm2File {
|
|
50
|
-
fileProps;
|
|
51
|
-
/**
|
|
52
|
-
* Constructs an `ITerm2File` payload object.
|
|
53
|
-
* @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProps}.
|
|
54
|
-
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
55
|
-
* contain special characters (like `;`, `=`, or non-ASCII characters).
|
|
56
|
-
* If `fileData` is provided, `props.content` will be overridden, and `props.size` will be
|
|
57
|
-
* set from `fileData.byteLength` if not already present in `props`.
|
|
58
|
-
* @param fileData (Optional) A `Uint8Array` containing the raw file data. If provided, this data will be
|
|
59
|
-
* Base64 encoded and used as the `content` of the file transfer. The `size` property
|
|
60
|
-
* will also be automatically set from `fileData.byteLength` if not specified in `props`.
|
|
61
|
-
*/
|
|
62
|
-
constructor(properties, fileData) {
|
|
63
|
-
this.fileProps = { ...properties };
|
|
64
|
-
if (fileData) {
|
|
65
|
-
if (fileData.byteLength > 10 * 1024 * 1024) {
|
|
66
|
-
throw new Error("File size exceeds maximum limit of 10MB");
|
|
67
|
-
}
|
|
68
|
-
this.fileProps.content = Buffer.from(fileData).toString("base64");
|
|
69
|
-
if (this.fileProps.size === void 0) {
|
|
70
|
-
this.fileProps.size = fileData.byteLength;
|
|
71
|
-
}
|
|
72
|
-
if (this.fileProps.size !== fileData.byteLength) {
|
|
73
|
-
throw new Error("File size property doesn't match actual data length");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Converts the file properties and its content (if any) into the string payload
|
|
79
|
-
* suitable for the iTerm2 `File=` command.
|
|
80
|
-
* @returns The string payload (e.g., `"File=name=...;size=...:BASE64_CONTENT"` or `"File=name=...;size=..."`).
|
|
81
|
-
*/
|
|
82
|
-
toString() {
|
|
83
|
-
let s = "File=";
|
|
84
|
-
s += formatITerm2FileProperties(this.fileProps);
|
|
85
|
-
if (this.fileProps.content !== void 0) {
|
|
86
|
-
s += `:${this.fileProps.content}`;
|
|
87
|
-
}
|
|
88
|
-
return s;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
class ITerm2FileEnd {
|
|
92
|
-
/**
|
|
93
|
-
* Generates the string payload for the iTerm2 `FileEnd` command.
|
|
94
|
-
* @returns The string `"FileEnd"`.
|
|
95
|
-
*/
|
|
96
|
-
// eslint-disable-next-line class-methods-use-this
|
|
97
|
-
toString() {
|
|
98
|
-
return "FileEnd";
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
class ITerm2FilePart {
|
|
102
|
-
/**
|
|
103
|
-
* Constructs an `ITerm2FilePart` payload object.
|
|
104
|
-
* @param base64Chunk A string containing a Base64 encoded chunk of the file data.
|
|
105
|
-
* The caller is responsible for chunking the file and Base64 encoding each chunk.
|
|
106
|
-
*/
|
|
107
|
-
constructor(base64Chunk) {
|
|
108
|
-
this.base64Chunk = base64Chunk;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Converts the Base64 encoded chunk into the string payload suitable for the iTerm2 `FilePart=` command.
|
|
112
|
-
* @returns The string payload (e.g., `"FilePart=U09NRURBVEE="`).
|
|
113
|
-
*/
|
|
114
|
-
toString() {
|
|
115
|
-
return `FilePart=${this.base64Chunk}`;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
class ITerm2MultipartFileStart {
|
|
119
|
-
/**
|
|
120
|
-
* Constructs an `ITerm2MultipartFileStart` payload object.
|
|
121
|
-
* @param properties Properties for the multipart file (e.g., `name`, `size`). Content is not part of this command.
|
|
122
|
-
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
123
|
-
* contain special characters.
|
|
124
|
-
*/
|
|
125
|
-
constructor(properties) {
|
|
126
|
-
this.properties = properties;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Converts the file properties into the string payload suitable for the iTerm2 `MultipartFile=` command.
|
|
130
|
-
* @returns The string payload (e.g., `"MultipartFile=name=...;size=..."`).
|
|
131
|
-
*/
|
|
132
|
-
toString() {
|
|
133
|
-
return `MultipartFile=${formatITerm2FileProperties(this.properties)}`;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export { ITerm2File, ITerm2FileEnd, ITerm2FilePart, ITerm2MultipartFileStart };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { C as CSI, E as ESC, S as SEP } from './constants-CE7WkXh_.js';
|
|
2
|
-
import './restoreCursor-GfYEeJqN.js';
|
|
3
|
-
|
|
4
|
-
const isBrowser = globalThis?.window?.document !== void 0;
|
|
5
|
-
const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === "Apple_Terminal";
|
|
6
|
-
const isWindows = !isBrowser && (process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE));
|
|
7
|
-
|
|
8
|
-
const SAVE_CURSOR_DEC = `${ESC}7`;
|
|
9
|
-
const RESTORE_CURSOR_DEC = `${ESC}8`;
|
|
10
|
-
const CURSOR_UP_1 = `${CSI}A`;
|
|
11
|
-
const CURSOR_DOWN_1 = `${CSI}B`;
|
|
12
|
-
const CURSOR_FORWARD_1 = `${CSI}C`;
|
|
13
|
-
const CURSOR_BACKWARD_1 = `${CSI}D`;
|
|
14
|
-
const REQUEST_CURSOR_POSITION = `${CSI}6n`;
|
|
15
|
-
const REQUEST_EXTENDED_CURSOR_POSITION = `${CSI}?6n`;
|
|
16
|
-
const cursorBackward = (count = 1) => `${CSI + count}D`;
|
|
17
|
-
const cursorDown = (count = 1) => `${CSI + count}B`;
|
|
18
|
-
const cursorForward = (count = 1) => `${CSI + count}C`;
|
|
19
|
-
const cursorHide = `${CSI}?25l`;
|
|
20
|
-
const cursorToColumn1 = `${CSI}G`;
|
|
21
|
-
const cursorLeft = (count = 1) => cursorBackward(count);
|
|
22
|
-
const cursorHorizontalAbsolute = (column = 1) => `${CSI + column}G`;
|
|
23
|
-
const cursorMove = (x, y) => {
|
|
24
|
-
let returnValue = "";
|
|
25
|
-
if (x < 0) {
|
|
26
|
-
returnValue += `${CSI + -x}D`;
|
|
27
|
-
} else if (x > 0) {
|
|
28
|
-
returnValue += `${CSI + x}C`;
|
|
29
|
-
}
|
|
30
|
-
if (y < 0) {
|
|
31
|
-
returnValue += `${CSI + -y}A`;
|
|
32
|
-
} else if (y > 0) {
|
|
33
|
-
returnValue += `${CSI + y}B`;
|
|
34
|
-
}
|
|
35
|
-
return returnValue;
|
|
36
|
-
};
|
|
37
|
-
const cursorNextLine = (count = 1) => `${CSI + count}E`;
|
|
38
|
-
const cursorPreviousLine = (count = 1) => `${CSI + count}F`;
|
|
39
|
-
const cursorRestore = isTerminalApp ? RESTORE_CURSOR_DEC : `${ESC}u`;
|
|
40
|
-
const cursorSave = isTerminalApp ? SAVE_CURSOR_DEC : `${ESC}s`;
|
|
41
|
-
const cursorShow = `${CSI}?25h`;
|
|
42
|
-
const cursorTo = (x, y) => {
|
|
43
|
-
if (y === void 0) {
|
|
44
|
-
return cursorHorizontalAbsolute(x + 1);
|
|
45
|
-
}
|
|
46
|
-
return `${CSI + (y + 1) + SEP + (x + 1)}H`;
|
|
47
|
-
};
|
|
48
|
-
const cursorPosition = (row, column) => {
|
|
49
|
-
if (column === void 0) {
|
|
50
|
-
return `${CSI + row}H`;
|
|
51
|
-
}
|
|
52
|
-
return `${CSI + row + SEP + column}H`;
|
|
53
|
-
};
|
|
54
|
-
const cursorHorizontalForwardTab = (count = 1) => `${CSI + count}I`;
|
|
55
|
-
const cursorBackwardTab = (count = 1) => `${CSI + count}Z`;
|
|
56
|
-
const eraseCharacter = (count = 1) => `${CSI + count}X`;
|
|
57
|
-
const cursorVerticalAbsolute = (row = 1) => `${CSI + row}d`;
|
|
58
|
-
const cursorUp = (count = 1) => `${CSI + count}A`;
|
|
59
|
-
var CursorStyle = /* @__PURE__ */ ((CursorStyle2) => {
|
|
60
|
-
CursorStyle2[CursorStyle2["BlinkingBar"] = 5] = "BlinkingBar";
|
|
61
|
-
CursorStyle2[CursorStyle2["BlinkingBlock"] = 1] = "BlinkingBlock";
|
|
62
|
-
CursorStyle2[CursorStyle2["BlinkingUnderline"] = 3] = "BlinkingUnderline";
|
|
63
|
-
CursorStyle2[CursorStyle2["Default"] = 0] = "Default";
|
|
64
|
-
CursorStyle2[CursorStyle2["SteadyBar"] = 6] = "SteadyBar";
|
|
65
|
-
CursorStyle2[CursorStyle2["SteadyBlock"] = 2] = "SteadyBlock";
|
|
66
|
-
CursorStyle2[CursorStyle2["SteadyUnderline"] = 4] = "SteadyUnderline";
|
|
67
|
-
return CursorStyle2;
|
|
68
|
-
})(CursorStyle || {});
|
|
69
|
-
const setCursorStyle = (style) => `${CSI + style} q`;
|
|
70
|
-
|
|
71
|
-
export { isWindows as A, CursorStyle as B, CURSOR_BACKWARD_1 as C, REQUEST_CURSOR_POSITION as R, SAVE_CURSOR_DEC as S, CURSOR_DOWN_1 as a, CURSOR_FORWARD_1 as b, CURSOR_UP_1 as c, cursorBackward as d, cursorBackwardTab as e, cursorDown as f, cursorForward as g, cursorHide as h, cursorHorizontalAbsolute as i, cursorHorizontalForwardTab as j, cursorLeft as k, cursorMove as l, cursorNextLine as m, cursorPosition as n, cursorPreviousLine as o, cursorRestore as p, cursorSave as q, cursorShow as r, cursorTo as s, cursorToColumn1 as t, cursorUp as u, cursorVerticalAbsolute as v, eraseCharacter as w, REQUEST_EXTENDED_CURSOR_POSITION as x, RESTORE_CURSOR_DEC as y, setCursorStyle as z };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { O as OSC, B as BEL } from './constants-CE7WkXh_.js';
|
|
2
|
-
|
|
3
|
-
const resetProgressBar = `${OSC}9;4;0${BEL}`;
|
|
4
|
-
const setProgressBar = (percentage) => {
|
|
5
|
-
const clamped = Math.min(Math.max(0, percentage), 100);
|
|
6
|
-
return `${OSC}9;4;1;${clamped}${BEL}`;
|
|
7
|
-
};
|
|
8
|
-
const setErrorProgressBar = (percentage) => {
|
|
9
|
-
const clamped = Math.min(Math.max(0, percentage), 100);
|
|
10
|
-
return `${OSC}9;4;2;${clamped}${BEL}`;
|
|
11
|
-
};
|
|
12
|
-
const setIndeterminateProgressBar = `${OSC}9;4;3${BEL}`;
|
|
13
|
-
const setWarningProgressBar = (percentage) => {
|
|
14
|
-
const clamped = Math.min(Math.max(0, percentage), 100);
|
|
15
|
-
return `${OSC}9;4;4;${clamped}${BEL}`;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { resetProgressBar, setErrorProgressBar, setIndeterminateProgressBar, setProgressBar, setWarningProgressBar };
|
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const process$2 = __cjs_getProcess;
|
|
8
|
-
|
|
9
|
-
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
|
|
10
|
-
if (property === "length" || property === "prototype") {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (property === "arguments" || property === "caller") {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
|
|
17
|
-
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
|
|
18
|
-
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
Object.defineProperty(to, property, fromDescriptor);
|
|
22
|
-
};
|
|
23
|
-
const canCopyProperty = function(toDescriptor, fromDescriptor) {
|
|
24
|
-
return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
|
|
25
|
-
};
|
|
26
|
-
const changePrototype = (to, from) => {
|
|
27
|
-
const fromPrototype = Object.getPrototypeOf(from);
|
|
28
|
-
if (fromPrototype === Object.getPrototypeOf(to)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
Object.setPrototypeOf(to, fromPrototype);
|
|
32
|
-
};
|
|
33
|
-
const wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/
|
|
34
|
-
${fromBody}`;
|
|
35
|
-
const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
|
|
36
|
-
const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
|
|
37
|
-
const changeToString = (to, from, name) => {
|
|
38
|
-
const withName = name === "" ? "" : `with ${name.trim()}() `;
|
|
39
|
-
const newToString = wrappedToString.bind(null, withName, from.toString());
|
|
40
|
-
Object.defineProperty(newToString, "name", toStringName);
|
|
41
|
-
const { writable, enumerable, configurable } = toStringDescriptor;
|
|
42
|
-
Object.defineProperty(to, "toString", { value: newToString, writable, enumerable, configurable });
|
|
43
|
-
};
|
|
44
|
-
function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
|
|
45
|
-
const { name } = to;
|
|
46
|
-
for (const property of Reflect.ownKeys(from)) {
|
|
47
|
-
copyProperty(to, from, property, ignoreNonConfigurable);
|
|
48
|
-
}
|
|
49
|
-
changePrototype(to, from);
|
|
50
|
-
changeToString(to, from, name);
|
|
51
|
-
return to;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const calledFunctions = /* @__PURE__ */ new WeakMap();
|
|
55
|
-
const onetime = (function_, options = {}) => {
|
|
56
|
-
if (typeof function_ !== "function") {
|
|
57
|
-
throw new TypeError("Expected a function");
|
|
58
|
-
}
|
|
59
|
-
let returnValue;
|
|
60
|
-
let callCount = 0;
|
|
61
|
-
const functionName = function_.displayName || function_.name || "<anonymous>";
|
|
62
|
-
const onetime2 = function(...arguments_) {
|
|
63
|
-
calledFunctions.set(onetime2, ++callCount);
|
|
64
|
-
if (callCount === 1) {
|
|
65
|
-
returnValue = function_.apply(this, arguments_);
|
|
66
|
-
function_ = void 0;
|
|
67
|
-
} else if (options.throw === true) {
|
|
68
|
-
throw new Error(`Function \`${functionName}\` can only be called once`);
|
|
69
|
-
}
|
|
70
|
-
return returnValue;
|
|
71
|
-
};
|
|
72
|
-
mimicFunction(onetime2, function_);
|
|
73
|
-
calledFunctions.set(onetime2, callCount);
|
|
74
|
-
return onetime2;
|
|
75
|
-
};
|
|
76
|
-
onetime.callCount = (function_) => {
|
|
77
|
-
if (!calledFunctions.has(function_)) {
|
|
78
|
-
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
|
|
79
|
-
}
|
|
80
|
-
return calledFunctions.get(function_);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const signals = [];
|
|
84
|
-
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
85
|
-
if (process.platform !== "win32") {
|
|
86
|
-
signals.push(
|
|
87
|
-
"SIGALRM",
|
|
88
|
-
"SIGABRT",
|
|
89
|
-
"SIGVTALRM",
|
|
90
|
-
"SIGXCPU",
|
|
91
|
-
"SIGXFSZ",
|
|
92
|
-
"SIGUSR2",
|
|
93
|
-
"SIGTRAP",
|
|
94
|
-
"SIGSYS",
|
|
95
|
-
"SIGQUIT",
|
|
96
|
-
"SIGIOT"
|
|
97
|
-
// should detect profiler and enable/disable accordingly.
|
|
98
|
-
// see #21
|
|
99
|
-
// 'SIGPROF'
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
if (process.platform === "linux") {
|
|
103
|
-
signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const processOk = (process2) => !!process2 && true && typeof process2.removeListener === "function" && typeof process2.emit === "function" && typeof process2.reallyExit === "function" && typeof process2.listeners === "function" && typeof process2.kill === "function" && typeof process2.pid === "number" && typeof process2.on === "function";
|
|
107
|
-
const kExitEmitter = /* @__PURE__ */ Symbol.for("signal-exit emitter");
|
|
108
|
-
const global = globalThis;
|
|
109
|
-
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
110
|
-
class Emitter {
|
|
111
|
-
emitted = {
|
|
112
|
-
afterExit: false,
|
|
113
|
-
exit: false
|
|
114
|
-
};
|
|
115
|
-
listeners = {
|
|
116
|
-
afterExit: [],
|
|
117
|
-
exit: []
|
|
118
|
-
};
|
|
119
|
-
count = 0;
|
|
120
|
-
id = Math.random();
|
|
121
|
-
constructor() {
|
|
122
|
-
if (global[kExitEmitter]) {
|
|
123
|
-
return global[kExitEmitter];
|
|
124
|
-
}
|
|
125
|
-
ObjectDefineProperty(global, kExitEmitter, {
|
|
126
|
-
value: this,
|
|
127
|
-
writable: false,
|
|
128
|
-
enumerable: false,
|
|
129
|
-
configurable: false
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
on(ev, fn) {
|
|
133
|
-
this.listeners[ev].push(fn);
|
|
134
|
-
}
|
|
135
|
-
removeListener(ev, fn) {
|
|
136
|
-
const list = this.listeners[ev];
|
|
137
|
-
const i = list.indexOf(fn);
|
|
138
|
-
if (i === -1) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (i === 0 && list.length === 1) {
|
|
142
|
-
list.length = 0;
|
|
143
|
-
} else {
|
|
144
|
-
list.splice(i, 1);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
emit(ev, code, signal) {
|
|
148
|
-
if (this.emitted[ev]) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
this.emitted[ev] = true;
|
|
152
|
-
let ret = false;
|
|
153
|
-
for (const fn of this.listeners[ev]) {
|
|
154
|
-
ret = fn(code, signal) === true || ret;
|
|
155
|
-
}
|
|
156
|
-
if (ev === "exit") {
|
|
157
|
-
ret = this.emit("afterExit", code, signal) || ret;
|
|
158
|
-
}
|
|
159
|
-
return ret;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
class SignalExitBase {
|
|
163
|
-
}
|
|
164
|
-
const signalExitWrap = (handler) => {
|
|
165
|
-
return {
|
|
166
|
-
onExit(cb, opts) {
|
|
167
|
-
return handler.onExit(cb, opts);
|
|
168
|
-
},
|
|
169
|
-
load() {
|
|
170
|
-
return handler.load();
|
|
171
|
-
},
|
|
172
|
-
unload() {
|
|
173
|
-
return handler.unload();
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
class SignalExitFallback extends SignalExitBase {
|
|
178
|
-
onExit() {
|
|
179
|
-
return () => {
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
load() {
|
|
183
|
-
}
|
|
184
|
-
unload() {
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
class SignalExit extends SignalExitBase {
|
|
188
|
-
// "SIGHUP" throws an `ENOSYS` error on Windows,
|
|
189
|
-
// so use a supported signal instead
|
|
190
|
-
/* c8 ignore start */
|
|
191
|
-
#hupSig = process$1.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
192
|
-
/* c8 ignore stop */
|
|
193
|
-
#emitter = new Emitter();
|
|
194
|
-
#process;
|
|
195
|
-
#originalProcessEmit;
|
|
196
|
-
#originalProcessReallyExit;
|
|
197
|
-
#sigListeners = {};
|
|
198
|
-
#loaded = false;
|
|
199
|
-
constructor(process2) {
|
|
200
|
-
super();
|
|
201
|
-
this.#process = process2;
|
|
202
|
-
this.#sigListeners = {};
|
|
203
|
-
for (const sig of signals) {
|
|
204
|
-
this.#sigListeners[sig] = () => {
|
|
205
|
-
const listeners = this.#process.listeners(sig);
|
|
206
|
-
let { count } = this.#emitter;
|
|
207
|
-
const p = process2;
|
|
208
|
-
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
|
|
209
|
-
count += p.__signal_exit_emitter__.count;
|
|
210
|
-
}
|
|
211
|
-
if (listeners.length === count) {
|
|
212
|
-
this.unload();
|
|
213
|
-
const ret = this.#emitter.emit("exit", null, sig);
|
|
214
|
-
const s = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
215
|
-
if (!ret)
|
|
216
|
-
process2.kill(process2.pid, s);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
this.#originalProcessReallyExit = process2.reallyExit;
|
|
221
|
-
this.#originalProcessEmit = process2.emit;
|
|
222
|
-
}
|
|
223
|
-
onExit(cb, opts) {
|
|
224
|
-
if (!processOk(this.#process)) {
|
|
225
|
-
return () => {
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
if (this.#loaded === false) {
|
|
229
|
-
this.load();
|
|
230
|
-
}
|
|
231
|
-
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
232
|
-
this.#emitter.on(ev, cb);
|
|
233
|
-
return () => {
|
|
234
|
-
this.#emitter.removeListener(ev, cb);
|
|
235
|
-
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
|
|
236
|
-
this.unload();
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
load() {
|
|
241
|
-
if (this.#loaded) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.#loaded = true;
|
|
245
|
-
this.#emitter.count += 1;
|
|
246
|
-
for (const sig of signals) {
|
|
247
|
-
try {
|
|
248
|
-
const fn = this.#sigListeners[sig];
|
|
249
|
-
if (fn)
|
|
250
|
-
this.#process.on(sig, fn);
|
|
251
|
-
} catch (_) {
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
this.#process.emit = (ev, ...a) => {
|
|
255
|
-
return this.#processEmit(ev, ...a);
|
|
256
|
-
};
|
|
257
|
-
this.#process.reallyExit = (code) => {
|
|
258
|
-
return this.#processReallyExit(code);
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
unload() {
|
|
262
|
-
if (!this.#loaded) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
this.#loaded = false;
|
|
266
|
-
signals.forEach((sig) => {
|
|
267
|
-
const listener = this.#sigListeners[sig];
|
|
268
|
-
if (!listener) {
|
|
269
|
-
throw new Error("Listener not defined for signal: " + sig);
|
|
270
|
-
}
|
|
271
|
-
try {
|
|
272
|
-
this.#process.removeListener(sig, listener);
|
|
273
|
-
} catch (_) {
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
this.#process.emit = this.#originalProcessEmit;
|
|
277
|
-
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
278
|
-
this.#emitter.count -= 1;
|
|
279
|
-
}
|
|
280
|
-
#processReallyExit(code) {
|
|
281
|
-
if (!processOk(this.#process)) {
|
|
282
|
-
return 0;
|
|
283
|
-
}
|
|
284
|
-
this.#process.exitCode = code || 0;
|
|
285
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
286
|
-
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
287
|
-
}
|
|
288
|
-
#processEmit(ev, ...args) {
|
|
289
|
-
const og = this.#originalProcessEmit;
|
|
290
|
-
if (ev === "exit" && processOk(this.#process)) {
|
|
291
|
-
if (typeof args[0] === "number") {
|
|
292
|
-
this.#process.exitCode = args[0];
|
|
293
|
-
}
|
|
294
|
-
const ret = og.call(this.#process, ev, ...args);
|
|
295
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
296
|
-
return ret;
|
|
297
|
-
} else {
|
|
298
|
-
return og.call(this.#process, ev, ...args);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
const process$1 = globalThis.process;
|
|
303
|
-
const {
|
|
304
|
-
/**
|
|
305
|
-
* Called when the process is exiting, whether via signal, explicit
|
|
306
|
-
* exit, or running out of stuff to do.
|
|
307
|
-
*
|
|
308
|
-
* If the global process object is not suitable for instrumentation,
|
|
309
|
-
* then this will be a no-op.
|
|
310
|
-
*
|
|
311
|
-
* Returns a function that may be used to unload signal-exit.
|
|
312
|
-
*/
|
|
313
|
-
onExit} = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
|
|
314
|
-
|
|
315
|
-
const terminal = process$2.stderr.isTTY ? process$2.stderr : process$2.stdout.isTTY ? process$2.stdout : void 0;
|
|
316
|
-
const restoreCursor = terminal ? onetime(() => {
|
|
317
|
-
onExit(() => {
|
|
318
|
-
terminal.write("\x1B[?25h");
|
|
319
|
-
}, { alwaysLast: true });
|
|
320
|
-
}) : () => {
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
export { restoreCursor as default };
|
package/dist/passthrough.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default value for the `limit` parameter in {@link screenPassthrough}, indicating no chunking.
|
|
3
|
-
* When this value is used (or any value <= 0), the passthrough sequence is not split into smaller chunks.
|
|
4
|
-
*/
|
|
5
|
-
export declare const SCREEN_MAX_LEN_DEFAULT: number;
|
|
6
|
-
/**
|
|
7
|
-
* A typical limit for string sequences in GNU Screen (e.g., 768 bytes).
|
|
8
|
-
* This constant can be used as a practical value for the `limit` parameter in {@link screenPassthrough}
|
|
9
|
-
* to avoid issues with Screen's internal buffers, though the function itself defaults to no limit.
|
|
10
|
-
* It's provided for informational purposes and as a suggested practical chunking limit.
|
|
11
|
-
*/
|
|
12
|
-
export declare const SCREEN_TYPICAL_LIMIT: number;
|
|
13
|
-
/**
|
|
14
|
-
* Wraps a given ANSI escape sequence in a DCS (Device Control String) passthrough sequence
|
|
15
|
-
* specifically for GNU Screen. This allows raw escape sequences to be sent to the
|
|
16
|
-
* terminal emulator that is hosting Screen, bypassing Screen's own interpretation.
|
|
17
|
-
*
|
|
18
|
-
* The basic format is: `DCS <data> ST` (where `DCS` is `ESC P` and `ST` is `ESC \`).
|
|
19
|
-
*
|
|
20
|
-
* GNU Screen has limitations on the length of string sequences it can handle (often around 768 bytes).
|
|
21
|
-
* This function can optionally chunk the input `sequence` into smaller parts, each wrapped
|
|
22
|
-
* in its own `DCS...ST` sequence, to work around this limitation.
|
|
23
|
-
* @param sequence The ANSI escape sequence string to be wrapped.
|
|
24
|
-
* @param limit The maximum length for each chunk of the `sequence` before it's wrapped.
|
|
25
|
-
* If `0` or a negative number, the sequence is not chunked. Defaults to {@link SCREEN_MAX_LEN_DEFAULT} (0).
|
|
26
|
-
* Consider using {@link SCREEN_TYPICAL_LIMIT} (768) for practical chunking with Screen.
|
|
27
|
-
* @returns The wrapped string, possibly chunked into multiple `DCS...ST` sequences if `limit` is positive and the `sequence` exceeds it.
|
|
28
|
-
* @see {@link https://www.gnu.org/software/screen/manual/screen.html#String-Escapes} GNU Screen Manual - String Escapes.
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* import { screenPassthrough, SCREEN_TYPICAL_LIMIT } from \'@visulima/ansi/passthrough\';
|
|
32
|
-
* import { cursorShow, cursorHide } from \'@visulima/ansi/cursor\';
|
|
33
|
-
*
|
|
34
|
-
* const longSequence = cursorHide + "Some very long output..." + cursorShow;
|
|
35
|
-
*
|
|
36
|
-
* // No chunking (default behavior if sequence is short enough or limit is 0)
|
|
37
|
-
* const passthrough1 = screenPassthrough(cursorHide);
|
|
38
|
-
* console.log(JSON.stringify(passthrough1)); // "\u001bP?25l\u001b\\"
|
|
39
|
-
*
|
|
40
|
-
* // With chunking, assuming SCREEN_TYPICAL_LIMIT is small for demonstration
|
|
41
|
-
* const limitedPassthrough = screenPassthrough(longSequence, 10); // Hypothetical small limit
|
|
42
|
-
* // Example output if longSequence was "0123456789abcde" and limit 10:
|
|
43
|
-
* // "\u001bP0123456789\u001b\\\u001bPabcde\u001b\\"
|
|
44
|
-
* console.log(JSON.stringify(limitedPassthrough));
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export declare const screenPassthrough: (sequence: string, limit?: number) => string;
|
|
48
|
-
/**
|
|
49
|
-
* Wraps a given ANSI escape sequence in a special DCS (Device Control String) passthrough sequence
|
|
50
|
-
* designed for tmux (Terminal Multiplexer). This allows raw escape sequences to be sent to the
|
|
51
|
-
* terminal emulator hosting tmux, bypassing tmux's own interpretation.
|
|
52
|
-
*
|
|
53
|
-
* The format is: `DCS tmux ; <escaped-data> ST`
|
|
54
|
-
* (where `DCS` is `ESC P`, and `ST` is `ESC \`).
|
|
55
|
-
*
|
|
56
|
-
* The `<escaped-data>` is the original `sequence` with all occurrences of the ESC character (`\u001B`)
|
|
57
|
-
* doubled (i.e., `ESC` becomes `ESC ESC`).
|
|
58
|
-
*
|
|
59
|
-
* **Note:** For this to work, the tmux option `allow-passthrough` must be enabled (`on`) in the tmux configuration.
|
|
60
|
-
* By default, it might be off.
|
|
61
|
-
* @param sequence The ANSI escape sequence string to be wrapped and properly escaped for tmux.
|
|
62
|
-
* @returns The wrapped and escaped string suitable for tmux passthrough.
|
|
63
|
-
* @see {@link https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it} Tmux FAQ on Passthrough.
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* import { tmuxPassthrough } from \'@visulima/ansi/passthrough\';
|
|
67
|
-
* import { cursorShow } from \'@visulima/ansi/cursor\';
|
|
68
|
-
*
|
|
69
|
-
* const originalSequence = cursorShow; // e.g., "\u001b[?25h"
|
|
70
|
-
* const passthrough = tmuxPassthrough(originalSequence);
|
|
71
|
-
*
|
|
72
|
-
* // Expected: "\u001bPtmux;\u001b\u001b[?25h\u001b\\"
|
|
73
|
-
* // (ESC P tmux ; ESC ESC [ ? 2 5 h ESC \)
|
|
74
|
-
* console.log(JSON.stringify(passthrough));
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare const tmuxPassthrough: (sequence: string) => string;
|
package/dist/passthrough.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { a as ST, D as DCS, E as ESC } from './packem_shared/constants-CE7WkXh_.js';
|
|
2
|
-
|
|
3
|
-
const SCREEN_MAX_LEN_DEFAULT = 0;
|
|
4
|
-
const SCREEN_TYPICAL_LIMIT = 768;
|
|
5
|
-
const screenPassthrough = (sequence, limit = SCREEN_MAX_LEN_DEFAULT) => {
|
|
6
|
-
let result = DCS;
|
|
7
|
-
if (limit > 0 && sequence.length > limit) {
|
|
8
|
-
for (let index = 0; index < sequence.length; index += limit) {
|
|
9
|
-
const end = Math.min(index + limit, sequence.length);
|
|
10
|
-
result += sequence.slice(index, end);
|
|
11
|
-
if (end < sequence.length) {
|
|
12
|
-
result += ST + DCS;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
} else {
|
|
16
|
-
result += sequence;
|
|
17
|
-
}
|
|
18
|
-
result += ST;
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
const tmuxPassthrough = (sequence) => {
|
|
22
|
-
let escapedSequence = "";
|
|
23
|
-
for (const element of sequence) {
|
|
24
|
-
escapedSequence += element === ESC ? ESC + ESC : element;
|
|
25
|
-
}
|
|
26
|
-
return `${DCS}tmux;${escapedSequence}${ST}`;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export { SCREEN_MAX_LEN_DEFAULT, SCREEN_TYPICAL_LIMIT, screenPassthrough, tmuxPassthrough };
|