@visulima/ansi 1.0.18 → 1.1.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 +21 -0
- package/LICENSE.md +76 -74
- package/README.md +335 -2
- package/dist/alternative-screen.cjs +11 -5
- package/dist/alternative-screen.d.cts +74 -4
- package/dist/alternative-screen.d.mts +74 -4
- package/dist/alternative-screen.d.ts +74 -4
- package/dist/alternative-screen.mjs +8 -4
- package/dist/clear.cjs +10 -18
- package/dist/clear.d.cts +77 -7
- package/dist/clear.d.mts +77 -7
- package/dist/clear.d.ts +77 -7
- package/dist/clear.mjs +8 -15
- package/dist/constants.d.cts +20 -0
- package/dist/constants.d.mts +20 -0
- package/dist/constants.d.ts +20 -0
- package/dist/cursor.cjs +19 -2
- package/dist/cursor.d.cts +436 -30
- package/dist/cursor.d.mts +436 -30
- package/dist/cursor.d.ts +436 -30
- package/dist/cursor.mjs +2 -2
- package/dist/erase.cjs +44 -13
- package/dist/erase.d.cts +206 -9
- package/dist/erase.d.mts +206 -9
- package/dist/erase.d.ts +206 -9
- package/dist/erase.mjs +40 -14
- package/dist/helpers.d.cts +14 -0
- package/dist/helpers.d.mts +14 -0
- package/dist/helpers.d.ts +14 -0
- package/dist/hyperlink.cjs +9 -0
- package/dist/hyperlink.d.cts +29 -0
- package/dist/hyperlink.d.mts +27 -0
- package/dist/hyperlink.d.ts +29 -0
- package/dist/hyperlink.mjs +7 -0
- package/dist/image.cjs +12 -5
- package/dist/image.d.cts +69 -58
- package/dist/image.d.mts +69 -58
- package/dist/image.d.ts +69 -58
- package/dist/image.mjs +10 -5
- package/dist/index.cjs +209 -11
- package/dist/index.d.cts +35 -12
- package/dist/index.d.mts +35 -12
- package/dist/index.d.ts +35 -12
- package/dist/index.mjs +20 -7
- package/dist/iterm2/iterm2-properties.d.cts +135 -0
- package/dist/iterm2/iterm2-properties.d.mts +135 -0
- package/dist/iterm2/iterm2-properties.d.ts +135 -0
- package/dist/iterm2/iterm2-sequences.d.cts +96 -0
- package/dist/iterm2/iterm2-sequences.d.mts +96 -0
- package/dist/iterm2/iterm2-sequences.d.ts +96 -0
- package/dist/iterm2.cjs +26 -0
- package/dist/iterm2.d.cts +58 -0
- package/dist/iterm2.d.mts +58 -0
- package/dist/iterm2.d.ts +58 -0
- package/dist/iterm2.mjs +14 -0
- package/dist/mode.cjs +388 -0
- package/dist/mode.d.cts +657 -0
- package/dist/mode.d.mts +657 -0
- package/dist/mode.d.ts +657 -0
- package/dist/mode.mjs +235 -0
- package/dist/mouse.cjs +127 -0
- package/dist/mouse.d.cts +230 -0
- package/dist/mouse.d.mts +230 -0
- package/dist/mouse.d.ts +230 -0
- package/dist/mouse.mjs +108 -0
- package/dist/packem_shared/IT2_AUTO-5vTJQMm6.cjs +15 -0
- package/dist/packem_shared/IT2_AUTO-DnfCUXso.mjs +8 -0
- package/dist/packem_shared/ITerm2File-BGPqNSjB.cjs +137 -0
- package/dist/packem_shared/ITerm2File-DKFkdqdA.mjs +130 -0
- package/dist/packem_shared/{constants-D8u2npjW.cjs → constants-BK26O-46.cjs} +4 -0
- package/dist/packem_shared/constants-CE7WkXh_.mjs +9 -0
- package/dist/packem_shared/cursor-CQKLCu7U.cjs +105 -0
- package/dist/packem_shared/cursor-DhFQcQ9g.mjs +73 -0
- package/dist/passthrough.cjs +38 -0
- package/dist/passthrough.d.cts +77 -0
- package/dist/passthrough.d.mts +77 -0
- package/dist/passthrough.d.ts +77 -0
- package/dist/passthrough.mjs +31 -0
- package/dist/reset.cjs +9 -0
- package/dist/reset.d.cts +26 -0
- package/dist/reset.d.mts +26 -0
- package/dist/reset.d.ts +26 -0
- package/dist/reset.mjs +4 -0
- package/dist/screen.cjs +41 -0
- package/dist/screen.d.cts +234 -0
- package/dist/screen.d.mts +234 -0
- package/dist/screen.d.ts +234 -0
- package/dist/screen.mjs +29 -0
- package/dist/scroll.cjs +17 -3
- package/dist/scroll.d.cts +67 -4
- package/dist/scroll.d.mts +67 -4
- package/dist/scroll.d.ts +67 -4
- package/dist/scroll.mjs +16 -4
- package/dist/status.cjs +147 -0
- package/dist/status.d.cts +501 -0
- package/dist/status.d.mts +501 -0
- package/dist/status.d.ts +501 -0
- package/dist/status.mjs +104 -0
- package/dist/strip.d.cts +23 -1
- package/dist/strip.d.mts +22 -2
- package/dist/strip.d.ts +23 -1
- package/dist/termcap.cjs +33 -0
- package/dist/termcap.d.cts +38 -0
- package/dist/termcap.d.mts +38 -0
- package/dist/termcap.d.ts +38 -0
- package/dist/termcap.mjs +27 -0
- package/dist/title.cjs +31 -0
- package/dist/title.d.cts +185 -0
- package/dist/title.d.mts +185 -0
- package/dist/title.d.ts +185 -0
- package/dist/title.mjs +20 -0
- package/dist/window-ops.cjs +85 -0
- package/dist/window-ops.d.cts +418 -0
- package/dist/window-ops.d.mts +418 -0
- package/dist/window-ops.d.ts +418 -0
- package/dist/window-ops.mjs +63 -0
- package/dist/xterm.cjs +48 -0
- package/dist/xterm.d.cts +94 -0
- package/dist/xterm.d.mts +94 -0
- package/dist/xterm.d.ts +94 -0
- package/dist/xterm.mjs +35 -0
- package/package.json +153 -9
- package/dist/link.cjs +0 -9
- package/dist/link.d.cts +0 -3
- package/dist/link.d.mts +0 -3
- package/dist/link.d.ts +0 -3
- package/dist/link.mjs +0 -7
- package/dist/packem_shared/constants-CqXMfQy0.mjs +0 -7
- package/dist/packem_shared/cursor-2tHgT9r6.cjs +0 -57
- package/dist/packem_shared/cursor-CDCWqbC9.mjs +0 -42
package/dist/erase.mjs
CHANGED
|
@@ -1,23 +1,49 @@
|
|
|
1
|
-
import { C as CSI } from './packem_shared/constants-
|
|
2
|
-
import {
|
|
1
|
+
import { C as CSI } from './packem_shared/constants-CE7WkXh_.mjs';
|
|
2
|
+
import { u as cursorUp, t as cursorToColumn1 } from './packem_shared/cursor-DhFQcQ9g.mjs';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var EraseDisplayMode = /* @__PURE__ */ ((EraseDisplayMode2) => {
|
|
7
|
+
EraseDisplayMode2[EraseDisplayMode2["EntireScreen"] = 2] = "EntireScreen";
|
|
8
|
+
EraseDisplayMode2[EraseDisplayMode2["EntireScreenAndScrollback"] = 3] = "EntireScreenAndScrollback";
|
|
9
|
+
EraseDisplayMode2[EraseDisplayMode2["ToBeginning"] = 1] = "ToBeginning";
|
|
10
|
+
EraseDisplayMode2[EraseDisplayMode2["ToEnd"] = 0] = "ToEnd";
|
|
11
|
+
return EraseDisplayMode2;
|
|
12
|
+
})(EraseDisplayMode || {});
|
|
13
|
+
const eraseDisplay = /* @__PURE__ */ __name((mode) => {
|
|
14
|
+
const validMode = mode >= 0 && mode <= 3 ? mode : 0 /* ToEnd */;
|
|
15
|
+
return `${CSI + (validMode === 0 /* ToEnd */ ? "" : String(validMode))}J`;
|
|
16
|
+
}, "eraseDisplay");
|
|
17
|
+
var EraseLineMode = /* @__PURE__ */ ((EraseLineMode2) => {
|
|
18
|
+
EraseLineMode2[EraseLineMode2["EntireLine"] = 2] = "EntireLine";
|
|
19
|
+
EraseLineMode2[EraseLineMode2["ToBeginning"] = 1] = "ToBeginning";
|
|
20
|
+
EraseLineMode2[EraseLineMode2["ToEnd"] = 0] = "ToEnd";
|
|
21
|
+
return EraseLineMode2;
|
|
22
|
+
})(EraseLineMode || {});
|
|
23
|
+
const eraseInLine = /* @__PURE__ */ __name((mode) => {
|
|
24
|
+
const validMode = mode >= 0 && mode <= 2 ? mode : 0 /* ToEnd */;
|
|
25
|
+
return `${CSI + (validMode === 0 /* ToEnd */ ? "" : String(validMode))}K`;
|
|
26
|
+
}, "eraseInLine");
|
|
27
|
+
const eraseDown = eraseDisplay(0 /* ToEnd */);
|
|
28
|
+
const eraseLine = eraseInLine(2 /* EntireLine */);
|
|
29
|
+
const eraseLineEnd = eraseInLine(0 /* ToEnd */);
|
|
30
|
+
const eraseLineStart = eraseInLine(1 /* ToBeginning */);
|
|
10
31
|
const eraseLines = /* @__PURE__ */ __name((count) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
clear += eraseLine + (index < count - 1 ? cursorUp() : "");
|
|
32
|
+
if (count <= 0) {
|
|
33
|
+
return "";
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
|
|
35
|
+
let clear = "";
|
|
36
|
+
for (let index = 0; index < count; index += 1) {
|
|
37
|
+
clear += eraseLine;
|
|
38
|
+
if (index < count - 1) {
|
|
39
|
+
clear += cursorUp();
|
|
40
|
+
}
|
|
17
41
|
}
|
|
42
|
+
clear += cursorToColumn1;
|
|
18
43
|
return clear;
|
|
19
44
|
}, "eraseLines");
|
|
20
|
-
const eraseScreen =
|
|
21
|
-
const eraseUp =
|
|
45
|
+
const eraseScreen = eraseDisplay(2 /* EntireScreen */);
|
|
46
|
+
const eraseUp = eraseDisplay(1 /* ToBeginning */);
|
|
47
|
+
const eraseScreenAndScrollback = eraseDisplay(3 /* EntireScreenAndScrollback */);
|
|
22
48
|
|
|
23
|
-
export { eraseDown, eraseLine, eraseLineEnd, eraseLineStart, eraseLines, eraseScreen, eraseUp };
|
|
49
|
+
export { EraseDisplayMode, EraseLineMode, eraseDisplay, eraseDown, eraseInLine, eraseLine, eraseLineEnd, eraseLineStart, eraseLines, eraseScreen, eraseScreenAndScrollback, eraseUp };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current environment is a browser-like environment.
|
|
3
|
+
* It specifically checks for the presence of `globalThis.window.document`.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Indicates whether the code is running inside Apple's Terminal.app.
|
|
7
|
+
* This is true if not in a browser and the `TERM_PROGRAM` environment variable is "Apple_Terminal".
|
|
8
|
+
*/
|
|
9
|
+
export declare const isTerminalApp: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates whether the current platform is Windows.
|
|
12
|
+
* This is true if not in a browser and `process.platform` is "win32".
|
|
13
|
+
*/
|
|
14
|
+
export declare const isWindows: boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current environment is a browser-like environment.
|
|
3
|
+
* It specifically checks for the presence of `globalThis.window.document`.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Indicates whether the code is running inside Apple's Terminal.app.
|
|
7
|
+
* This is true if not in a browser and the `TERM_PROGRAM` environment variable is "Apple_Terminal".
|
|
8
|
+
*/
|
|
9
|
+
export declare const isTerminalApp: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates whether the current platform is Windows.
|
|
12
|
+
* This is true if not in a browser and `process.platform` is "win32".
|
|
13
|
+
*/
|
|
14
|
+
export declare const isWindows: boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current environment is a browser-like environment.
|
|
3
|
+
* It specifically checks for the presence of `globalThis.window.document`.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Indicates whether the code is running inside Apple's Terminal.app.
|
|
7
|
+
* This is true if not in a browser and the `TERM_PROGRAM` environment variable is "Apple_Terminal".
|
|
8
|
+
*/
|
|
9
|
+
export declare const isTerminalApp: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Indicates whether the current platform is Windows.
|
|
12
|
+
* This is true if not in a browser and `process.platform` is "win32".
|
|
13
|
+
*/
|
|
14
|
+
export declare const isWindows: boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const constants = require('./packem_shared/constants-BK26O-46.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
const hyperlink = /* @__PURE__ */ __name((text, url) => [constants.OSC, "8", constants.SEP, constants.SEP, url, constants.BEL, text, constants.OSC, "8", constants.SEP, constants.SEP, constants.BEL].join(""), "hyperlink");
|
|
8
|
+
|
|
9
|
+
module.exports = hyperlink;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a clickable hyperlink in the terminal.
|
|
3
|
+
*
|
|
4
|
+
* This function constructs an ANSI escape sequence that, when printed to a compatible terminal,
|
|
5
|
+
* renders as a clickable link. The link's visible text and its target URL are specified
|
|
6
|
+
* by the `text` and `url` parameters, respectively.
|
|
7
|
+
*
|
|
8
|
+
* For information on terminal support for hyperlinks, see this
|
|
9
|
+
* [Gist by Egmont Kob](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda).
|
|
10
|
+
* To programmatically check for hyperlink support in the current environment,
|
|
11
|
+
* consider using a library like [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks).
|
|
12
|
+
* @param text The visible text of the link.
|
|
13
|
+
* @param url The URL the link should point to.
|
|
14
|
+
* @returns A string representing the ANSI escape sequence for the hyperlink.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { hyperlink } from "@visulima/ansi/hyperlink"; // Adjust import path as needed
|
|
18
|
+
*
|
|
19
|
+
* const aLink = hyperlink("Visulima", "https://www.visulima.com");
|
|
20
|
+
* console.log(`Visit ${aLink} for more information.`);
|
|
21
|
+
* // In a supported terminal, this will output:
|
|
22
|
+
* // Visit Visulima for more information. (where "Visulima" is a clickable link)
|
|
23
|
+
* ```
|
|
24
|
+
* @see {@link https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda} for supported terminals.
|
|
25
|
+
*/
|
|
26
|
+
declare const hyperlink: (text: string, url: string) => string;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export = hyperlink;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a clickable hyperlink in the terminal.
|
|
3
|
+
*
|
|
4
|
+
* This function constructs an ANSI escape sequence that, when printed to a compatible terminal,
|
|
5
|
+
* renders as a clickable link. The link's visible text and its target URL are specified
|
|
6
|
+
* by the `text` and `url` parameters, respectively.
|
|
7
|
+
*
|
|
8
|
+
* For information on terminal support for hyperlinks, see this
|
|
9
|
+
* [Gist by Egmont Kob](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda).
|
|
10
|
+
* To programmatically check for hyperlink support in the current environment,
|
|
11
|
+
* consider using a library like [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks).
|
|
12
|
+
* @param text The visible text of the link.
|
|
13
|
+
* @param url The URL the link should point to.
|
|
14
|
+
* @returns A string representing the ANSI escape sequence for the hyperlink.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { hyperlink } from "@visulima/ansi/hyperlink"; // Adjust import path as needed
|
|
18
|
+
*
|
|
19
|
+
* const aLink = hyperlink("Visulima", "https://www.visulima.com");
|
|
20
|
+
* console.log(`Visit ${aLink} for more information.`);
|
|
21
|
+
* // In a supported terminal, this will output:
|
|
22
|
+
* // Visit Visulima for more information. (where "Visulima" is a clickable link)
|
|
23
|
+
* ```
|
|
24
|
+
* @see {@link https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda} for supported terminals.
|
|
25
|
+
*/
|
|
26
|
+
declare const hyperlink: (text: string, url: string) => string;
|
|
27
|
+
export default hyperlink;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a clickable hyperlink in the terminal.
|
|
3
|
+
*
|
|
4
|
+
* This function constructs an ANSI escape sequence that, when printed to a compatible terminal,
|
|
5
|
+
* renders as a clickable link. The link's visible text and its target URL are specified
|
|
6
|
+
* by the `text` and `url` parameters, respectively.
|
|
7
|
+
*
|
|
8
|
+
* For information on terminal support for hyperlinks, see this
|
|
9
|
+
* [Gist by Egmont Kob](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda).
|
|
10
|
+
* To programmatically check for hyperlink support in the current environment,
|
|
11
|
+
* consider using a library like [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks).
|
|
12
|
+
* @param text The visible text of the link.
|
|
13
|
+
* @param url The URL the link should point to.
|
|
14
|
+
* @returns A string representing the ANSI escape sequence for the hyperlink.
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { hyperlink } from "@visulima/ansi/hyperlink"; // Adjust import path as needed
|
|
18
|
+
*
|
|
19
|
+
* const aLink = hyperlink("Visulima", "https://www.visulima.com");
|
|
20
|
+
* console.log(`Visit ${aLink} for more information.`);
|
|
21
|
+
* // In a supported terminal, this will output:
|
|
22
|
+
* // Visit Visulima for more information. (where "Visulima" is a clickable link)
|
|
23
|
+
* ```
|
|
24
|
+
* @see {@link https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda} for supported terminals.
|
|
25
|
+
*/
|
|
26
|
+
declare const hyperlink: (text: string, url: string) => string;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export = hyperlink;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { O as OSC, S as SEP, B as BEL } from './packem_shared/constants-CE7WkXh_.mjs';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
const hyperlink = /* @__PURE__ */ __name((text, url) => [OSC, "8", SEP, SEP, url, BEL, text, OSC, "8", SEP, SEP, BEL].join(""), "hyperlink");
|
|
6
|
+
|
|
7
|
+
export { hyperlink as default };
|
package/dist/image.cjs
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const node_buffer = require('node:buffer');
|
|
6
|
+
const constants = require('./packem_shared/constants-BK26O-46.cjs');
|
|
4
7
|
|
|
5
8
|
var __defProp = Object.defineProperty;
|
|
6
9
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
10
|
const image = /* @__PURE__ */ __name((data, options = {}) => {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return "";
|
|
13
|
+
}
|
|
8
14
|
let returnValue = `${constants.OSC}1337;File=inline=1`;
|
|
9
|
-
if (options.width) {
|
|
15
|
+
if (options.width !== void 0) {
|
|
10
16
|
returnValue += `;width=${options.width}`;
|
|
11
17
|
}
|
|
12
|
-
if (options.height) {
|
|
18
|
+
if (options.height !== void 0) {
|
|
13
19
|
returnValue += `;height=${options.height}`;
|
|
14
20
|
}
|
|
15
21
|
if (options.preserveAspectRatio === false) {
|
|
16
22
|
returnValue += ";preserveAspectRatio=0";
|
|
17
23
|
}
|
|
18
|
-
|
|
24
|
+
const base64Data = node_buffer.Buffer.from(data).toString("base64");
|
|
25
|
+
return `${returnValue}:${base64Data}${constants.BEL}`;
|
|
19
26
|
}, "image");
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
exports.image = image;
|
package/dist/image.d.cts
CHANGED
|
@@ -1,62 +1,73 @@
|
|
|
1
|
+
import type { LiteralUnion } from "type-fest";
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
| symbol
|
|
13
|
-
| bigint;
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
17
|
-
interface SymbolConstructor {
|
|
18
|
-
readonly observable: symbol;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
24
|
-
|
|
25
|
-
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
26
|
-
|
|
27
|
-
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
28
|
-
|
|
29
|
-
@example
|
|
30
|
-
```
|
|
31
|
-
import type {LiteralUnion} from 'type-fest';
|
|
32
|
-
|
|
33
|
-
// Before
|
|
34
|
-
|
|
35
|
-
type Pet = 'dog' | 'cat' | string;
|
|
36
|
-
|
|
37
|
-
const pet: Pet = '';
|
|
38
|
-
// Start typing in your TypeScript-enabled IDE.
|
|
39
|
-
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
40
|
-
|
|
41
|
-
// After
|
|
42
|
-
|
|
43
|
-
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
44
|
-
|
|
45
|
-
const pet: Pet2 = '';
|
|
46
|
-
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
@category Type
|
|
50
|
-
*/
|
|
51
|
-
type LiteralUnion<
|
|
52
|
-
LiteralType,
|
|
53
|
-
BaseType extends Primitive,
|
|
54
|
-
> = LiteralType | (BaseType & Record<never, never>);
|
|
55
|
-
|
|
56
|
-
declare const image: (data: Uint8Array, options?: {
|
|
3
|
+
* Options for controlling the display of an inline image in iTerm2.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The display height of the image. It can be specified as:
|
|
8
|
+
* - A number: Interpreted as the number of character cells (e.g., `10`).
|
|
9
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"100px"`).
|
|
10
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's height (e.g., `"50%"`).
|
|
11
|
+
* - The string `"auto"`: The image's inherent height will be used, or the terminal will decide.
|
|
12
|
+
*/
|
|
57
13
|
readonly height?: LiteralUnion<"auto", number | string>;
|
|
14
|
+
/**
|
|
15
|
+
* Controls whether the image's aspect ratio is preserved when scaling.
|
|
16
|
+
* - If `true` (default), the aspect ratio is preserved.
|
|
17
|
+
* - If `false`, the image may be stretched to fit the specified width and height.
|
|
18
|
+
* Corresponds to the `preserveAspectRatio` argument in the iTerm2 sequence (`1` for true, `0` for false).
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
58
21
|
readonly preserveAspectRatio?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The display width of the image. It can be specified as:
|
|
24
|
+
* - A number: Interpreted as the number of character cells (e.g., `20`).
|
|
25
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"200px"`).
|
|
26
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's width (e.g., `"75%"`).
|
|
27
|
+
* - The string `"auto"`: The image's inherent width will be used, or the terminal will decide.
|
|
28
|
+
*/
|
|
59
29
|
readonly width?: LiteralUnion<"auto", number | string>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generates an ANSI escape sequence for displaying an image inline, primarily for iTerm2.
|
|
33
|
+
*
|
|
34
|
+
* This function constructs a proprietary iTerm2 escape sequence (`OSC 1337 ; File = [arguments] : <base64_data> BEL`)
|
|
35
|
+
* that allows raw image data to be displayed directly in the terminal.
|
|
36
|
+
* @param data The raw image data as a `Uint8Array`. This data will be Base64 encoded.
|
|
37
|
+
* @param options Optional parameters to control how the image is displayed (e.g., width, height, aspect ratio).
|
|
38
|
+
* See {@link ImageOptions}.
|
|
39
|
+
* @returns A string containing the ANSI escape sequence for displaying the image in iTerm2.
|
|
40
|
+
* Returns an empty string if `data` is null or undefined, though TypeScript should prevent this.
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { image } from '@visulima/ansi/image'; // Adjust import path
|
|
44
|
+
* import { promises as fs } from 'fs';
|
|
45
|
+
*
|
|
46
|
+
* async function displayImage() {
|
|
47
|
+
* try {
|
|
48
|
+
* const imageData = await fs.readFile('path/to/your/image.png');
|
|
49
|
+
* const imageSequence = image(new Uint8Array(imageData), {
|
|
50
|
+
* width: 50, // 50 character cells wide
|
|
51
|
+
* height: "auto",
|
|
52
|
+
* preserveAspectRatio: true,
|
|
53
|
+
* });
|
|
54
|
+
* console.log(imageSequence);
|
|
55
|
+
* } catch (error) {
|
|
56
|
+
* console.error("Error reading or displaying image:", error);
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* displayImage();
|
|
61
|
+
* ```
|
|
62
|
+
* @remarks
|
|
63
|
+
* - This sequence is specific to iTerm2 and may not work in other terminal emulators.
|
|
64
|
+
* - For Node.js environments, `Buffer.from(data).toString("base64")` is used for Base64 encoding.
|
|
65
|
+
* In browser environments, a polyfill or an alternative method for Base64 encoding `Uint8Array` would be necessary
|
|
66
|
+
* if `Buffer` is not available (e.g., `btoa(String.fromCharCode(...data))` after careful handling of binary data).
|
|
67
|
+
* - The `name` parameter (for filename) is not directly supported by this simplified helper but is part of the
|
|
68
|
+
* full iTerm2 inline image protocol. For more advanced features, consider using the more detailed iTerm2 sequence
|
|
69
|
+
* builders in `iterm2/` files.
|
|
70
|
+
* @see {@link https://iterm2.com/documentation-images.html} iTerm2 Inline Images Protocol.
|
|
71
|
+
* @see {@link ImageOptions}
|
|
72
|
+
*/
|
|
73
|
+
export declare const image: (data: Uint8Array, options?: ImageOptions) => string;
|
package/dist/image.d.mts
CHANGED
|
@@ -1,62 +1,73 @@
|
|
|
1
|
+
import type { LiteralUnion } from "type-fest";
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
| symbol
|
|
13
|
-
| bigint;
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
17
|
-
interface SymbolConstructor {
|
|
18
|
-
readonly observable: symbol;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
24
|
-
|
|
25
|
-
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
26
|
-
|
|
27
|
-
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
28
|
-
|
|
29
|
-
@example
|
|
30
|
-
```
|
|
31
|
-
import type {LiteralUnion} from 'type-fest';
|
|
32
|
-
|
|
33
|
-
// Before
|
|
34
|
-
|
|
35
|
-
type Pet = 'dog' | 'cat' | string;
|
|
36
|
-
|
|
37
|
-
const pet: Pet = '';
|
|
38
|
-
// Start typing in your TypeScript-enabled IDE.
|
|
39
|
-
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
40
|
-
|
|
41
|
-
// After
|
|
42
|
-
|
|
43
|
-
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
44
|
-
|
|
45
|
-
const pet: Pet2 = '';
|
|
46
|
-
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
@category Type
|
|
50
|
-
*/
|
|
51
|
-
type LiteralUnion<
|
|
52
|
-
LiteralType,
|
|
53
|
-
BaseType extends Primitive,
|
|
54
|
-
> = LiteralType | (BaseType & Record<never, never>);
|
|
55
|
-
|
|
56
|
-
declare const image: (data: Uint8Array, options?: {
|
|
3
|
+
* Options for controlling the display of an inline image in iTerm2.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The display height of the image. It can be specified as:
|
|
8
|
+
* - A number: Interpreted as the number of character cells (e.g., `10`).
|
|
9
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"100px"`).
|
|
10
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's height (e.g., `"50%"`).
|
|
11
|
+
* - The string `"auto"`: The image's inherent height will be used, or the terminal will decide.
|
|
12
|
+
*/
|
|
57
13
|
readonly height?: LiteralUnion<"auto", number | string>;
|
|
14
|
+
/**
|
|
15
|
+
* Controls whether the image's aspect ratio is preserved when scaling.
|
|
16
|
+
* - If `true` (default), the aspect ratio is preserved.
|
|
17
|
+
* - If `false`, the image may be stretched to fit the specified width and height.
|
|
18
|
+
* Corresponds to the `preserveAspectRatio` argument in the iTerm2 sequence (`1` for true, `0` for false).
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
58
21
|
readonly preserveAspectRatio?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The display width of the image. It can be specified as:
|
|
24
|
+
* - A number: Interpreted as the number of character cells (e.g., `20`).
|
|
25
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"200px"`).
|
|
26
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's width (e.g., `"75%"`).
|
|
27
|
+
* - The string `"auto"`: The image's inherent width will be used, or the terminal will decide.
|
|
28
|
+
*/
|
|
59
29
|
readonly width?: LiteralUnion<"auto", number | string>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generates an ANSI escape sequence for displaying an image inline, primarily for iTerm2.
|
|
33
|
+
*
|
|
34
|
+
* This function constructs a proprietary iTerm2 escape sequence (`OSC 1337 ; File = [arguments] : <base64_data> BEL`)
|
|
35
|
+
* that allows raw image data to be displayed directly in the terminal.
|
|
36
|
+
* @param data The raw image data as a `Uint8Array`. This data will be Base64 encoded.
|
|
37
|
+
* @param options Optional parameters to control how the image is displayed (e.g., width, height, aspect ratio).
|
|
38
|
+
* See {@link ImageOptions}.
|
|
39
|
+
* @returns A string containing the ANSI escape sequence for displaying the image in iTerm2.
|
|
40
|
+
* Returns an empty string if `data` is null or undefined, though TypeScript should prevent this.
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { image } from '@visulima/ansi/image'; // Adjust import path
|
|
44
|
+
* import { promises as fs } from 'fs';
|
|
45
|
+
*
|
|
46
|
+
* async function displayImage() {
|
|
47
|
+
* try {
|
|
48
|
+
* const imageData = await fs.readFile('path/to/your/image.png');
|
|
49
|
+
* const imageSequence = image(new Uint8Array(imageData), {
|
|
50
|
+
* width: 50, // 50 character cells wide
|
|
51
|
+
* height: "auto",
|
|
52
|
+
* preserveAspectRatio: true,
|
|
53
|
+
* });
|
|
54
|
+
* console.log(imageSequence);
|
|
55
|
+
* } catch (error) {
|
|
56
|
+
* console.error("Error reading or displaying image:", error);
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* displayImage();
|
|
61
|
+
* ```
|
|
62
|
+
* @remarks
|
|
63
|
+
* - This sequence is specific to iTerm2 and may not work in other terminal emulators.
|
|
64
|
+
* - For Node.js environments, `Buffer.from(data).toString("base64")` is used for Base64 encoding.
|
|
65
|
+
* In browser environments, a polyfill or an alternative method for Base64 encoding `Uint8Array` would be necessary
|
|
66
|
+
* if `Buffer` is not available (e.g., `btoa(String.fromCharCode(...data))` after careful handling of binary data).
|
|
67
|
+
* - The `name` parameter (for filename) is not directly supported by this simplified helper but is part of the
|
|
68
|
+
* full iTerm2 inline image protocol. For more advanced features, consider using the more detailed iTerm2 sequence
|
|
69
|
+
* builders in `iterm2/` files.
|
|
70
|
+
* @see {@link https://iterm2.com/documentation-images.html} iTerm2 Inline Images Protocol.
|
|
71
|
+
* @see {@link ImageOptions}
|
|
72
|
+
*/
|
|
73
|
+
export declare const image: (data: Uint8Array, options?: ImageOptions) => string;
|
package/dist/image.d.ts
CHANGED
|
@@ -1,62 +1,73 @@
|
|
|
1
|
+
import type { LiteralUnion } from "type-fest";
|
|
1
2
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
| symbol
|
|
13
|
-
| bigint;
|
|
14
|
-
|
|
15
|
-
declare global {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
17
|
-
interface SymbolConstructor {
|
|
18
|
-
readonly observable: symbol;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
24
|
-
|
|
25
|
-
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
26
|
-
|
|
27
|
-
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
28
|
-
|
|
29
|
-
@example
|
|
30
|
-
```
|
|
31
|
-
import type {LiteralUnion} from 'type-fest';
|
|
32
|
-
|
|
33
|
-
// Before
|
|
34
|
-
|
|
35
|
-
type Pet = 'dog' | 'cat' | string;
|
|
36
|
-
|
|
37
|
-
const pet: Pet = '';
|
|
38
|
-
// Start typing in your TypeScript-enabled IDE.
|
|
39
|
-
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
40
|
-
|
|
41
|
-
// After
|
|
42
|
-
|
|
43
|
-
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
44
|
-
|
|
45
|
-
const pet: Pet2 = '';
|
|
46
|
-
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
@category Type
|
|
50
|
-
*/
|
|
51
|
-
type LiteralUnion<
|
|
52
|
-
LiteralType,
|
|
53
|
-
BaseType extends Primitive,
|
|
54
|
-
> = LiteralType | (BaseType & Record<never, never>);
|
|
55
|
-
|
|
56
|
-
declare const image: (data: Uint8Array, options?: {
|
|
3
|
+
* Options for controlling the display of an inline image in iTerm2.
|
|
4
|
+
*/
|
|
5
|
+
export interface ImageOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The display height of the image. It can be specified as:
|
|
8
|
+
* - A number: Interpreted as the number of character cells (e.g., `10`).
|
|
9
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"100px"`).
|
|
10
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's height (e.g., `"50%"`).
|
|
11
|
+
* - The string `"auto"`: The image's inherent height will be used, or the terminal will decide.
|
|
12
|
+
*/
|
|
57
13
|
readonly height?: LiteralUnion<"auto", number | string>;
|
|
14
|
+
/**
|
|
15
|
+
* Controls whether the image's aspect ratio is preserved when scaling.
|
|
16
|
+
* - If `true` (default), the aspect ratio is preserved.
|
|
17
|
+
* - If `false`, the image may be stretched to fit the specified width and height.
|
|
18
|
+
* Corresponds to the `preserveAspectRatio` argument in the iTerm2 sequence (`1` for true, `0` for false).
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
58
21
|
readonly preserveAspectRatio?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The display width of the image. It can be specified as:
|
|
24
|
+
* - A number: Interpreted as the number of character cells (e.g., `20`).
|
|
25
|
+
* - A string with `px`: Interpreted as pixels (e.g., `"200px"`).
|
|
26
|
+
* - A string with `%`: Interpreted as a percentage of the terminal session's width (e.g., `"75%"`).
|
|
27
|
+
* - The string `"auto"`: The image's inherent width will be used, or the terminal will decide.
|
|
28
|
+
*/
|
|
59
29
|
readonly width?: LiteralUnion<"auto", number | string>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generates an ANSI escape sequence for displaying an image inline, primarily for iTerm2.
|
|
33
|
+
*
|
|
34
|
+
* This function constructs a proprietary iTerm2 escape sequence (`OSC 1337 ; File = [arguments] : <base64_data> BEL`)
|
|
35
|
+
* that allows raw image data to be displayed directly in the terminal.
|
|
36
|
+
* @param data The raw image data as a `Uint8Array`. This data will be Base64 encoded.
|
|
37
|
+
* @param options Optional parameters to control how the image is displayed (e.g., width, height, aspect ratio).
|
|
38
|
+
* See {@link ImageOptions}.
|
|
39
|
+
* @returns A string containing the ANSI escape sequence for displaying the image in iTerm2.
|
|
40
|
+
* Returns an empty string if `data` is null or undefined, though TypeScript should prevent this.
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { image } from '@visulima/ansi/image'; // Adjust import path
|
|
44
|
+
* import { promises as fs } from 'fs';
|
|
45
|
+
*
|
|
46
|
+
* async function displayImage() {
|
|
47
|
+
* try {
|
|
48
|
+
* const imageData = await fs.readFile('path/to/your/image.png');
|
|
49
|
+
* const imageSequence = image(new Uint8Array(imageData), {
|
|
50
|
+
* width: 50, // 50 character cells wide
|
|
51
|
+
* height: "auto",
|
|
52
|
+
* preserveAspectRatio: true,
|
|
53
|
+
* });
|
|
54
|
+
* console.log(imageSequence);
|
|
55
|
+
* } catch (error) {
|
|
56
|
+
* console.error("Error reading or displaying image:", error);
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
* displayImage();
|
|
61
|
+
* ```
|
|
62
|
+
* @remarks
|
|
63
|
+
* - This sequence is specific to iTerm2 and may not work in other terminal emulators.
|
|
64
|
+
* - For Node.js environments, `Buffer.from(data).toString("base64")` is used for Base64 encoding.
|
|
65
|
+
* In browser environments, a polyfill or an alternative method for Base64 encoding `Uint8Array` would be necessary
|
|
66
|
+
* if `Buffer` is not available (e.g., `btoa(String.fromCharCode(...data))` after careful handling of binary data).
|
|
67
|
+
* - The `name` parameter (for filename) is not directly supported by this simplified helper but is part of the
|
|
68
|
+
* full iTerm2 inline image protocol. For more advanced features, consider using the more detailed iTerm2 sequence
|
|
69
|
+
* builders in `iterm2/` files.
|
|
70
|
+
* @see {@link https://iterm2.com/documentation-images.html} iTerm2 Inline Images Protocol.
|
|
71
|
+
* @see {@link ImageOptions}
|
|
72
|
+
*/
|
|
73
|
+
export declare const image: (data: Uint8Array, options?: ImageOptions) => string;
|