@visulima/ansi 2.0.1 → 3.0.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.
Files changed (152) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE.md +2 -133
  3. package/README.md +226 -226
  4. package/dist/alternative-screen.d.ts +6 -74
  5. package/dist/alternative-screen.js +1 -0
  6. package/dist/clear.d.ts +6 -77
  7. package/dist/clear.js +1 -0
  8. package/dist/cursor.d.ts +48 -429
  9. package/dist/cursor.js +1 -0
  10. package/dist/erase.d.ts +14 -197
  11. package/dist/erase.js +1 -0
  12. package/dist/hyperlink.d.ts +2 -26
  13. package/dist/hyperlink.js +1 -0
  14. package/dist/image.d.ts +7 -69
  15. package/dist/image.js +1 -0
  16. package/dist/index.d.ts +30 -35
  17. package/dist/index.js +1 -0
  18. package/dist/iterm2.d.ts +43 -58
  19. package/dist/iterm2.js +1 -0
  20. package/dist/mode.d.ts +174 -648
  21. package/dist/mode.js +1 -0
  22. package/dist/mouse.d.ts +21 -203
  23. package/dist/mouse.js +1 -0
  24. package/dist/packem_shared/IT2_AUTO-BYrffRAq.js +1 -0
  25. package/dist/packem_shared/ITerm2File-C88DBJC-.js +1 -0
  26. package/dist/packem_shared/constants-D12jy2Zh.js +1 -0
  27. package/dist/packem_shared/cursor-D2UOfUc_.js +1 -0
  28. package/dist/packem_shared/resetProgressBar-BtBbpWCM.js +1 -0
  29. package/dist/packem_shared/restoreCursor-D3XBmqcY.js +2 -0
  30. package/dist/passthrough.d.ts +6 -77
  31. package/dist/passthrough.js +1 -0
  32. package/dist/reset.d.ts +4 -26
  33. package/dist/reset.js +1 -0
  34. package/dist/screen.d.ts +11 -234
  35. package/dist/screen.js +1 -0
  36. package/dist/scroll.d.ts +6 -67
  37. package/dist/scroll.js +1 -0
  38. package/dist/status.d.ts +48 -498
  39. package/dist/status.js +1 -0
  40. package/dist/strip.d.ts +2 -22
  41. package/dist/strip.js +1 -0
  42. package/dist/termcap.d.ts +5 -38
  43. package/dist/termcap.js +1 -0
  44. package/dist/title.d.ts +10 -185
  45. package/dist/title.js +1 -0
  46. package/dist/window-ops.d.ts +24 -396
  47. package/dist/window-ops.js +1 -0
  48. package/dist/xterm.d.ts +12 -94
  49. package/dist/xterm.js +1 -0
  50. package/package.json +45 -230
  51. package/dist/alternative-screen.cjs +0 -17
  52. package/dist/alternative-screen.d.cts +0 -74
  53. package/dist/alternative-screen.d.mts +0 -74
  54. package/dist/alternative-screen.mjs +0 -10
  55. package/dist/clear.cjs +0 -17
  56. package/dist/clear.d.cts +0 -77
  57. package/dist/clear.d.mts +0 -77
  58. package/dist/clear.mjs +0 -10
  59. package/dist/constants.d.cts +0 -20
  60. package/dist/constants.d.mts +0 -20
  61. package/dist/constants.d.ts +0 -20
  62. package/dist/cursor.cjs +0 -41
  63. package/dist/cursor.d.cts +0 -437
  64. package/dist/cursor.d.mts +0 -437
  65. package/dist/cursor.mjs +0 -3
  66. package/dist/erase.cjs +0 -64
  67. package/dist/erase.d.cts +0 -206
  68. package/dist/erase.d.mts +0 -206
  69. package/dist/erase.mjs +0 -49
  70. package/dist/helpers.d.cts +0 -14
  71. package/dist/helpers.d.mts +0 -14
  72. package/dist/helpers.d.ts +0 -14
  73. package/dist/hyperlink.cjs +0 -9
  74. package/dist/hyperlink.d.cts +0 -27
  75. package/dist/hyperlink.d.mts +0 -27
  76. package/dist/hyperlink.mjs +0 -7
  77. package/dist/image.cjs +0 -28
  78. package/dist/image.d.cts +0 -73
  79. package/dist/image.d.mts +0 -73
  80. package/dist/image.mjs +0 -24
  81. package/dist/index.cjs +0 -246
  82. package/dist/index.d.cts +0 -35
  83. package/dist/index.d.mts +0 -35
  84. package/dist/index.mjs +0 -25
  85. package/dist/iterm2/iterm2-properties.d.cts +0 -135
  86. package/dist/iterm2/iterm2-properties.d.mts +0 -135
  87. package/dist/iterm2/iterm2-properties.d.ts +0 -135
  88. package/dist/iterm2/iterm2-sequences.d.cts +0 -96
  89. package/dist/iterm2/iterm2-sequences.d.mts +0 -96
  90. package/dist/iterm2/iterm2-sequences.d.ts +0 -96
  91. package/dist/iterm2.cjs +0 -26
  92. package/dist/iterm2.d.cts +0 -58
  93. package/dist/iterm2.d.mts +0 -58
  94. package/dist/iterm2.mjs +0 -14
  95. package/dist/mode.cjs +0 -388
  96. package/dist/mode.d.cts +0 -657
  97. package/dist/mode.d.mts +0 -657
  98. package/dist/mode.mjs +0 -235
  99. package/dist/mouse.cjs +0 -127
  100. package/dist/mouse.d.cts +0 -230
  101. package/dist/mouse.d.mts +0 -230
  102. package/dist/mouse.mjs +0 -108
  103. package/dist/packem_shared/IT2_AUTO-5vTJQMm6.cjs +0 -15
  104. package/dist/packem_shared/IT2_AUTO-DnfCUXso.mjs +0 -8
  105. package/dist/packem_shared/ITerm2File-BGPqNSjB.cjs +0 -137
  106. package/dist/packem_shared/ITerm2File-DKFkdqdA.mjs +0 -130
  107. package/dist/packem_shared/constants-BK26O-46.cjs +0 -17
  108. package/dist/packem_shared/constants-CE7WkXh_.mjs +0 -9
  109. package/dist/packem_shared/cursor-CQKLCu7U.cjs +0 -105
  110. package/dist/packem_shared/cursor-DhFQcQ9g.mjs +0 -73
  111. package/dist/packem_shared/restoreCursor-C6pNB8UY.mjs +0 -336
  112. package/dist/packem_shared/restoreCursor-DC_ZKZwT.cjs +0 -342
  113. package/dist/passthrough.cjs +0 -38
  114. package/dist/passthrough.d.cts +0 -77
  115. package/dist/passthrough.d.mts +0 -77
  116. package/dist/passthrough.mjs +0 -31
  117. package/dist/reset.cjs +0 -9
  118. package/dist/reset.d.cts +0 -26
  119. package/dist/reset.d.mts +0 -26
  120. package/dist/reset.mjs +0 -4
  121. package/dist/screen.cjs +0 -41
  122. package/dist/screen.d.cts +0 -234
  123. package/dist/screen.d.mts +0 -234
  124. package/dist/screen.mjs +0 -29
  125. package/dist/scroll.cjs +0 -27
  126. package/dist/scroll.d.cts +0 -67
  127. package/dist/scroll.d.mts +0 -67
  128. package/dist/scroll.mjs +0 -20
  129. package/dist/status.cjs +0 -147
  130. package/dist/status.d.cts +0 -501
  131. package/dist/status.d.mts +0 -501
  132. package/dist/status.mjs +0 -104
  133. package/dist/strip.cjs +0 -20
  134. package/dist/strip.d.cts +0 -23
  135. package/dist/strip.d.mts +0 -23
  136. package/dist/strip.mjs +0 -18
  137. package/dist/termcap.cjs +0 -33
  138. package/dist/termcap.d.cts +0 -38
  139. package/dist/termcap.d.mts +0 -38
  140. package/dist/termcap.mjs +0 -27
  141. package/dist/title.cjs +0 -31
  142. package/dist/title.d.cts +0 -185
  143. package/dist/title.d.mts +0 -185
  144. package/dist/title.mjs +0 -20
  145. package/dist/window-ops.cjs +0 -85
  146. package/dist/window-ops.d.cts +0 -418
  147. package/dist/window-ops.d.mts +0 -418
  148. package/dist/window-ops.mjs +0 -63
  149. package/dist/xterm.cjs +0 -48
  150. package/dist/xterm.d.cts +0 -94
  151. package/dist/xterm.d.mts +0 -94
  152. package/dist/xterm.mjs +0 -35
