@visulima/ansi 3.0.4 → 4.0.0-alpha.1
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 +32 -0
- package/dist/alternative-screen.js +8 -1
- package/dist/clear.js +16 -1
- package/dist/cursor.js +3 -1
- package/dist/erase.js +47 -1
- package/dist/hyperlink.js +5 -1
- package/dist/image.js +43 -1
- package/dist/index.js +26 -1
- package/dist/iterm2.js +12 -1
- package/dist/mode.js +245 -1
- package/dist/mouse.js +106 -1
- package/dist/packem_shared/IT2_AUTO-BGxGtZAE.js +6 -0
- package/dist/packem_shared/ITerm2File-DzWaT6j3.js +137 -0
- package/dist/packem_shared/constants-CE7WkXh_.js +9 -0
- package/dist/packem_shared/cursor-CHPvxMal.js +71 -0
- package/dist/packem_shared/resetProgressBar-kV21u2hs.js +18 -0
- package/dist/packem_shared/restoreCursor-GfYEeJqN.js +323 -0
- package/dist/passthrough.js +29 -1
- package/dist/reset.js +4 -1
- package/dist/screen.js +27 -1
- package/dist/scroll.js +18 -1
- package/dist/status.js +98 -1
- package/dist/strip.js +12 -1
- package/dist/termcap.js +25 -1
- package/dist/title.js +18 -1
- package/dist/window-ops.js +61 -1
- package/dist/xterm.js +33 -1
- package/package.json +49 -3
- package/dist/packem_shared/IT2_AUTO-BYrffRAq.js +0 -1
- package/dist/packem_shared/ITerm2File-C88DBJC-.js +0 -1
- package/dist/packem_shared/constants-D12jy2Zh.js +0 -1
- package/dist/packem_shared/cursor-nxpKt8Tn.js +0 -1
- package/dist/packem_shared/resetProgressBar-BtBbpWCM.js +0 -1
- package/dist/packem_shared/restoreCursor-CHy0jZuu.js +0 -2
|
@@ -0,0 +1,137 @@
|
|
|
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 };
|
|
@@ -0,0 +1,71 @@
|
|
|
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 };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 };
|
|
@@ -0,0 +1,323 @@
|
|
|
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.js
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
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 };
|
package/dist/reset.js
CHANGED
package/dist/screen.js
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
import { C as CSI, S as SEP } from './packem_shared/constants-CE7WkXh_.js';
|
|
2
|
+
|
|
3
|
+
const insertLine = (count = 1) => `${CSI + (count <= 1 ? "" : count)}L`;
|
|
4
|
+
const deleteLine = (count = 1) => `${CSI + (count <= 1 ? "" : count)}M`;
|
|
5
|
+
const setTopBottomMargins = (top, bottom) => {
|
|
6
|
+
const topString = top && top > 0 ? top.toString() : "";
|
|
7
|
+
const bottomString = bottom && bottom > 0 ? bottom.toString() : "";
|
|
8
|
+
if (topString === "" && bottomString === "") {
|
|
9
|
+
return `${CSI + SEP}r`;
|
|
10
|
+
}
|
|
11
|
+
return `${CSI + topString + SEP + bottomString}r`;
|
|
12
|
+
};
|
|
13
|
+
const setLeftRightMargins = (left, right) => {
|
|
14
|
+
const leftString = left && left > 0 ? left.toString() : "";
|
|
15
|
+
const rightString = right && right > 0 ? right.toString() : "";
|
|
16
|
+
if (leftString === "" && rightString === "") {
|
|
17
|
+
return `${CSI + SEP}s`;
|
|
18
|
+
}
|
|
19
|
+
return `${CSI + leftString + SEP + rightString}s`;
|
|
20
|
+
};
|
|
21
|
+
const insertCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}@`;
|
|
22
|
+
const deleteCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}P`;
|
|
23
|
+
const clearTabStop = (mode = 0) => `${CSI + mode}g`;
|
|
24
|
+
const requestPresentationStateReport = (mode) => `${CSI + mode}$u`;
|
|
25
|
+
const repeatPreviousCharacter = (count = 1) => `${CSI + (count <= 1 ? "" : count)}b`;
|
|
26
|
+
|
|
27
|
+
export { clearTabStop, deleteCharacter, deleteLine, insertCharacter, insertLine, repeatPreviousCharacter, requestPresentationStateReport, setLeftRightMargins, setTopBottomMargins };
|
package/dist/scroll.js
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { C as CSI } from './packem_shared/constants-CE7WkXh_.js';
|
|
2
|
+
|
|
3
|
+
const scrollUp = (count = 1) => {
|
|
4
|
+
if (count === 0) {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
|
7
|
+
return `${CSI + (count <= 1 ? "" : count)}S`;
|
|
8
|
+
};
|
|
9
|
+
const scrollDown = (count = 1) => {
|
|
10
|
+
if (count === 0) {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
return `${CSI + (count <= 1 ? "" : count)}T`;
|
|
14
|
+
};
|
|
15
|
+
const SCROLL_UP_1 = `${CSI}S`;
|
|
16
|
+
const SCROLL_DOWN_1 = `${CSI}T`;
|
|
17
|
+
|
|
18
|
+
export { SCROLL_DOWN_1, SCROLL_UP_1, scrollDown, scrollUp };
|