@visulima/ansi 1.0.17 → 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 +37 -0
- package/LICENSE.md +76 -74
- package/README.md +336 -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 +20 -3
- 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 +3 -3
- 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/packem_shared/{restoreCursor-UYYzYxTZ.mjs → restoreCursor-C6pNB8UY.mjs} +4 -21
- package/dist/packem_shared/{restoreCursor-Bjacc7pa.cjs → restoreCursor-DC_ZKZwT.cjs} +4 -21
- 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.cjs +1 -1
- package/dist/strip.d.cts +23 -1
- package/dist/strip.d.mts +22 -2
- package/dist/strip.d.ts +23 -1
- package/dist/strip.mjs +1 -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-BzPDI1bk.mjs +0 -42
- package/dist/packem_shared/cursor-DSN9nA2g.cjs +0 -57
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { LiteralUnion } from "type-fest";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the special string value `'auto'` used for iTerm2 image or file dimensions.
|
|
4
|
+
* When `'auto'` is used for width or height, the terminal (iTerm2) determines the appropriate dimension
|
|
5
|
+
* based on the image's inherent size or other context.
|
|
6
|
+
* @example `width: IT2_AUTO`
|
|
7
|
+
*/
|
|
8
|
+
export declare const IT2_AUTO: string;
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number as a string representing a dimension in character cells for iTerm2.
|
|
11
|
+
* iTerm2 interprets plain numbers for width/height as character cell counts.
|
|
12
|
+
* @param n The number of character cells.
|
|
13
|
+
* @returns A string representation of the number (e.g., `10` becomes `"10"`).
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const widthInCells = it2Cells(20); // "20"
|
|
17
|
+
* const sequence = `File=width=${widthInCells}`;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const it2Cells: (n: number) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a number as a string representing a dimension in pixels for iTerm2.
|
|
23
|
+
* Appends `px` to the number.
|
|
24
|
+
* @param n The number of pixels.
|
|
25
|
+
* @returns A string representing the dimension in pixels (e.g., `100` becomes `"100px"`).
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const heightInPixels = it2Pixels(150);
|
|
29
|
+
* const sequence = `File=height=${heightInPixels}`;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const it2Pixels: (n: number) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Formats a number as a string representing a dimension as a percentage for iTerm2.
|
|
35
|
+
* Appends `%` to the number.
|
|
36
|
+
* @param n The percentage value (e.g., `50` for 50%).
|
|
37
|
+
* @returns A string representing the dimension as a percentage (e.g., `50` becomes `"50%"`).
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const widthAsPercentage = it2Percent(75);
|
|
41
|
+
* const sequence = `File=width=${widthAsPercentage}`;
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const it2Percent: (n: number) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Defines the interface for any iTerm2 OSC 1337 payload object.
|
|
47
|
+
*
|
|
48
|
+
* An OSC 1337 sequence has the general form: `OSC 1337 ; <payload_string> BEL`.
|
|
49
|
+
* Objects implementing this interface are responsible for generating that `<payload_string>`
|
|
50
|
+
* via their `toString()` method. This allows for a structured way to build various iTerm2 commands.
|
|
51
|
+
* @see {@link iTerm2} function which consumes objects of this type.
|
|
52
|
+
*/
|
|
53
|
+
export interface IITerm2Payload {
|
|
54
|
+
/**
|
|
55
|
+
* Converts the payload object into its specific string representation required for an iTerm2 OSC 1337 command.
|
|
56
|
+
* For example, for a file transfer, this might return `"File=name=...;size=...:content..."`.
|
|
57
|
+
* @returns The string payload part of the OSC 1337 sequence.
|
|
58
|
+
*/
|
|
59
|
+
toString: () => string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Defines the properties for an iTerm2 file transfer or inline image display command (`File=...`).
|
|
63
|
+
* These correspond to the key-value pairs used within the `File=` argument of the OSC 1337 sequence.
|
|
64
|
+
* @see {@link https://iterm2.com/documentation-escape-codes.html} iTerm2 Escape Codes (search for `File=`)
|
|
65
|
+
* @see {@link https://iterm2.com/documentation-images.html} iTerm2 Inline Images Protocol
|
|
66
|
+
*/
|
|
67
|
+
export interface ITerm2FileProperties {
|
|
68
|
+
/**
|
|
69
|
+
* The Base64 encoded content of the file or image.
|
|
70
|
+
* This is typically used when `inline=1` is set for images, or for transferring small files directly
|
|
71
|
+
* within the escape sequence. For larger files, multipart transfer is recommended.
|
|
72
|
+
* @remarks The `ITerm2File` class can handle the Base64 encoding of `Uint8Array` data automatically.
|
|
73
|
+
*/
|
|
74
|
+
content?: string;
|
|
75
|
+
/**
|
|
76
|
+
* If `true`, instructs the terminal not to move the cursor after displaying an inline image.
|
|
77
|
+
* Corresponds to `doNotMoveCursor=1` in the sequence.
|
|
78
|
+
* This is a WezTerm extension, also supported by iTerm2 beta/nightly builds as of some versions.
|
|
79
|
+
* @default false (cursor behavior is default terminal behavior)
|
|
80
|
+
*/
|
|
81
|
+
doNotMoveCursor?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The display height of the image or file placeholder.
|
|
84
|
+
* Can be:
|
|
85
|
+
* - A number (interpreted as character cells, e.g., `10`).
|
|
86
|
+
* - A string with units: `"Npx"` (N pixels), `"N%"` (N percent of session height).
|
|
87
|
+
* - The string {@link IT2_AUTO} (`"auto"`) for automatic sizing.
|
|
88
|
+
* Use helper functions like {@link it2Cells}, {@link it2Pixels}, {@link it2Percent} for formatting if needed.
|
|
89
|
+
* @example `10`, `"100px"`, `"50%"`, `IT2_AUTO`
|
|
90
|
+
*/
|
|
91
|
+
height?: LiteralUnion<typeof IT2_AUTO, number | string>;
|
|
92
|
+
/**
|
|
93
|
+
* Controls aspect ratio preservation for inline images.
|
|
94
|
+
* - If `true` (or omitted), the aspect ratio *is* preserved (`preserveAspectRatio=1`, which is the default iTerm2 behavior if the param is absent).
|
|
95
|
+
* - If `false`, the aspect ratio is *not* preserved, and the image may stretch (`preserveAspectRatio=0`).
|
|
96
|
+
* @remarks Note the slight inversion: this property `ignoreAspectRatio: true` means `preserveAspectRatio=0` in the sequence.
|
|
97
|
+
* The default iTerm2 behavior *is* to preserve aspect ratio if the `preserveAspectRatio` parameter is not given.
|
|
98
|
+
* So, to *not* preserve, you set this to true to *add* `preserveAspectRatio=0`.
|
|
99
|
+
* If you want to preserve (default), you can omit this or set it to `false`.
|
|
100
|
+
* @default false (meaning aspect ratio is preserved by iTerm2 default unless overridden)
|
|
101
|
+
*/
|
|
102
|
+
ignoreAspectRatio?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* If `true`, the file (typically an image) should be displayed inline in the terminal.
|
|
105
|
+
* Corresponds to `inline=1` in the sequence.
|
|
106
|
+
* If `false` or omitted, iTerm2 might prompt for download or handle based on file type.
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
inline?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* The name of the file. This is displayed in UI elements (like a download prompt or image info)
|
|
112
|
+
* and used as the default filename if downloaded.
|
|
113
|
+
* The name **must be Base64 encoded** if it contains special characters (like `;`, `=`, or non-ASCII characters)
|
|
114
|
+
* to ensure correct parsing of the escape sequence by iTerm2.
|
|
115
|
+
* The `ITerm2File` and `ITerm2MultipartFileStart` classes generally expect the name to be pre-encoded if necessary.
|
|
116
|
+
* @example `"bXlmaWxlLnR4dA=="` (Base64 for "myfile.txt")
|
|
117
|
+
*/
|
|
118
|
+
name?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The size of the file in bytes. This is used by iTerm2 for progress indication during downloads
|
|
121
|
+
* or to inform inline display mechanisms.
|
|
122
|
+
* JavaScript `number` type is generally sufficient for typical file sizes (up to `Number.MAX_SAFE_INTEGER`).
|
|
123
|
+
*/
|
|
124
|
+
size?: number;
|
|
125
|
+
/**
|
|
126
|
+
* The display width of the image or file placeholder.
|
|
127
|
+
* Can be:
|
|
128
|
+
* - A number (interpreted as character cells, e.g., `20`).
|
|
129
|
+
* - A string with units: `"Npx"` (N pixels), `"N%"` (N percent of session width).
|
|
130
|
+
* - The string {@link IT2_AUTO} (`"auto"`) for automatic sizing.
|
|
131
|
+
* Use helper functions like {@link it2Cells}, {@link it2Pixels}, {@link it2Percent} for formatting if needed.
|
|
132
|
+
* @example `20`, `"200px"`, `"75%"`, `IT2_AUTO`
|
|
133
|
+
*/
|
|
134
|
+
width?: LiteralUnion<typeof IT2_AUTO, number | string>;
|
|
135
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { LiteralUnion } from "type-fest";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the special string value `'auto'` used for iTerm2 image or file dimensions.
|
|
4
|
+
* When `'auto'` is used for width or height, the terminal (iTerm2) determines the appropriate dimension
|
|
5
|
+
* based on the image's inherent size or other context.
|
|
6
|
+
* @example `width: IT2_AUTO`
|
|
7
|
+
*/
|
|
8
|
+
export declare const IT2_AUTO: string;
|
|
9
|
+
/**
|
|
10
|
+
* Formats a number as a string representing a dimension in character cells for iTerm2.
|
|
11
|
+
* iTerm2 interprets plain numbers for width/height as character cell counts.
|
|
12
|
+
* @param n The number of character cells.
|
|
13
|
+
* @returns A string representation of the number (e.g., `10` becomes `"10"`).
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const widthInCells = it2Cells(20); // "20"
|
|
17
|
+
* const sequence = `File=width=${widthInCells}`;
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const it2Cells: (n: number) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Formats a number as a string representing a dimension in pixels for iTerm2.
|
|
23
|
+
* Appends `px` to the number.
|
|
24
|
+
* @param n The number of pixels.
|
|
25
|
+
* @returns A string representing the dimension in pixels (e.g., `100` becomes `"100px"`).
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const heightInPixels = it2Pixels(150);
|
|
29
|
+
* const sequence = `File=height=${heightInPixels}`;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const it2Pixels: (n: number) => string;
|
|
33
|
+
/**
|
|
34
|
+
* Formats a number as a string representing a dimension as a percentage for iTerm2.
|
|
35
|
+
* Appends `%` to the number.
|
|
36
|
+
* @param n The percentage value (e.g., `50` for 50%).
|
|
37
|
+
* @returns A string representing the dimension as a percentage (e.g., `50` becomes `"50%"`).
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const widthAsPercentage = it2Percent(75);
|
|
41
|
+
* const sequence = `File=width=${widthAsPercentage}`;
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const it2Percent: (n: number) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Defines the interface for any iTerm2 OSC 1337 payload object.
|
|
47
|
+
*
|
|
48
|
+
* An OSC 1337 sequence has the general form: `OSC 1337 ; <payload_string> BEL`.
|
|
49
|
+
* Objects implementing this interface are responsible for generating that `<payload_string>`
|
|
50
|
+
* via their `toString()` method. This allows for a structured way to build various iTerm2 commands.
|
|
51
|
+
* @see {@link iTerm2} function which consumes objects of this type.
|
|
52
|
+
*/
|
|
53
|
+
export interface IITerm2Payload {
|
|
54
|
+
/**
|
|
55
|
+
* Converts the payload object into its specific string representation required for an iTerm2 OSC 1337 command.
|
|
56
|
+
* For example, for a file transfer, this might return `"File=name=...;size=...:content..."`.
|
|
57
|
+
* @returns The string payload part of the OSC 1337 sequence.
|
|
58
|
+
*/
|
|
59
|
+
toString: () => string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Defines the properties for an iTerm2 file transfer or inline image display command (`File=...`).
|
|
63
|
+
* These correspond to the key-value pairs used within the `File=` argument of the OSC 1337 sequence.
|
|
64
|
+
* @see {@link https://iterm2.com/documentation-escape-codes.html} iTerm2 Escape Codes (search for `File=`)
|
|
65
|
+
* @see {@link https://iterm2.com/documentation-images.html} iTerm2 Inline Images Protocol
|
|
66
|
+
*/
|
|
67
|
+
export interface ITerm2FileProperties {
|
|
68
|
+
/**
|
|
69
|
+
* The Base64 encoded content of the file or image.
|
|
70
|
+
* This is typically used when `inline=1` is set for images, or for transferring small files directly
|
|
71
|
+
* within the escape sequence. For larger files, multipart transfer is recommended.
|
|
72
|
+
* @remarks The `ITerm2File` class can handle the Base64 encoding of `Uint8Array` data automatically.
|
|
73
|
+
*/
|
|
74
|
+
content?: string;
|
|
75
|
+
/**
|
|
76
|
+
* If `true`, instructs the terminal not to move the cursor after displaying an inline image.
|
|
77
|
+
* Corresponds to `doNotMoveCursor=1` in the sequence.
|
|
78
|
+
* This is a WezTerm extension, also supported by iTerm2 beta/nightly builds as of some versions.
|
|
79
|
+
* @default false (cursor behavior is default terminal behavior)
|
|
80
|
+
*/
|
|
81
|
+
doNotMoveCursor?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The display height of the image or file placeholder.
|
|
84
|
+
* Can be:
|
|
85
|
+
* - A number (interpreted as character cells, e.g., `10`).
|
|
86
|
+
* - A string with units: `"Npx"` (N pixels), `"N%"` (N percent of session height).
|
|
87
|
+
* - The string {@link IT2_AUTO} (`"auto"`) for automatic sizing.
|
|
88
|
+
* Use helper functions like {@link it2Cells}, {@link it2Pixels}, {@link it2Percent} for formatting if needed.
|
|
89
|
+
* @example `10`, `"100px"`, `"50%"`, `IT2_AUTO`
|
|
90
|
+
*/
|
|
91
|
+
height?: LiteralUnion<typeof IT2_AUTO, number | string>;
|
|
92
|
+
/**
|
|
93
|
+
* Controls aspect ratio preservation for inline images.
|
|
94
|
+
* - If `true` (or omitted), the aspect ratio *is* preserved (`preserveAspectRatio=1`, which is the default iTerm2 behavior if the param is absent).
|
|
95
|
+
* - If `false`, the aspect ratio is *not* preserved, and the image may stretch (`preserveAspectRatio=0`).
|
|
96
|
+
* @remarks Note the slight inversion: this property `ignoreAspectRatio: true` means `preserveAspectRatio=0` in the sequence.
|
|
97
|
+
* The default iTerm2 behavior *is* to preserve aspect ratio if the `preserveAspectRatio` parameter is not given.
|
|
98
|
+
* So, to *not* preserve, you set this to true to *add* `preserveAspectRatio=0`.
|
|
99
|
+
* If you want to preserve (default), you can omit this or set it to `false`.
|
|
100
|
+
* @default false (meaning aspect ratio is preserved by iTerm2 default unless overridden)
|
|
101
|
+
*/
|
|
102
|
+
ignoreAspectRatio?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* If `true`, the file (typically an image) should be displayed inline in the terminal.
|
|
105
|
+
* Corresponds to `inline=1` in the sequence.
|
|
106
|
+
* If `false` or omitted, iTerm2 might prompt for download or handle based on file type.
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
inline?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* The name of the file. This is displayed in UI elements (like a download prompt or image info)
|
|
112
|
+
* and used as the default filename if downloaded.
|
|
113
|
+
* The name **must be Base64 encoded** if it contains special characters (like `;`, `=`, or non-ASCII characters)
|
|
114
|
+
* to ensure correct parsing of the escape sequence by iTerm2.
|
|
115
|
+
* The `ITerm2File` and `ITerm2MultipartFileStart` classes generally expect the name to be pre-encoded if necessary.
|
|
116
|
+
* @example `"bXlmaWxlLnR4dA=="` (Base64 for "myfile.txt")
|
|
117
|
+
*/
|
|
118
|
+
name?: string;
|
|
119
|
+
/**
|
|
120
|
+
* The size of the file in bytes. This is used by iTerm2 for progress indication during downloads
|
|
121
|
+
* or to inform inline display mechanisms.
|
|
122
|
+
* JavaScript `number` type is generally sufficient for typical file sizes (up to `Number.MAX_SAFE_INTEGER`).
|
|
123
|
+
*/
|
|
124
|
+
size?: number;
|
|
125
|
+
/**
|
|
126
|
+
* The display width of the image or file placeholder.
|
|
127
|
+
* Can be:
|
|
128
|
+
* - A number (interpreted as character cells, e.g., `20`).
|
|
129
|
+
* - A string with units: `"Npx"` (N pixels), `"N%"` (N percent of session width).
|
|
130
|
+
* - The string {@link IT2_AUTO} (`"auto"`) for automatic sizing.
|
|
131
|
+
* Use helper functions like {@link it2Cells}, {@link it2Pixels}, {@link it2Percent} for formatting if needed.
|
|
132
|
+
* @example `20`, `"200px"`, `"75%"`, `IT2_AUTO`
|
|
133
|
+
*/
|
|
134
|
+
width?: LiteralUnion<typeof IT2_AUTO, number | string>;
|
|
135
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { IITerm2Payload, ITerm2FileProperties } from "./iterm2-properties.d.cts";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the payload for a complete iTerm2 file transfer or an inline image display command.
|
|
4
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `File=`.
|
|
5
|
+
* The generated payload can be either:
|
|
6
|
+
* - `File=[PROPERTIES]:[BASE64_CONTENT]` (for inline content)
|
|
7
|
+
* - `File=[PROPERTIES]` (if content is not provided directly, e.g., for a download announcement)
|
|
8
|
+
*
|
|
9
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
10
|
+
* @see {@link ITerm2FileProps} for property details.
|
|
11
|
+
* @see {@link iTerm2} for the function that wraps this payload into a full escape sequence.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ITerm2File implements IITerm2Payload {
|
|
14
|
+
private readonly fileProps;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs an `ITerm2File` payload object.
|
|
17
|
+
* @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProps}.
|
|
18
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
19
|
+
* contain special characters (like `;`, `=`, or non-ASCII characters).
|
|
20
|
+
* If `fileData` is provided, `props.content` will be overridden, and `props.size` will be
|
|
21
|
+
* set from `fileData.byteLength` if not already present in `props`.
|
|
22
|
+
* @param fileData (Optional) A `Uint8Array` containing the raw file data. If provided, this data will be
|
|
23
|
+
* Base64 encoded and used as the `content` of the file transfer. The `size` property
|
|
24
|
+
* will also be automatically set from `fileData.byteLength` if not specified in `props`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(properties: ITerm2FileProperties, fileData?: Uint8Array);
|
|
27
|
+
/**
|
|
28
|
+
* Converts the file properties and its content (if any) into the string payload
|
|
29
|
+
* suitable for the iTerm2 `File=` command.
|
|
30
|
+
* @returns The string payload (e.g., `"File=name=...;size=...:BASE64_CONTENT"` or `"File=name=...;size=..."`).
|
|
31
|
+
*/
|
|
32
|
+
toString(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents the payload for ending an iTerm2 multipart file transfer.
|
|
36
|
+
* This class is used to construct the part of the OSC 1337 sequence that is simply `FileEnd`.
|
|
37
|
+
*
|
|
38
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
39
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
40
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
41
|
+
*/
|
|
42
|
+
export declare class ITerm2FileEnd implements IITerm2Payload {
|
|
43
|
+
/**
|
|
44
|
+
* Generates the string payload for the iTerm2 `FileEnd` command.
|
|
45
|
+
* @returns The string `"FileEnd"`.
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents the payload for a part (chunk) of an iTerm2 multipart file transfer.
|
|
51
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `FilePart=`.
|
|
52
|
+
* The provided chunk must already be Base64 encoded.
|
|
53
|
+
*
|
|
54
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
55
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
56
|
+
* @see {@link ITerm2FileEnd} to finalize the transfer.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ITerm2FilePart implements IITerm2Payload {
|
|
59
|
+
private readonly base64Chunk;
|
|
60
|
+
/**
|
|
61
|
+
* Constructs an `ITerm2FilePart` payload object.
|
|
62
|
+
* @param base64Chunk A string containing a Base64 encoded chunk of the file data.
|
|
63
|
+
* The caller is responsible for chunking the file and Base64 encoding each chunk.
|
|
64
|
+
*/
|
|
65
|
+
constructor(base64Chunk: string);
|
|
66
|
+
/**
|
|
67
|
+
* Converts the Base64 encoded chunk into the string payload suitable for the iTerm2 `FilePart=` command.
|
|
68
|
+
* @returns The string payload (e.g., `"FilePart=U09NRURBVEE="`).
|
|
69
|
+
*/
|
|
70
|
+
toString(): string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Represents the payload for starting an iTerm2 multipart file transfer.
|
|
74
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `MultipartFile=`.
|
|
75
|
+
* This command initiates a transfer; the actual file data is sent in subsequent `FilePart` commands.
|
|
76
|
+
*
|
|
77
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
78
|
+
* @see {@link ITerm2FileProps} for property details (omitting `content`).
|
|
79
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
80
|
+
* @see {@link ITerm2FileEnd} for finalizing the transfer.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ITerm2MultipartFileStart implements IITerm2Payload {
|
|
83
|
+
private readonly properties;
|
|
84
|
+
/**
|
|
85
|
+
* Constructs an `ITerm2MultipartFileStart` payload object.
|
|
86
|
+
* @param properties Properties for the multipart file (e.g., `name`, `size`). Content is not part of this command.
|
|
87
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
88
|
+
* contain special characters.
|
|
89
|
+
*/
|
|
90
|
+
constructor(properties: Omit<ITerm2FileProperties, "content">);
|
|
91
|
+
/**
|
|
92
|
+
* Converts the file properties into the string payload suitable for the iTerm2 `MultipartFile=` command.
|
|
93
|
+
* @returns The string payload (e.g., `"MultipartFile=name=...;size=..."`).
|
|
94
|
+
*/
|
|
95
|
+
toString(): string;
|
|
96
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { IITerm2Payload, ITerm2FileProperties } from "./iterm2-properties.d.mts";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the payload for a complete iTerm2 file transfer or an inline image display command.
|
|
4
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `File=`.
|
|
5
|
+
* The generated payload can be either:
|
|
6
|
+
* - `File=[PROPERTIES]:[BASE64_CONTENT]` (for inline content)
|
|
7
|
+
* - `File=[PROPERTIES]` (if content is not provided directly, e.g., for a download announcement)
|
|
8
|
+
*
|
|
9
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
10
|
+
* @see {@link ITerm2FileProps} for property details.
|
|
11
|
+
* @see {@link iTerm2} for the function that wraps this payload into a full escape sequence.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ITerm2File implements IITerm2Payload {
|
|
14
|
+
private readonly fileProps;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs an `ITerm2File` payload object.
|
|
17
|
+
* @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProps}.
|
|
18
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
19
|
+
* contain special characters (like `;`, `=`, or non-ASCII characters).
|
|
20
|
+
* If `fileData` is provided, `props.content` will be overridden, and `props.size` will be
|
|
21
|
+
* set from `fileData.byteLength` if not already present in `props`.
|
|
22
|
+
* @param fileData (Optional) A `Uint8Array` containing the raw file data. If provided, this data will be
|
|
23
|
+
* Base64 encoded and used as the `content` of the file transfer. The `size` property
|
|
24
|
+
* will also be automatically set from `fileData.byteLength` if not specified in `props`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(properties: ITerm2FileProperties, fileData?: Uint8Array);
|
|
27
|
+
/**
|
|
28
|
+
* Converts the file properties and its content (if any) into the string payload
|
|
29
|
+
* suitable for the iTerm2 `File=` command.
|
|
30
|
+
* @returns The string payload (e.g., `"File=name=...;size=...:BASE64_CONTENT"` or `"File=name=...;size=..."`).
|
|
31
|
+
*/
|
|
32
|
+
toString(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents the payload for ending an iTerm2 multipart file transfer.
|
|
36
|
+
* This class is used to construct the part of the OSC 1337 sequence that is simply `FileEnd`.
|
|
37
|
+
*
|
|
38
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
39
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
40
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
41
|
+
*/
|
|
42
|
+
export declare class ITerm2FileEnd implements IITerm2Payload {
|
|
43
|
+
/**
|
|
44
|
+
* Generates the string payload for the iTerm2 `FileEnd` command.
|
|
45
|
+
* @returns The string `"FileEnd"`.
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents the payload for a part (chunk) of an iTerm2 multipart file transfer.
|
|
51
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `FilePart=`.
|
|
52
|
+
* The provided chunk must already be Base64 encoded.
|
|
53
|
+
*
|
|
54
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
55
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
56
|
+
* @see {@link ITerm2FileEnd} to finalize the transfer.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ITerm2FilePart implements IITerm2Payload {
|
|
59
|
+
private readonly base64Chunk;
|
|
60
|
+
/**
|
|
61
|
+
* Constructs an `ITerm2FilePart` payload object.
|
|
62
|
+
* @param base64Chunk A string containing a Base64 encoded chunk of the file data.
|
|
63
|
+
* The caller is responsible for chunking the file and Base64 encoding each chunk.
|
|
64
|
+
*/
|
|
65
|
+
constructor(base64Chunk: string);
|
|
66
|
+
/**
|
|
67
|
+
* Converts the Base64 encoded chunk into the string payload suitable for the iTerm2 `FilePart=` command.
|
|
68
|
+
* @returns The string payload (e.g., `"FilePart=U09NRURBVEE="`).
|
|
69
|
+
*/
|
|
70
|
+
toString(): string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Represents the payload for starting an iTerm2 multipart file transfer.
|
|
74
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `MultipartFile=`.
|
|
75
|
+
* This command initiates a transfer; the actual file data is sent in subsequent `FilePart` commands.
|
|
76
|
+
*
|
|
77
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
78
|
+
* @see {@link ITerm2FileProps} for property details (omitting `content`).
|
|
79
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
80
|
+
* @see {@link ITerm2FileEnd} for finalizing the transfer.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ITerm2MultipartFileStart implements IITerm2Payload {
|
|
83
|
+
private readonly properties;
|
|
84
|
+
/**
|
|
85
|
+
* Constructs an `ITerm2MultipartFileStart` payload object.
|
|
86
|
+
* @param properties Properties for the multipart file (e.g., `name`, `size`). Content is not part of this command.
|
|
87
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
88
|
+
* contain special characters.
|
|
89
|
+
*/
|
|
90
|
+
constructor(properties: Omit<ITerm2FileProperties, "content">);
|
|
91
|
+
/**
|
|
92
|
+
* Converts the file properties into the string payload suitable for the iTerm2 `MultipartFile=` command.
|
|
93
|
+
* @returns The string payload (e.g., `"MultipartFile=name=...;size=..."`).
|
|
94
|
+
*/
|
|
95
|
+
toString(): string;
|
|
96
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { IITerm2Payload, ITerm2FileProperties } from "./iterm2-properties.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Represents the payload for a complete iTerm2 file transfer or an inline image display command.
|
|
4
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `File=`.
|
|
5
|
+
* The generated payload can be either:
|
|
6
|
+
* - `File=[PROPERTIES]:[BASE64_CONTENT]` (for inline content)
|
|
7
|
+
* - `File=[PROPERTIES]` (if content is not provided directly, e.g., for a download announcement)
|
|
8
|
+
*
|
|
9
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
10
|
+
* @see {@link ITerm2FileProps} for property details.
|
|
11
|
+
* @see {@link iTerm2} for the function that wraps this payload into a full escape sequence.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ITerm2File implements IITerm2Payload {
|
|
14
|
+
private readonly fileProps;
|
|
15
|
+
/**
|
|
16
|
+
* Constructs an `ITerm2File` payload object.
|
|
17
|
+
* @param properties An object containing properties for the file/image, as defined by {@link ITerm2FileProps}.
|
|
18
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
19
|
+
* contain special characters (like `;`, `=`, or non-ASCII characters).
|
|
20
|
+
* If `fileData` is provided, `props.content` will be overridden, and `props.size` will be
|
|
21
|
+
* set from `fileData.byteLength` if not already present in `props`.
|
|
22
|
+
* @param fileData (Optional) A `Uint8Array` containing the raw file data. If provided, this data will be
|
|
23
|
+
* Base64 encoded and used as the `content` of the file transfer. The `size` property
|
|
24
|
+
* will also be automatically set from `fileData.byteLength` if not specified in `props`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(properties: ITerm2FileProperties, fileData?: Uint8Array);
|
|
27
|
+
/**
|
|
28
|
+
* Converts the file properties and its content (if any) into the string payload
|
|
29
|
+
* suitable for the iTerm2 `File=` command.
|
|
30
|
+
* @returns The string payload (e.g., `"File=name=...;size=...:BASE64_CONTENT"` or `"File=name=...;size=..."`).
|
|
31
|
+
*/
|
|
32
|
+
toString(): string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents the payload for ending an iTerm2 multipart file transfer.
|
|
36
|
+
* This class is used to construct the part of the OSC 1337 sequence that is simply `FileEnd`.
|
|
37
|
+
*
|
|
38
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
39
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
40
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
41
|
+
*/
|
|
42
|
+
export declare class ITerm2FileEnd implements IITerm2Payload {
|
|
43
|
+
/**
|
|
44
|
+
* Generates the string payload for the iTerm2 `FileEnd` command.
|
|
45
|
+
* @returns The string `"FileEnd"`.
|
|
46
|
+
*/
|
|
47
|
+
toString(): string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents the payload for a part (chunk) of an iTerm2 multipart file transfer.
|
|
51
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `FilePart=`.
|
|
52
|
+
* The provided chunk must already be Base64 encoded.
|
|
53
|
+
*
|
|
54
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
55
|
+
* @see {@link ITerm2MultipartFileStart} to initiate the transfer.
|
|
56
|
+
* @see {@link ITerm2FileEnd} to finalize the transfer.
|
|
57
|
+
*/
|
|
58
|
+
export declare class ITerm2FilePart implements IITerm2Payload {
|
|
59
|
+
private readonly base64Chunk;
|
|
60
|
+
/**
|
|
61
|
+
* Constructs an `ITerm2FilePart` payload object.
|
|
62
|
+
* @param base64Chunk A string containing a Base64 encoded chunk of the file data.
|
|
63
|
+
* The caller is responsible for chunking the file and Base64 encoding each chunk.
|
|
64
|
+
*/
|
|
65
|
+
constructor(base64Chunk: string);
|
|
66
|
+
/**
|
|
67
|
+
* Converts the Base64 encoded chunk into the string payload suitable for the iTerm2 `FilePart=` command.
|
|
68
|
+
* @returns The string payload (e.g., `"FilePart=U09NRURBVEE="`).
|
|
69
|
+
*/
|
|
70
|
+
toString(): string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Represents the payload for starting an iTerm2 multipart file transfer.
|
|
74
|
+
* This class is used to construct the part of the OSC 1337 sequence that follows `MultipartFile=`.
|
|
75
|
+
* This command initiates a transfer; the actual file data is sent in subsequent `FilePart` commands.
|
|
76
|
+
*
|
|
77
|
+
* Implements {@link IITerm2Payload} for use with the generic `iTerm2` function.
|
|
78
|
+
* @see {@link ITerm2FileProps} for property details (omitting `content`).
|
|
79
|
+
* @see {@link ITerm2FilePart} for sending file chunks.
|
|
80
|
+
* @see {@link ITerm2FileEnd} for finalizing the transfer.
|
|
81
|
+
*/
|
|
82
|
+
export declare class ITerm2MultipartFileStart implements IITerm2Payload {
|
|
83
|
+
private readonly properties;
|
|
84
|
+
/**
|
|
85
|
+
* Constructs an `ITerm2MultipartFileStart` payload object.
|
|
86
|
+
* @param properties Properties for the multipart file (e.g., `name`, `size`). Content is not part of this command.
|
|
87
|
+
* The `name` property within `props` should be pre-Base64 encoded by the caller if it might
|
|
88
|
+
* contain special characters.
|
|
89
|
+
*/
|
|
90
|
+
constructor(properties: Omit<ITerm2FileProperties, "content">);
|
|
91
|
+
/**
|
|
92
|
+
* Converts the file properties into the string payload suitable for the iTerm2 `MultipartFile=` command.
|
|
93
|
+
* @returns The string payload (e.g., `"MultipartFile=name=...;size=..."`).
|
|
94
|
+
*/
|
|
95
|
+
toString(): string;
|
|
96
|
+
}
|
package/dist/iterm2.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const constants = require('./packem_shared/constants-BK26O-46.cjs');
|
|
6
|
+
const IT2_AUTO = require('./packem_shared/IT2_AUTO-5vTJQMm6.cjs');
|
|
7
|
+
const ITerm2File = require('./packem_shared/ITerm2File-BGPqNSjB.cjs');
|
|
8
|
+
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
+
const iTerm2 = /* @__PURE__ */ __name((payload) => {
|
|
12
|
+
if (!payload || typeof payload.toString !== "function" || payload.toString === Object.prototype.toString) {
|
|
13
|
+
throw new Error("Invalid payload: must implement IITerm2Payload with a custom toString method");
|
|
14
|
+
}
|
|
15
|
+
return `${constants.OSC}1337;${payload.toString()}${constants.BEL}`;
|
|
16
|
+
}, "iTerm2");
|
|
17
|
+
|
|
18
|
+
exports.IT2_AUTO = IT2_AUTO.IT2_AUTO;
|
|
19
|
+
exports.it2Cells = IT2_AUTO.it2Cells;
|
|
20
|
+
exports.it2Percent = IT2_AUTO.it2Percent;
|
|
21
|
+
exports.it2Pixels = IT2_AUTO.it2Pixels;
|
|
22
|
+
exports.ITerm2File = ITerm2File.ITerm2File;
|
|
23
|
+
exports.ITerm2FileEnd = ITerm2File.ITerm2FileEnd;
|
|
24
|
+
exports.ITerm2FilePart = ITerm2File.ITerm2FilePart;
|
|
25
|
+
exports.ITerm2MultipartFileStart = ITerm2File.ITerm2MultipartFileStart;
|
|
26
|
+
exports.iTerm2 = iTerm2;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { IITerm2Payload } from './iterm2/iterm2-properties.d.cts';
|
|
2
|
+
export type { IITerm2Payload, ITerm2FileProperties } from './iterm2/iterm2-properties.d.cts';
|
|
3
|
+
export { IT2_AUTO, it2Cells, it2Percent, it2Pixels, } from './iterm2/iterm2-properties.d.cts';
|
|
4
|
+
export { ITerm2File, ITerm2FileEnd, ITerm2FilePart, ITerm2MultipartFileStart, } from './iterm2/iterm2-sequences.d.cts';
|
|
5
|
+
/**
|
|
6
|
+
* Generates a complete iTerm2 proprietary escape sequence (OSC 1337).
|
|
7
|
+
*
|
|
8
|
+
* This function serves as a general-purpose constructor for iTerm2 escape codes.
|
|
9
|
+
* It takes a payload object that conforms to the {@link IITerm2Payload} interface.
|
|
10
|
+
* The `toString()` method of this payload object is responsible for generating the
|
|
11
|
+
* specific command and arguments part of the sequence (e.g., `File=...`, `ShellIntegrationVersion=...`).
|
|
12
|
+
*
|
|
13
|
+
* The overall structure of the generated sequence is: `OSC 1337 ; <PAYLOAD_STRING> BEL`
|
|
14
|
+
* (`OSC` is `\x1b]`, `BEL` is `\x07`).
|
|
15
|
+
* @param payload An object that implements the {@link IITerm2Payload} interface.
|
|
16
|
+
* This object must have a `toString()` method that returns the string representation
|
|
17
|
+
* of the iTerm2 command-specific payload.
|
|
18
|
+
* Examples include instances of `ITerm2File`, `ITerm2MultipartFileStart`, etc.
|
|
19
|
+
* @returns The fully formed ANSI escape sequence for the iTerm2 command.
|
|
20
|
+
* Returns an empty string if the provided `payload` is invalid (e.g., null, undefined,
|
|
21
|
+
* lacks a proper `toString` method, or its `toString` method is the generic `Object.prototype.toString`).
|
|
22
|
+
* @see {@link https://iterm2.com/documentation-escape-codes.html iTerm2 Escape Codes Documentation}
|
|
23
|
+
* for a comprehensive list of supported commands and their payloads.
|
|
24
|
+
* @see {@link IITerm2Payload} for the interface requirement.
|
|
25
|
+
* @see Classes like {@link ITerm2File}, {@link ITerm2MultipartFileStart}, {@link ITerm2FilePart}, {@link ITerm2FileEnd}
|
|
26
|
+
* for concrete examples of payload objects.
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { iTerm2, ITerm2File, ITerm2FileProps } from '@visulima/ansi/iterm2'; // ITerm2FileProps can be used for options
|
|
30
|
+
* import { Buffer } from 'node:buffer';
|
|
31
|
+
*
|
|
32
|
+
* // Example 1: Sending a file inline (like an image)
|
|
33
|
+
* const imageName = "my_image.png";
|
|
34
|
+
* const imageData = Buffer.from("dummyimagecontent"); // Replace with actual Uint8Array image data
|
|
35
|
+
* const imageFileProps: ITerm2FileProps = { // Use ITerm2FileProps for broader options
|
|
36
|
+
* name: Buffer.from(imageName).toString("base64"), // Name should be base64 encoded
|
|
37
|
+
* inline: true,
|
|
38
|
+
* width: "50%",
|
|
39
|
+
* height: "auto",
|
|
40
|
+
* ignoreAspectRatio: false, // Equivalent to preserveAspectRatio: true
|
|
41
|
+
* };
|
|
42
|
+
* const filePayload = new ITerm2File(imageFileProps, imageData);
|
|
43
|
+
* const imageSequence = iTerm2(filePayload);
|
|
44
|
+
* console.log(imageSequence);
|
|
45
|
+
* // Expected output (simplified, actual base64 will be longer):
|
|
46
|
+
* // OSC1337;File=name=bXlfaW1hZ2UucG5n;inline=1;width=50%;height=auto:ZHVtbXlpbWFnZWNvbnRlbnQ=BEL
|
|
47
|
+
* // Note: if ignoreAspectRatio was true, preserveAspectRatio=0 would be in the sequence.
|
|
48
|
+
*
|
|
49
|
+
* // Example 2: A hypothetical simple command (e.g., shell integration handshake)
|
|
50
|
+
* const shellIntegrationPayload: IITerm2Payload = {
|
|
51
|
+
* toString: () => "ShellIntegrationVersion=15;Shell=zsh"
|
|
52
|
+
* };
|
|
53
|
+
* const shellSequence = iTerm2(shellIntegrationPayload);
|
|
54
|
+
* console.log(shellSequence);
|
|
55
|
+
* // Output: OSC1337;ShellIntegrationVersion=15;Shell=zshBEL
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare const iTerm2: (payload: IITerm2Payload) => string;
|