@@ -1,105 +0,0 @@
1
- 'use strict';
2
-
3
- const constants = require('./constants-BK26O-46.cjs');
4
- require('./restoreCursor-DC_ZKZwT.cjs');
5
-
6
- const isBrowser = globalThis?.window?.document !== void 0;
7
- const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === "Apple_Terminal";
8
- const isWindows = !isBrowser && (process.platform === "win32" || /^(?:msys|cygwin)$/.test(process.env.OSTYPE));
9
-
10
- var __defProp = Object.defineProperty;
11
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- const SAVE_CURSOR_DEC = `${constants.ESC}7`;
13
- const RESTORE_CURSOR_DEC = `${constants.ESC}8`;
14
- const CURSOR_UP_1 = `${constants.CSI}A`;
15
- const CURSOR_DOWN_1 = `${constants.CSI}B`;
16
- const CURSOR_FORWARD_1 = `${constants.CSI}C`;
17
- const CURSOR_BACKWARD_1 = `${constants.CSI}D`;
18
- const REQUEST_CURSOR_POSITION = `${constants.CSI}6n`;
19
- const REQUEST_EXTENDED_CURSOR_POSITION = `${constants.CSI}?6n`;
20
- const cursorBackward = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}D`, "cursorBackward");
21
- const cursorDown = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}B`, "cursorDown");
22
- const cursorForward = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}C`, "cursorForward");
23
- const cursorHide = `${constants.CSI}?25l`;
24
- const cursorToColumn1 = `${constants.CSI}G`;
25
- const cursorLeft = /* @__PURE__ */ __name((count = 1) => cursorBackward(count), "cursorLeft");
26
- const cursorHorizontalAbsolute = /* @__PURE__ */ __name((column = 1) => `${constants.CSI + column}G`, "cursorHorizontalAbsolute");
27
- const cursorMove = /* @__PURE__ */ __name((x, y) => {
28
- let returnValue = "";
29
- if (x < 0) {
30
- returnValue += `${constants.CSI + -x}D`;
31
- } else if (x > 0) {
32
- returnValue += `${constants.CSI + x}C`;
33
- }
34
- if (y < 0) {
35
- returnValue += `${constants.CSI + -y}A`;
36
- } else if (y > 0) {
37
- returnValue += `${constants.CSI + y}B`;
38
- }
39
- return returnValue;
40
- }, "cursorMove");
41
- const cursorNextLine = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}E`, "cursorNextLine");
42
- const cursorPreviousLine = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}F`, "cursorPreviousLine");
43
- const cursorRestore = isTerminalApp ? RESTORE_CURSOR_DEC : `${constants.ESC}u`;
44
- const cursorSave = isTerminalApp ? SAVE_CURSOR_DEC : `${constants.ESC}s`;
45
- const cursorShow = `${constants.CSI}?25h`;
46
- const cursorTo = /* @__PURE__ */ __name((x, y) => {
47
- if (y === void 0) {
48
- return cursorHorizontalAbsolute(x + 1);
49
- }
50
- return `${constants.CSI + (y + 1) + constants.SEP + (x + 1)}H`;
51
- }, "cursorTo");
52
- const cursorPosition = /* @__PURE__ */ __name((row, column) => {
53
- if (column === void 0) {
54
- return `${constants.CSI + row}H`;
55
- }
56
- return `${constants.CSI + row + constants.SEP + column}H`;
57
- }, "cursorPosition");
58
- const cursorHorizontalForwardTab = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}I`, "cursorHorizontalForwardTab");
59
- const cursorBackwardTab = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}Z`, "cursorBackwardTab");
60
- const eraseCharacter = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}X`, "eraseCharacter");
61
- const cursorVerticalAbsolute = /* @__PURE__ */ __name((row = 1) => `${constants.CSI + row}d`, "cursorVerticalAbsolute");
62
- const cursorUp = /* @__PURE__ */ __name((count = 1) => `${constants.CSI + count}A`, "cursorUp");
63
- var CursorStyle = /* @__PURE__ */ ((CursorStyle2) => {
64
- CursorStyle2[CursorStyle2["BlinkingBar"] = 5] = "BlinkingBar";
65
- CursorStyle2[CursorStyle2["BlinkingBlock"] = 1] = "BlinkingBlock";
66
- CursorStyle2[CursorStyle2["BlinkingUnderline"] = 3] = "BlinkingUnderline";
67
- CursorStyle2[CursorStyle2["Default"] = 0] = "Default";
68
- CursorStyle2[CursorStyle2["SteadyBar"] = 6] = "SteadyBar";
69
- CursorStyle2[CursorStyle2["SteadyBlock"] = 2] = "SteadyBlock";
70
- CursorStyle2[CursorStyle2["SteadyUnderline"] = 4] = "SteadyUnderline";
71
- return CursorStyle2;
72
- })(CursorStyle || {});
73
- const setCursorStyle = /* @__PURE__ */ __name((style) => `${constants.CSI + style} q`, "setCursorStyle");
74
-
75
- exports.CURSOR_BACKWARD_1 = CURSOR_BACKWARD_1;
76
- exports.CURSOR_DOWN_1 = CURSOR_DOWN_1;
77
- exports.CURSOR_FORWARD_1 = CURSOR_FORWARD_1;
78
- exports.CURSOR_UP_1 = CURSOR_UP_1;
79
- exports.CursorStyle = CursorStyle;
80
- exports.REQUEST_CURSOR_POSITION = REQUEST_CURSOR_POSITION;
81
- exports.REQUEST_EXTENDED_CURSOR_POSITION = REQUEST_EXTENDED_CURSOR_POSITION;
82
- exports.RESTORE_CURSOR_DEC = RESTORE_CURSOR_DEC;
83
- exports.SAVE_CURSOR_DEC = SAVE_CURSOR_DEC;
84
- exports.cursorBackward = cursorBackward;
85
- exports.cursorBackwardTab = cursorBackwardTab;
86
- exports.cursorDown = cursorDown;
87
- exports.cursorForward = cursorForward;
88
- exports.cursorHide = cursorHide;
89
- exports.cursorHorizontalAbsolute = cursorHorizontalAbsolute;
90
- exports.cursorHorizontalForwardTab = cursorHorizontalForwardTab;
91
- exports.cursorLeft = cursorLeft;
92
- exports.cursorMove = cursorMove;
93
- exports.cursorNextLine = cursorNextLine;
94
- exports.cursorPosition = cursorPosition;
95
- exports.cursorPreviousLine = cursorPreviousLine;
96
- exports.cursorRestore = cursorRestore;
97
- exports.cursorSave = cursorSave;
98
- exports.cursorShow = cursorShow;
99
- exports.cursorTo = cursorTo;
100
- exports.cursorToColumn1 = cursorToColumn1;
101
- exports.cursorUp = cursorUp;
102
- exports.cursorVerticalAbsolute = cursorVerticalAbsolute;
103
- exports.eraseCharacter = eraseCharacter;
104
- exports.isWindows = isWindows;
105
- exports.setCursorStyle = setCursorStyle;
@@ -1,73 +0,0 @@
1
- import { C as CSI, E as ESC, S as SEP } from './constants-CE7WkXh_.mjs';
2
- import './restoreCursor-C6pNB8UY.mjs';
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
- var __defProp = Object.defineProperty;
9
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- const SAVE_CURSOR_DEC = `${ESC}7`;
11
- const RESTORE_CURSOR_DEC = `${ESC}8`;
12
- const CURSOR_UP_1 = `${CSI}A`;
13
- const CURSOR_DOWN_1 = `${CSI}B`;
14
- const CURSOR_FORWARD_1 = `${CSI}C`;
15
- const CURSOR_BACKWARD_1 = `${CSI}D`;
16
- const REQUEST_CURSOR_POSITION = `${CSI}6n`;
17
- const REQUEST_EXTENDED_CURSOR_POSITION = `${CSI}?6n`;
18
- const cursorBackward = /* @__PURE__ */ __name((count = 1) => `${CSI + count}D`, "cursorBackward");
19
- const cursorDown = /* @__PURE__ */ __name((count = 1) => `${CSI + count}B`, "cursorDown");
20
- const cursorForward = /* @__PURE__ */ __name((count = 1) => `${CSI + count}C`, "cursorForward");
21
- const cursorHide = `${CSI}?25l`;
22
- const cursorToColumn1 = `${CSI}G`;
23
- const cursorLeft = /* @__PURE__ */ __name((count = 1) => cursorBackward(count), "cursorLeft");
24
- const cursorHorizontalAbsolute = /* @__PURE__ */ __name((column = 1) => `${CSI + column}G`, "cursorHorizontalAbsolute");
25
- const cursorMove = /* @__PURE__ */ __name((x, y) => {
26
- let returnValue = "";
27
- if (x < 0) {
28
- returnValue += `${CSI + -x}D`;
29
- } else if (x > 0) {
30
- returnValue += `${CSI + x}C`;
31
- }
32
- if (y < 0) {
33
- returnValue += `${CSI + -y}A`;
34
- } else if (y > 0) {
35
- returnValue += `${CSI + y}B`;
36
- }
37
- return returnValue;
38
- }, "cursorMove");
39
- const cursorNextLine = /* @__PURE__ */ __name((count = 1) => `${CSI + count}E`, "cursorNextLine");
40
- const cursorPreviousLine = /* @__PURE__ */ __name((count = 1) => `${CSI + count}F`, "cursorPreviousLine");
41
- const cursorRestore = isTerminalApp ? RESTORE_CURSOR_DEC : `${ESC}u`;
42
- const cursorSave = isTerminalApp ? SAVE_CURSOR_DEC : `${ESC}s`;
43
- const cursorShow = `${CSI}?25h`;
44
- const cursorTo = /* @__PURE__ */ __name((x, y) => {
45
- if (y === void 0) {
46
- return cursorHorizontalAbsolute(x + 1);
47
- }
48
- return `${CSI + (y + 1) + SEP + (x + 1)}H`;
49
- }, "cursorTo");
50
- const cursorPosition = /* @__PURE__ */ __name((row, column) => {
51
- if (column === void 0) {
52
- return `${CSI + row}H`;
53
- }
54
- return `${CSI + row + SEP + column}H`;
55
- }, "cursorPosition");
56
- const cursorHorizontalForwardTab = /* @__PURE__ */ __name((count = 1) => `${CSI + count}I`, "cursorHorizontalForwardTab");
57
- const cursorBackwardTab = /* @__PURE__ */ __name((count = 1) => `${CSI + count}Z`, "cursorBackwardTab");
58
- const eraseCharacter = /* @__PURE__ */ __name((count = 1) => `${CSI + count}X`, "eraseCharacter");
59
- const cursorVerticalAbsolute = /* @__PURE__ */ __name((row = 1) => `${CSI + row}d`, "cursorVerticalAbsolute");
60
- const cursorUp = /* @__PURE__ */ __name((count = 1) => `${CSI + count}A`, "cursorUp");
61
- var CursorStyle = /* @__PURE__ */ ((CursorStyle2) => {
62
- CursorStyle2[CursorStyle2["BlinkingBar"] = 5] = "BlinkingBar";
63
- CursorStyle2[CursorStyle2["BlinkingBlock"] = 1] = "BlinkingBlock";
64
- CursorStyle2[CursorStyle2["BlinkingUnderline"] = 3] = "BlinkingUnderline";
65
- CursorStyle2[CursorStyle2["Default"] = 0] = "Default";
66
- CursorStyle2[CursorStyle2["SteadyBar"] = 6] = "SteadyBar";
67
- CursorStyle2[CursorStyle2["SteadyBlock"] = 2] = "SteadyBlock";
68
- CursorStyle2[CursorStyle2["SteadyUnderline"] = 4] = "SteadyUnderline";
69
- return CursorStyle2;
70
- })(CursorStyle || {});
71
- const setCursorStyle = /* @__PURE__ */ __name((style) => `${CSI + style} q`, "setCursorStyle");
72
-
73
- 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,336 +0,0 @@
1
- import process$2 from 'node:process';
2
-
3
- var __defProp$2 = Object.defineProperty;
4
- var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
5
- const copyProperty = /* @__PURE__ */ __name$2((to, from, property, ignoreNonConfigurable) => {
6
- if (property === "length" || property === "prototype") {
7
- return;
8
- }
9
- if (property === "arguments" || property === "caller") {
10
- return;
11
- }
12
- const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
13
- const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
14
- if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
15
- return;
16
- }
17
- Object.defineProperty(to, property, fromDescriptor);
18
- }, "copyProperty");
19
- const canCopyProperty = /* @__PURE__ */ __name$2(function(toDescriptor, fromDescriptor) {
20
- return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
21
- }, "canCopyProperty");
22
- const changePrototype = /* @__PURE__ */ __name$2((to, from) => {
23
- const fromPrototype = Object.getPrototypeOf(from);
24
- if (fromPrototype === Object.getPrototypeOf(to)) {
25
- return;
26
- }
27
- Object.setPrototypeOf(to, fromPrototype);
28
- }, "changePrototype");
29
- const wrappedToString = /* @__PURE__ */ __name$2((withName, fromBody) => `/* Wrapped ${withName}*/
30
- ${fromBody}`, "wrappedToString");
31
- const toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
32
- const toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
33
- const changeToString = /* @__PURE__ */ __name$2((to, from, name) => {
34
- const withName = name === "" ? "" : `with ${name.trim()}() `;
35
- const newToString = wrappedToString.bind(null, withName, from.toString());
36
- Object.defineProperty(newToString, "name", toStringName);
37
- const { writable, enumerable, configurable } = toStringDescriptor;
38
- Object.defineProperty(to, "toString", { value: newToString, writable, enumerable, configurable });
39
- }, "changeToString");
40
- function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
41
- const { name } = to;
42
- for (const property of Reflect.ownKeys(from)) {
43
- copyProperty(to, from, property, ignoreNonConfigurable);
44
- }
45
- changePrototype(to, from);
46
- changeToString(to, from, name);
47
- return to;
48
- }
49
- __name$2(mimicFunction, "mimicFunction");
50
-
51
- var __defProp$1 = Object.defineProperty;
52
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
53
- const calledFunctions = /* @__PURE__ */ new WeakMap();
54
- const onetime = /* @__PURE__ */ __name$1((function_, options = {}) => {
55
- if (typeof function_ !== "function") {
56
- throw new TypeError("Expected a function");
57
- }
58
- let returnValue;
59
- let callCount = 0;
60
- const functionName = function_.displayName || function_.name || "<anonymous>";
61
- const onetime2 = /* @__PURE__ */ __name$1(function(...arguments_) {
62
- calledFunctions.set(onetime2, ++callCount);
63
- if (callCount === 1) {
64
- returnValue = function_.apply(this, arguments_);
65
- function_ = void 0;
66
- } else if (options.throw === true) {
67
- throw new Error(`Function \`${functionName}\` can only be called once`);
68
- }
69
- return returnValue;
70
- }, "onetime");
71
- mimicFunction(onetime2, function_);
72
- calledFunctions.set(onetime2, callCount);
73
- return onetime2;
74
- }, "onetime");
75
- onetime.callCount = (function_) => {
76
- if (!calledFunctions.has(function_)) {
77
- throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
78
- }
79
- return calledFunctions.get(function_);
80
- };
81
-
82
- const signals = [];
83
- signals.push("SIGHUP", "SIGINT", "SIGTERM");
84
- if (process.platform !== "win32") {
85
- signals.push(
86
- "SIGALRM",
87
- "SIGABRT",
88
- "SIGVTALRM",
89
- "SIGXCPU",
90
- "SIGXFSZ",
91
- "SIGUSR2",
92
- "SIGTRAP",
93
- "SIGSYS",
94
- "SIGQUIT",
95
- "SIGIOT"
96
- // should detect profiler and enable/disable accordingly.
97
- // see #21
98
- // 'SIGPROF'
99
- );
100
- }
101
- if (process.platform === "linux") {
102
- signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
103
- }
104
-
105
- var __defProp = Object.defineProperty;
106
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
107
- const processOk = /* @__PURE__ */ __name((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", "processOk");
108
- const kExitEmitter = Symbol.for("signal-exit emitter");
109
- const global = globalThis;
110
- const ObjectDefineProperty = Object.defineProperty.bind(Object);
111
- class Emitter {
112
- static {
113
- __name(this, "Emitter");
114
- }
115
- emitted = {
116
- afterExit: false,
117
- exit: false
118
- };
119
- listeners = {
120
- afterExit: [],
121
- exit: []
122
- };
123
- count = 0;
124
- id = Math.random();
125
- constructor() {
126
- if (global[kExitEmitter]) {
127
- return global[kExitEmitter];
128
- }
129
- ObjectDefineProperty(global, kExitEmitter, {
130
- value: this,
131
- writable: false,
132
- enumerable: false,
133
- configurable: false
134
- });
135
- }
136
- on(ev, fn) {
137
- this.listeners[ev].push(fn);
138
- }
139
- removeListener(ev, fn) {
140
- const list = this.listeners[ev];
141
- const i = list.indexOf(fn);
142
- if (i === -1) {
143
- return;
144
- }
145
- if (i === 0 && list.length === 1) {
146
- list.length = 0;
147
- } else {
148
- list.splice(i, 1);
149
- }
150
- }
151
- emit(ev, code, signal) {
152
- if (this.emitted[ev]) {
153
- return false;
154
- }
155
- this.emitted[ev] = true;
156
- let ret = false;
157
- for (const fn of this.listeners[ev]) {
158
- ret = fn(code, signal) === true || ret;
159
- }
160
- if (ev === "exit") {
161
- ret = this.emit("afterExit", code, signal) || ret;
162
- }
163
- return ret;
164
- }
165
- }
166
- class SignalExitBase {
167
- static {
168
- __name(this, "SignalExitBase");
169
- }
170
- }
171
- const signalExitWrap = /* @__PURE__ */ __name((handler) => {
172
- return {
173
- onExit(cb, opts) {
174
- return handler.onExit(cb, opts);
175
- },
176
- load() {
177
- return handler.load();
178
- },
179
- unload() {
180
- return handler.unload();
181
- }
182
- };
183
- }, "signalExitWrap");
184
- class SignalExitFallback extends SignalExitBase {
185
- static {
186
- __name(this, "SignalExitFallback");
187
- }
188
- onExit() {
189
- return () => {
190
- };
191
- }
192
- load() {
193
- }
194
- unload() {
195
- }
196
- }
197
- class SignalExit extends SignalExitBase {
198
- static {
199
- __name(this, "SignalExit");
200
- }
201
- // "SIGHUP" throws an `ENOSYS` error on Windows,
202
- // so use a supported signal instead
203
- /* c8 ignore start */
204
- #hupSig = process$1.platform === "win32" ? "SIGINT" : "SIGHUP";
205
- /* c8 ignore stop */
206
- #emitter = new Emitter();
207
- #process;
208
- #originalProcessEmit;
209
- #originalProcessReallyExit;
210
- #sigListeners = {};
211
- #loaded = false;
212
- constructor(process2) {
213
- super();
214
- this.#process = process2;
215
- this.#sigListeners = {};
216
- for (const sig of signals) {
217
- this.#sigListeners[sig] = () => {
218
- const listeners = this.#process.listeners(sig);
219
- let { count } = this.#emitter;
220
- const p = process2;
221
- if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
222
- count += p.__signal_exit_emitter__.count;
223
- }
224
- if (listeners.length === count) {
225
- this.unload();
226
- const ret = this.#emitter.emit("exit", null, sig);
227
- const s = sig === "SIGHUP" ? this.#hupSig : sig;
228
- if (!ret)
229
- process2.kill(process2.pid, s);
230
- }
231
- };
232
- }
233
- this.#originalProcessReallyExit = process2.reallyExit;
234
- this.#originalProcessEmit = process2.emit;
235
- }
236
- onExit(cb, opts) {
237
- if (!processOk(this.#process)) {
238
- return () => {
239
- };
240
- }
241
- if (this.#loaded === false) {
242
- this.load();
243
- }
244
- const ev = opts?.alwaysLast ? "afterExit" : "exit";
245
- this.#emitter.on(ev, cb);
246
- return () => {
247
- this.#emitter.removeListener(ev, cb);
248
- if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
249
- this.unload();
250
- }
251
- };
252
- }
253
- load() {
254
- if (this.#loaded) {
255
- return;
256
- }
257
- this.#loaded = true;
258
- this.#emitter.count += 1;
259
- for (const sig of signals) {
260
- try {
261
- const fn = this.#sigListeners[sig];
262
- if (fn)
263
- this.#process.on(sig, fn);
264
- } catch (_) {
265
- }
266
- }
267
- this.#process.emit = (ev, ...a) => {
268
- return this.#processEmit(ev, ...a);
269
- };
270
- this.#process.reallyExit = (code) => {
271
- return this.#processReallyExit(code);
272
- };
273
- }
274
- unload() {
275
- if (!this.#loaded) {
276
- return;
277
- }
278
- this.#loaded = false;
279
- signals.forEach((sig) => {
280
- const listener = this.#sigListeners[sig];
281
- if (!listener) {
282
- throw new Error("Listener not defined for signal: " + sig);
283
- }
284
- try {
285
- this.#process.removeListener(sig, listener);
286
- } catch (_) {
287
- }
288
- });
289
- this.#process.emit = this.#originalProcessEmit;
290
- this.#process.reallyExit = this.#originalProcessReallyExit;
291
- this.#emitter.count -= 1;
292
- }
293
- #processReallyExit(code) {
294
- if (!processOk(this.#process)) {
295
- return 0;
296
- }
297
- this.#process.exitCode = code || 0;
298
- this.#emitter.emit("exit", this.#process.exitCode, null);
299
- return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
300
- }
301
- #processEmit(ev, ...args) {
302
- const og = this.#originalProcessEmit;
303
- if (ev === "exit" && processOk(this.#process)) {
304
- if (typeof args[0] === "number") {
305
- this.#process.exitCode = args[0];
306
- }
307
- const ret = og.call(this.#process, ev, ...args);
308
- this.#emitter.emit("exit", this.#process.exitCode, null);
309
- return ret;
310
- } else {
311
- return og.call(this.#process, ev, ...args);
312
- }
313
- }
314
- }
315
- const process$1 = globalThis.process;
316
- const {
317
- /**
318
- * Called when the process is exiting, whether via signal, explicit
319
- * exit, or running out of stuff to do.
320
- *
321
- * If the global process object is not suitable for instrumentation,
322
- * then this will be a no-op.
323
- *
324
- * Returns a function that may be used to unload signal-exit.
325
- */
326
- onExit} = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
327
-
328
- const terminal = process$2.stderr.isTTY ? process$2.stderr : process$2.stdout.isTTY ? process$2.stdout : void 0;
329
- const restoreCursor = terminal ? onetime(() => {
330
- onExit(() => {
331
- terminal.write("\x1B[?25h");
332
- }, { alwaysLast: true });
333
- }) : () => {
334
- };
335
-
336
- export { restoreCursor as default };