@f5-sales-demo/pi-tui 20.20.2 → 20.20.3
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/package.json +3 -3
- package/src/terminal-capabilities.ts +30 -16
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-tui",
|
|
4
|
-
"version": "20.20.
|
|
4
|
+
"version": "20.20.3",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@f5-sales-demo/pi-natives": "20.20.
|
|
41
|
-
"@f5-sales-demo/pi-utils": "20.20.
|
|
40
|
+
"@f5-sales-demo/pi-natives": "20.20.3",
|
|
41
|
+
"@f5-sales-demo/pi-utils": "20.20.3",
|
|
42
42
|
"marked": "^18.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
@@ -59,8 +59,8 @@ export function isNotificationSuppressed(): boolean {
|
|
|
59
59
|
return value === "off" || value === "0" || value === "false";
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function getForcedImageProtocol(): ImageProtocol | null | undefined {
|
|
63
|
-
const raw =
|
|
62
|
+
function getForcedImageProtocol(env: NodeJS.ProcessEnv): ImageProtocol | null | undefined {
|
|
63
|
+
const raw = env.PI_FORCE_IMAGE_PROTOCOL?.trim().toLowerCase();
|
|
64
64
|
if (!raw) return undefined;
|
|
65
65
|
if (raw === "kitty") return ImageProtocol.Kitty;
|
|
66
66
|
if (raw === "iterm2" || raw === "iterm") return ImageProtocol.Iterm2;
|
|
@@ -97,12 +97,21 @@ export function isWindowsTerminalPreviewSixelSupported(
|
|
|
97
97
|
if (!version) return false;
|
|
98
98
|
return version.major > 1 || (version.major === 1 && version.minor >= 22);
|
|
99
99
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
100
|
+
function hasHerdrKittyGraphics(env: NodeJS.ProcessEnv): boolean {
|
|
101
|
+
return env.HERDR_ENV === "1" && env.HERDR_KITTY_GRAPHICS === "1";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function getFallbackImageProtocol(
|
|
105
|
+
terminalId: TerminalId,
|
|
106
|
+
env: NodeJS.ProcessEnv,
|
|
107
|
+
stdoutIsTTY: boolean,
|
|
108
|
+
): ImageProtocol | null {
|
|
109
|
+
if (!stdoutIsTTY) return null;
|
|
110
|
+
if (hasHerdrKittyGraphics(env)) return ImageProtocol.Kitty;
|
|
102
111
|
if (terminalId === "alacritty") return null;
|
|
103
112
|
// VS Code 1.80+ supports iTerm2 inline image protocol
|
|
104
113
|
if (terminalId === "vscode") return ImageProtocol.Iterm2;
|
|
105
|
-
const term =
|
|
114
|
+
const term = env.TERM?.toLowerCase() ?? "";
|
|
106
115
|
if (term.includes("screen") || term.includes("tmux") || term.includes("ghostty")) {
|
|
107
116
|
return ImageProtocol.Kitty;
|
|
108
117
|
}
|
|
@@ -121,11 +130,11 @@ const KNOWN_TERMINALS = Object.freeze({
|
|
|
121
130
|
alacritty: new TerminalInfo("alacritty", null, true, true, NotifyProtocol.Bell),
|
|
122
131
|
});
|
|
123
132
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
133
|
+
function caseEq(a: string, b: string): boolean {
|
|
134
|
+
return a.toLowerCase() === b.toLowerCase(); // For compiler to pattern match
|
|
135
|
+
}
|
|
128
136
|
|
|
137
|
+
export function resolveTerminalId(env: NodeJS.ProcessEnv): TerminalId {
|
|
129
138
|
const {
|
|
130
139
|
KITTY_WINDOW_ID,
|
|
131
140
|
GHOSTTY_RESOURCES_DIR,
|
|
@@ -136,7 +145,7 @@ export const TERMINAL_ID: TerminalId = (() => {
|
|
|
136
145
|
TERM_PROGRAM,
|
|
137
146
|
TERM,
|
|
138
147
|
COLORTERM,
|
|
139
|
-
} =
|
|
148
|
+
} = env;
|
|
140
149
|
|
|
141
150
|
if (KITTY_WINDOW_ID) return "kitty";
|
|
142
151
|
if (GHOSTTY_RESOURCES_DIR) return "ghostty";
|
|
@@ -160,11 +169,12 @@ export const TERMINAL_ID: TerminalId = (() => {
|
|
|
160
169
|
if (caseEq(COLORTERM, "truecolor") || caseEq(COLORTERM, "24bit")) return "trueColor";
|
|
161
170
|
}
|
|
162
171
|
return "base";
|
|
163
|
-
}
|
|
172
|
+
}
|
|
164
173
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const
|
|
174
|
+
/** Resolve terminal capabilities from an explicit environment and stdout TTY state. */
|
|
175
|
+
export function resolveTerminalInfo(env: NodeJS.ProcessEnv, stdoutIsTTY: boolean): TerminalInfo {
|
|
176
|
+
const terminal = getTerminalInfo(resolveTerminalId(env));
|
|
177
|
+
const forcedImageProtocol = getForcedImageProtocol(env);
|
|
168
178
|
if (forcedImageProtocol !== undefined) {
|
|
169
179
|
return new TerminalInfo(
|
|
170
180
|
terminal.id,
|
|
@@ -175,7 +185,7 @@ export const TERMINAL = (() => {
|
|
|
175
185
|
);
|
|
176
186
|
}
|
|
177
187
|
if (!terminal.imageProtocol) {
|
|
178
|
-
const fallbackImageProtocol = getFallbackImageProtocol(terminal.id);
|
|
188
|
+
const fallbackImageProtocol = getFallbackImageProtocol(terminal.id, env, stdoutIsTTY);
|
|
179
189
|
if (fallbackImageProtocol) {
|
|
180
190
|
return new TerminalInfo(
|
|
181
191
|
terminal.id,
|
|
@@ -187,7 +197,11 @@ export const TERMINAL = (() => {
|
|
|
187
197
|
}
|
|
188
198
|
}
|
|
189
199
|
return terminal;
|
|
190
|
-
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export const TERMINAL_ID: TerminalId = resolveTerminalId(Bun.env);
|
|
203
|
+
|
|
204
|
+
export const TERMINAL = resolveTerminalInfo(Bun.env, process.stdout.isTTY ?? false);
|
|
191
205
|
|
|
192
206
|
type MutableTerminalInfo = {
|
|
193
207
|
imageProtocol: ImageProtocol | null;
|