comfy-ts 2.5.0 → 2.7.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/README.md +15 -2
- package/dist/{DefinedWorkflow-CnzmQrBh.js → DefinedWorkflow-BJgt5t0x.js} +14 -3
- package/dist/DefinedWorkflow-BJgt5t0x.js.map +1 -0
- package/dist/{DraftsSt-C1MbWnEp.js → DraftsSt-dizp3VcC.js} +2 -2
- package/dist/{DraftsSt-C1MbWnEp.js.map → DraftsSt-dizp3VcC.js.map} +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +7 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -18
- package/dist/index.d.ts +24 -18
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/{run-serve-D47Zas-a.js → run-serve-D1Tsuru9.js} +494 -20
- package/dist/run-serve-D1Tsuru9.js.map +1 -0
- package/dist/{run-tui-t2TRBN0H.js → run-tui-JxlEbb_f.js} +511 -331
- package/dist/run-tui-JxlEbb_f.js.map +1 -0
- package/dist/serve-web.js +273 -0
- package/dist/{state-DY3Mp9Cl.js → state-CaHeDL-0.js} +7 -13
- package/dist/state-CaHeDL-0.js.map +1 -0
- package/dist/web.d.ts +24 -18
- package/dist/web.js +7 -2
- package/dist/web.js.map +1 -1
- package/examples/web/tsconfig.json +4 -1
- package/package.json +7 -5
- package/src/cli/comfy-ts-cli.ts +1 -1
- package/src/cli/serve/ServeApp.ts +383 -14
- package/src/cli/serve/describeVar.ts +6 -1
- package/src/cli/serve/promptEnhancers.ts +69 -0
- package/src/cli/serve/run-serve.ts +41 -7
- package/src/cli/serve/safeName.ts +12 -0
- package/src/cli/serve/web/api.ts +128 -0
- package/src/cli/serve/web/clipboard.ts +25 -0
- package/src/cli/serve/web/components/App.tsx +53 -0
- package/src/cli/serve/web/components/Gallery.tsx +186 -0
- package/src/cli/serve/web/components/PromptEnhancer.tsx +254 -0
- package/src/cli/serve/web/components/Sidebar.tsx +42 -0
- package/src/cli/serve/web/components/VarsForm.tsx +184 -0
- package/src/cli/serve/web/components/controls/BasicControls.tsx +95 -0
- package/src/cli/serve/web/components/controls/ImageControl.tsx +71 -0
- package/src/cli/serve/web/components/controls/LorasControl.tsx +340 -0
- package/src/cli/serve/web/components/controls/SeedControl.tsx +43 -0
- package/src/cli/serve/web/components/controls/SizeControl.tsx +49 -0
- package/src/cli/serve/web/llm.ts +254 -0
- package/src/cli/serve/web/main.tsx +18 -0
- package/src/cli/serve/web/state/EnhancerSt.ts +481 -0
- package/src/cli/serve/web/state/FormSt.ts +180 -0
- package/src/cli/serve/web/state/RunSt.ts +136 -0
- package/src/cli/serve/web/state/WebSt.ts +235 -0
- package/src/cli/serve/web/state/payload.ts +110 -0
- package/src/cli/serve/web/styles.ts +261 -0
- package/src/cli/serve/web/tsconfig.json +15 -0
- package/src/cli/serve/webBundle.ts +66 -0
- package/src/cli/tui/imageEscapes.ts +105 -0
- package/src/cli/tui/imagePicker/ImagePickerSt.ts +21 -8
- package/src/cli/tui/protocolImage.ts +39 -0
- package/src/cli/tui/protocolImagePainter.ts +56 -23
- package/src/cli/tui/run-tui.tsx +3 -2
- package/src/cli/tui/state/LorasSt.ts +22 -9
- package/src/cli/tui/state/PreviewSt.ts +31 -13
- package/src/cli/tui/state/SettingsSt.ts +1 -1
- package/src/state.ts +6 -0
- package/src/vars/ComfyVars.ts +4 -1
- package/dist/DefinedWorkflow-CnzmQrBh.js.map +0 -1
- package/dist/run-serve-D47Zas-a.js.map +0 -1
- package/dist/run-tui-t2TRBN0H.js.map +0 -1
- package/dist/state-DY3Mp9Cl.js.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { a as importSharp, i as stripAnsi, n as settingsPathFor } from "./state-
|
|
3
|
-
import { a as assignFamilyColors, c as findDefinedWorkflow, i as listDraftsForFile, l as mergeWorkflowSources, n as draftKeyForFile, o as buildFileRows, s as familyOf, t as DraftsSt, u as scanCflowFiles } from "./DraftsSt-
|
|
1
|
+
import { C as loraPreviewMapFrom, S as loraKey, _ as fetchLoraList, a as getLoraKeyword, c as setLoraKeyword, d as getLoraPreviewUrl, h as refreshLoraInfoCacheIfChanged, i as clearLoraKeywordOverride, k as logError, n as LorasVar, o as isLoraKeywordFromMirror, p as loraMatchesFilter, r as PromptVar, s as loraKeywordFromMirror, u as getLoraDisplayName, v as fetchLoraPreviewBytes, w as extractErrorMessage, x as loraBasename } from "./DefinedWorkflow-BJgt5t0x.js";
|
|
2
|
+
import { a as importSharp, i as stripAnsi, n as settingsPathFor } from "./state-CaHeDL-0.js";
|
|
3
|
+
import { a as assignFamilyColors, c as findDefinedWorkflow, i as listDraftsForFile, l as mergeWorkflowSources, n as draftKeyForFile, o as buildFileRows, s as familyOf, t as DraftsSt, u as scanCflowFiles } from "./DraftsSt-dizp3VcC.js";
|
|
4
4
|
import { spawn } from "node:child_process";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { basename, dirname, join, resolve } from "pathe";
|
|
8
8
|
import { imageMeta } from "image-meta";
|
|
9
9
|
import { makeAutoObservable, observableRef, reaction, runInAction } from "mobx";
|
|
10
|
+
import { homedir, tmpdir } from "node:os";
|
|
10
11
|
import { Box, Text, measureElement, render, useApp, useInput, useStdin } from "ink";
|
|
11
12
|
import sharp from "sharp";
|
|
12
13
|
import { observer } from "mobx-react-lite";
|
|
13
14
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { homedir, tmpdir } from "node:os";
|
|
15
15
|
import { useEffect, useRef } from "react";
|
|
16
16
|
//#region src/cli/tui-env.ts
|
|
17
17
|
const COMFY_TS_TUI_ENV = "COMFY_TS_TUI";
|
|
@@ -48,335 +48,205 @@ function bundledExamplesDir(moduleUrl = import.meta.url) {
|
|
|
48
48
|
throw new Error(`[comfy-ts] no package.json found walking up from ${fileURLToPath(moduleUrl)}`);
|
|
49
49
|
}
|
|
50
50
|
//#endregion
|
|
51
|
-
//#region src/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
data[i] ?? 0,
|
|
67
|
-
data[i + 1] ?? 0,
|
|
68
|
-
data[i + 2] ?? 0
|
|
69
|
-
];
|
|
51
|
+
//#region src/cli/tui/imageEscapes.ts
|
|
52
|
+
const ESC = "\x1B";
|
|
53
|
+
/** APC terminator: ESC backslash */
|
|
54
|
+
const ST = "\x1B\\";
|
|
55
|
+
/** one OSC 1337 paint: cursor save → CUP → image sized in CELLS → cursor restore */
|
|
56
|
+
function itermImageEscape(bytes, row, col, w, h) {
|
|
57
|
+
const b64 = Buffer.from(bytes).toString("base64");
|
|
58
|
+
return `${ESC}7${ESC}[${row};${col}H${ESC}]1337;File=inline=1;size=${bytes.byteLength};width=${w};height=${h};preserveAspectRatio=1:${b64}\u0007${ESC}8`;
|
|
59
|
+
}
|
|
60
|
+
/** kitty stretches to the given cell box (no preserveAspectRatio key): fit the
|
|
61
|
+
* box to the image aspect first. Cells are ~1:2 (w:h), same as cornerBox. */
|
|
62
|
+
function fitCellBox(p) {
|
|
63
|
+
if (p.imgW <= 0 || p.imgH <= 0) return {
|
|
64
|
+
w: p.w,
|
|
65
|
+
h: p.h
|
|
70
66
|
};
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
row += `\x1b[48;2;${tr};${tg};${tb}m\x1b[38;2;${br};${bg};${bb}m▄`;
|
|
78
|
-
}
|
|
79
|
-
rows.push(row + "\x1B[0m");
|
|
67
|
+
const aspect = p.imgW / p.imgH;
|
|
68
|
+
let w = p.w;
|
|
69
|
+
let h = Math.max(1, Math.round(w / aspect / 2));
|
|
70
|
+
if (h > p.h) {
|
|
71
|
+
h = p.h;
|
|
72
|
+
w = Math.max(1, Math.min(p.w, Math.round(h * aspect * 2)));
|
|
80
73
|
}
|
|
81
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
w,
|
|
76
|
+
h
|
|
77
|
+
};
|
|
82
78
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
79
|
+
const dimsCache = /* @__PURE__ */ new WeakMap();
|
|
80
|
+
/** header-only parse, cached per bytes object (the painter runs on every flush) */
|
|
81
|
+
function imageDims(bytes) {
|
|
82
|
+
const hit = dimsCache.get(bytes);
|
|
83
|
+
if (hit != null) return hit;
|
|
84
|
+
let dims = {
|
|
85
|
+
w: 0,
|
|
86
|
+
h: 0
|
|
87
|
+
};
|
|
88
|
+
try {
|
|
89
|
+
const meta = imageMeta(bytes);
|
|
90
|
+
if (meta.width != null && meta.height != null) dims = {
|
|
91
|
+
w: meta.width,
|
|
92
|
+
h: meta.height
|
|
93
|
+
};
|
|
94
|
+
} catch {}
|
|
95
|
+
dimsCache.set(bytes, dims);
|
|
96
|
+
return dims;
|
|
90
97
|
}
|
|
91
|
-
/**
|
|
92
|
-
const
|
|
93
|
-
/**
|
|
94
|
-
|
|
98
|
+
/** spec cap for one APC payload; continuation chunks carry only the m key */
|
|
99
|
+
const KITTY_CHUNK = 4096;
|
|
100
|
+
/** transmit png data under a fixed image id WITHOUT displaying it (a=t),
|
|
101
|
+
* base64 chunked with m=1/0 continuation */
|
|
102
|
+
function kittyTransmitEscape(bytes, id) {
|
|
103
|
+
const b64 = Buffer.from(bytes).toString("base64");
|
|
104
|
+
let out = "";
|
|
105
|
+
for (let i = 0; i < b64.length; i += KITTY_CHUNK) {
|
|
106
|
+
const last = i + KITTY_CHUNK >= b64.length;
|
|
107
|
+
const ctrl = i === 0 ? `a=t,f=100,t=d,i=${id},q=2,m=${last ? 0 : 1}` : `m=${last ? 0 : 1}`;
|
|
108
|
+
out += `${ESC}_G${ctrl};${b64.slice(i, i + KITTY_CHUNK)}${ST}`;
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** display a transmitted id at the cursor: same i,p replaces the previous
|
|
113
|
+
* placement, so repaints never accumulate; C=1 keeps the cursor put; z pins
|
|
114
|
+
* stacking (same-z overlaps draw newest-on-top, recency is not a contract) */
|
|
115
|
+
function kittyPlaceEscape(id, row, col, w, h, z) {
|
|
116
|
+
const zKey = z == null ? "" : `,z=${z}`;
|
|
117
|
+
return `${ESC}7${ESC}[${row};${col}H${ESC}_Ga=p,i=${id},p=1,c=${w},r=${h},C=1,q=2${zKey}${ST}${ESC}8`;
|
|
118
|
+
}
|
|
119
|
+
/** delete this id's placements AND free its data (uppercase I) */
|
|
120
|
+
function kittyDeleteEscape(id) {
|
|
121
|
+
return `${ESC}_Ga=d,d=I,i=${id},q=2${ST}`;
|
|
122
|
+
}
|
|
123
|
+
/** free every image + placement — the quit path: ED does not clear kitty images */
|
|
124
|
+
const KITTY_DELETE_ALL = `${ESC}_Ga=d,d=A,q=2${ST}`;
|
|
95
125
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* last output). Sources: live latent while running, last output after,
|
|
100
|
-
* selected lora while the loras overlay is open.
|
|
126
|
+
* per-id transmit-once bookkeeping: data uploads when the bytes OBJECT changes
|
|
127
|
+
* (delete-before-retransmit sidesteps the spec's underspecified reuse of a live
|
|
128
|
+
* id), a cheap placement re-paints every flush, drop deletes exactly once.
|
|
101
129
|
*/
|
|
102
|
-
var
|
|
103
|
-
constructor(
|
|
104
|
-
this.
|
|
105
|
-
this.
|
|
106
|
-
this.latentAnsi = null;
|
|
107
|
-
this.outputBytes = null;
|
|
108
|
-
this.latentBytes = null;
|
|
109
|
-
this.latentDims = null;
|
|
110
|
-
this.latentSeenThisRun = false;
|
|
111
|
-
this.lastOutput = null;
|
|
112
|
-
this.overlay = null;
|
|
113
|
-
this.menuIx = 0;
|
|
114
|
-
this._busy = false;
|
|
115
|
-
makeAutoObservable(this, { st: false });
|
|
116
|
-
}
|
|
117
|
-
get show() {
|
|
118
|
-
return this.st.settings.previewPanel;
|
|
119
|
-
}
|
|
120
|
-
get renderer() {
|
|
121
|
-
return this.st.settings.previewRenderer;
|
|
122
|
-
}
|
|
123
|
-
get useNative() {
|
|
124
|
-
return this.renderer === "native";
|
|
125
|
-
}
|
|
126
|
-
get duringRun() {
|
|
127
|
-
return this.st.settings.previewDuringRun;
|
|
130
|
+
var KittyImageSlot = class {
|
|
131
|
+
constructor(id) {
|
|
132
|
+
this.id = id;
|
|
133
|
+
this.transmitted = null;
|
|
128
134
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
this.overlay = p;
|
|
137
|
-
}
|
|
138
|
-
clearOverlayImage() {
|
|
139
|
-
this.overlay = null;
|
|
135
|
+
show(bytes, row, col, w, h, z) {
|
|
136
|
+
let out = "";
|
|
137
|
+
if (this.transmitted !== bytes) {
|
|
138
|
+
out += kittyDeleteEscape(this.id) + kittyTransmitEscape(bytes, this.id);
|
|
139
|
+
this.transmitted = bytes;
|
|
140
|
+
}
|
|
141
|
+
return out + kittyPlaceEscape(this.id, row, col, w, h, z);
|
|
140
142
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return this.st.exec.running && this.duringRun !== "last-output" && (this.st.exec.progress?.percent ?? 0) >= 20 && !this.latentSeenThisRun;
|
|
143
|
+
drop() {
|
|
144
|
+
if (this.transmitted == null) return "";
|
|
145
|
+
this.transmitted = null;
|
|
146
|
+
return kittyDeleteEscape(this.id);
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
148
|
+
};
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/cli/tui/protocolImage.ts
|
|
151
|
+
function imageProtocol() {
|
|
152
|
+
if (process.env.COMFY_TS_NO_ITERM_IMAGES === "1") return null;
|
|
153
|
+
const term = process.env.TERM ?? "";
|
|
154
|
+
const program = process.env.TERM_PROGRAM ?? "";
|
|
155
|
+
if (term.includes("kitty") || term.includes("ghostty") || process.env.KITTY_WINDOW_ID != null || process.env.GHOSTTY_RESOURCES_DIR != null) return "kitty";
|
|
156
|
+
return program === "iTerm.app" || program === "WezTerm" || program === "vscode" || process.env.LC_TERMINAL === "iTerm2" ? "iterm" : null;
|
|
157
|
+
}
|
|
158
|
+
function protocolCapable() {
|
|
159
|
+
return imageProtocol() != null;
|
|
160
|
+
}
|
|
161
|
+
const PNG_MAGIC = [
|
|
162
|
+
137,
|
|
163
|
+
80,
|
|
164
|
+
78,
|
|
165
|
+
71,
|
|
166
|
+
13,
|
|
167
|
+
10,
|
|
168
|
+
26,
|
|
169
|
+
10
|
|
170
|
+
];
|
|
171
|
+
function isPng(bytes) {
|
|
172
|
+
return PNG_MAGIC.every((byte, ix) => bytes[ix] === byte);
|
|
173
|
+
}
|
|
174
|
+
/** kitty only draws png (f=100), never jpeg/webp; iterm takes any format.
|
|
175
|
+
* Pass every native-renderer byte source that is not sharp-produced png through here. */
|
|
176
|
+
async function protocolReadyBytes(bytes) {
|
|
177
|
+
if (imageProtocol() !== "kitty" || isPng(bytes)) return bytes;
|
|
178
|
+
return new Uint8Array(await sharp(bytes).png().toBuffer());
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/cli/tui/protocolImagePainter.ts
|
|
182
|
+
const SYNC_BEGIN = "\x1B[?2026h";
|
|
183
|
+
const SYNC_END = "\x1B[?2026l";
|
|
184
|
+
/** below this a write is a terminal query/reply, not a frame — no cells damaged */
|
|
185
|
+
const MIN_FRAME_BYTES = 64;
|
|
186
|
+
/** kitty image ids: fixed, transmit-once bookkeeping keys */
|
|
187
|
+
const MAIN_ID = 1;
|
|
188
|
+
const CORNER_ID = 2;
|
|
189
|
+
/** corner placement z: pins the small latent ABOVE the main image (same-z
|
|
190
|
+
* stacking is recency, and a fresh output recreates MAIN after the corner) */
|
|
191
|
+
const CORNER_Z = 1;
|
|
192
|
+
/**
|
|
193
|
+
* paints the REAL image (iTerm OSC 1337 / kitty APC _G) over the preview
|
|
194
|
+
* panel's cell rect. Protocol images cannot go THROUGH ink (layout shreds the
|
|
195
|
+
* escape) and every ink frame write ERASES the image's cells — so this hooks
|
|
196
|
+
* stdout.write and re-paints SYNCHRONOUSLY within the same flush, the whole
|
|
197
|
+
* batch wrapped in DEC 2026 synchronized-update markers: the terminal never
|
|
198
|
+
* presents the erased-frame intermediate state. (The previous deferred
|
|
199
|
+
* setImmediate repaint WAS the native-mode flicker.) A mobx reaction covers
|
|
200
|
+
* byte-only changes (fresh latent/output/lora bytes with no frame write).
|
|
201
|
+
* NOT React: effects only fire for the component that re-rendered, which is
|
|
202
|
+
* why a useEffect painter missed frames (reported: the image waited for input).
|
|
203
|
+
* Kitty differs from iterm in three ways the code below encodes: data uploads
|
|
204
|
+
* ONCE per bytes object then a tiny placement re-paints per flush (same i,p
|
|
205
|
+
* replaces); kitty draws images OVER later text, so a gone image needs an
|
|
206
|
+
* explicit delete or it covers the menu; the cell box stretches, so it is
|
|
207
|
+
* fitted to the image aspect first.
|
|
208
|
+
*/
|
|
209
|
+
function installProtocolImagePainter(st) {
|
|
210
|
+
const proto = imageProtocol();
|
|
211
|
+
if (proto == null || process.stdout.isTTY !== true) return () => {};
|
|
212
|
+
const original = process.stdout.write.bind(process.stdout);
|
|
213
|
+
const CONTENT_ROW = 6;
|
|
214
|
+
const kittyMain = new KittyImageSlot(MAIN_ID);
|
|
215
|
+
const kittyCorner = new KittyImageSlot(CORNER_ID);
|
|
216
|
+
/** both images as ONE escape string ('' when nothing to paint or delete) */
|
|
217
|
+
const imageEscapes = () => {
|
|
218
|
+
const pv = st.preview;
|
|
219
|
+
const main = pv.protocolImage;
|
|
220
|
+
const corner = pv.protocolImageCorner;
|
|
221
|
+
const col = Math.max(1, st.termCols - (pv.width + 4) + 3);
|
|
222
|
+
if (proto === "iterm") {
|
|
223
|
+
if (main == null && corner == null) return "";
|
|
224
|
+
let out = "";
|
|
225
|
+
if (main != null) out += itermImageEscape(main, CONTENT_ROW, col, pv.width, pv.height);
|
|
226
|
+
if (corner != null) {
|
|
227
|
+
const box = pv.cornerBox;
|
|
228
|
+
out += itermImageEscape(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h);
|
|
163
229
|
}
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
beginMenu() {
|
|
167
|
-
this.st.mode = "preview";
|
|
168
|
-
this.menuIx = 0;
|
|
169
|
-
}
|
|
170
|
-
blurMenu() {
|
|
171
|
-
this.st.mode = "nav";
|
|
172
|
-
}
|
|
173
|
-
menuMove(delta) {
|
|
174
|
-
const len = this.menuRows.length;
|
|
175
|
-
this.menuIx = (this.menuIx + delta + len) % len;
|
|
176
|
-
}
|
|
177
|
-
/** cycle the selected row's value (settings persist via SettingsSt reaction) */
|
|
178
|
-
menuCycle(delta) {
|
|
179
|
-
const row = this.menuRows[this.menuIx];
|
|
180
|
-
if (row == null) return;
|
|
181
|
-
const s = this.st.settings;
|
|
182
|
-
if (row.key === "panel") s.previewPanel = !s.previewPanel;
|
|
183
|
-
else if (row.key === "renderer") {
|
|
184
|
-
if (protocolCapable()) s.previewRenderer = s.previewRenderer === "native" ? "pixel" : "native";
|
|
185
|
-
} else {
|
|
186
|
-
const order = [
|
|
187
|
-
"latent",
|
|
188
|
-
"latent-small",
|
|
189
|
-
"last-output"
|
|
190
|
-
];
|
|
191
|
-
s.previewDuringRun = order[(order.indexOf(s.previewDuringRun) + delta + order.length) % order.length] ?? "latent";
|
|
230
|
+
return out;
|
|
192
231
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.latentAnsi = null;
|
|
207
|
-
this.latentBytes = null;
|
|
208
|
-
this.latentDims = null;
|
|
209
|
-
this.latentSeenThisRun = false;
|
|
210
|
-
}
|
|
211
|
-
/** re-render the last output for the newly chosen settings */
|
|
212
|
-
onSettingsChanged() {
|
|
213
|
-
this.outputAnsi = null;
|
|
214
|
-
this.outputBytes = null;
|
|
215
|
-
if (this.show && this.lastOutput != null) this.renderOutput(this.lastOutput);
|
|
216
|
-
}
|
|
217
|
-
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
218
|
-
get protocolImage() {
|
|
219
|
-
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
220
|
-
if (this.overlayActive) return this.overlay?.bytes ?? null;
|
|
221
|
-
if (this.st.exec.running) {
|
|
222
|
-
if (this.duringRun === "latent") return this.latentBytes ?? this.outputBytes;
|
|
223
|
-
return this.outputBytes;
|
|
232
|
+
let out = "";
|
|
233
|
+
if (main == null) out += kittyMain.drop();
|
|
234
|
+
else {
|
|
235
|
+
const dims = imageDims(main);
|
|
236
|
+
const box = fitCellBox({
|
|
237
|
+
imgW: dims.w,
|
|
238
|
+
imgH: dims.h,
|
|
239
|
+
w: pv.width,
|
|
240
|
+
h: pv.height
|
|
241
|
+
});
|
|
242
|
+
const row = CONTENT_ROW + Math.max(0, Math.floor((pv.height - box.h) / 2));
|
|
243
|
+
const c = col + Math.max(0, Math.floor((pv.width - box.w) / 2));
|
|
244
|
+
out += kittyMain.show(main, row, c, box.w, box.h);
|
|
224
245
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
230
|
-
if (this.overlayActive) return null;
|
|
231
|
-
if (this.st.exec.running && this.duringRun === "latent-small") return this.latentBytes;
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
/** corner cell box matched to the latent's REAL aspect (a mismatched box
|
|
235
|
-
* letterboxes in iTerm, showing a tall rectangle). Cells are
|
|
236
|
-
* ~1:2 (w:h), hence the ×2 when converting image aspect to cells. */
|
|
237
|
-
get cornerBox() {
|
|
238
|
-
let w = Math.max(8, Math.floor(this.width * CORNER_FRACTION));
|
|
239
|
-
const maxH = Math.max(4, Math.floor(this.height * CORNER_FRACTION));
|
|
240
|
-
const dims = this.latentDims;
|
|
241
|
-
if (dims == null || dims.width === 0 || dims.height === 0) return {
|
|
242
|
-
w,
|
|
243
|
-
h: maxH
|
|
244
|
-
};
|
|
245
|
-
const aspect = dims.width / dims.height;
|
|
246
|
-
let h = Math.max(2, Math.round(w / aspect / 2));
|
|
247
|
-
if (h > maxH) {
|
|
248
|
-
h = maxH;
|
|
249
|
-
w = Math.max(4, Math.round(h * aspect * 2));
|
|
250
|
-
}
|
|
251
|
-
return {
|
|
252
|
-
w,
|
|
253
|
-
h
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
get width() {
|
|
257
|
-
return Math.max(24, Math.min(80, this.st.termCols - 68 - this.st.treeWidth));
|
|
258
|
-
}
|
|
259
|
-
get height() {
|
|
260
|
-
return Math.max(10, this.st.termRows - 12);
|
|
261
|
-
}
|
|
262
|
-
async renderOutput(src) {
|
|
263
|
-
this.lastOutput = src;
|
|
264
|
-
if (!this.show) return;
|
|
265
|
-
try {
|
|
266
|
-
if (this.useNative) {
|
|
267
|
-
const shrunk = await sharp(src).resize(896, 896, {
|
|
268
|
-
fit: "inside",
|
|
269
|
-
withoutEnlargement: true
|
|
270
|
-
}).png().toBuffer();
|
|
271
|
-
runInAction(() => {
|
|
272
|
-
this.outputBytes = new Uint8Array(shrunk);
|
|
273
|
-
});
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const rendered = await imageBufferToAnsi(src, {
|
|
277
|
-
width: this.width,
|
|
278
|
-
height: this.height
|
|
279
|
-
});
|
|
280
|
-
runInAction(() => {
|
|
281
|
-
this.outputAnsi = rendered;
|
|
282
|
-
});
|
|
283
|
-
} catch (e) {
|
|
284
|
-
runInAction(() => {
|
|
285
|
-
this.st.exec.notice = `preview: ${extractErrorMessage(e)}`;
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
async renderLatent(bytes) {
|
|
290
|
-
runInAction(() => {
|
|
291
|
-
this.latentSeenThisRun = true;
|
|
292
|
-
});
|
|
293
|
-
if (!this.show || this.duringRun === "last-output") return;
|
|
294
|
-
if (this.useNative) {
|
|
295
|
-
const meta = imageMeta(bytes);
|
|
296
|
-
this.latentBytes = bytes;
|
|
297
|
-
this.latentDims = meta.width != null && meta.height != null ? {
|
|
298
|
-
width: meta.width,
|
|
299
|
-
height: meta.height
|
|
300
|
-
} : null;
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
if (this._busy) return;
|
|
304
|
-
this._busy = true;
|
|
305
|
-
try {
|
|
306
|
-
const ansi = this.duringRun === "latent-small" ? await this.renderLatentSmallPixel(bytes) : await imageBufferToAnsi(bytes, {
|
|
307
|
-
width: this.width,
|
|
308
|
-
height: this.height
|
|
309
|
-
});
|
|
310
|
-
runInAction(() => {
|
|
311
|
-
this.latentAnsi = ansi;
|
|
312
|
-
});
|
|
313
|
-
} catch (e) {
|
|
314
|
-
runInAction(() => {
|
|
315
|
-
this.st.exec.notice = `latent preview: ${extractErrorMessage(e)}`;
|
|
316
|
-
});
|
|
317
|
-
} finally {
|
|
318
|
-
this._busy = false;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
/** pixel 'latent small': sharp-composite the latent thumb onto the last
|
|
322
|
-
* output (top-right), then ONE half-block render — a string-level overlay
|
|
323
|
-
* was tried and dropped: its space padding reads as black bars */
|
|
324
|
-
async renderLatentSmallPixel(bytes) {
|
|
325
|
-
const pxW = this.width;
|
|
326
|
-
const pxH = this.height * 2;
|
|
327
|
-
const thumb = await sharp(bytes).resize(Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)), Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)), { fit: "inside" }).png().toBuffer();
|
|
328
|
-
const out = this.lastOutput;
|
|
329
|
-
if (out == null) return imageBufferToAnsi(thumb, {
|
|
330
|
-
width: this.width,
|
|
331
|
-
height: this.height
|
|
332
|
-
});
|
|
333
|
-
return imageBufferToAnsi(await sharp(await sharp(out).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
|
|
334
|
-
input: thumb,
|
|
335
|
-
gravity: "northeast"
|
|
336
|
-
}]).png().toBuffer(), {
|
|
337
|
-
width: this.width,
|
|
338
|
-
height: this.height
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
//#endregion
|
|
343
|
-
//#region src/cli/tui/protocolImagePainter.ts
|
|
344
|
-
const SYNC_BEGIN = "\x1B[?2026h";
|
|
345
|
-
const SYNC_END = "\x1B[?2026l";
|
|
346
|
-
/** below this a write is a terminal query/reply, not a frame — no cells damaged */
|
|
347
|
-
const MIN_FRAME_BYTES = 64;
|
|
348
|
-
/**
|
|
349
|
-
* paints the REAL image (OSC 1337) over the preview panel's cell rect.
|
|
350
|
-
* Protocol images cannot go THROUGH ink (layout shreds the escape) and every
|
|
351
|
-
* ink frame write ERASES the image's cells — so this hooks stdout.write and
|
|
352
|
-
* re-paints SYNCHRONOUSLY within the same flush, the whole batch wrapped in
|
|
353
|
-
* DEC 2026 synchronized-update markers: the terminal never presents the
|
|
354
|
-
* erased-frame intermediate state. (The previous deferred setImmediate
|
|
355
|
-
* repaint WAS the native-mode flicker.) A mobx reaction covers
|
|
356
|
-
* byte-only changes (fresh latent/output/lora bytes with no frame write).
|
|
357
|
-
* NOT React: effects only fire for the component that re-rendered, which is
|
|
358
|
-
* why a useEffect painter missed frames (reported: the image waited for input).
|
|
359
|
-
*/
|
|
360
|
-
function installProtocolImagePainter(st) {
|
|
361
|
-
if (!protocolCapable() || process.stdout.isTTY !== true) return () => {};
|
|
362
|
-
const original = process.stdout.write.bind(process.stdout);
|
|
363
|
-
const imageEscape = (bytes, row, col, w, h) => {
|
|
364
|
-
const b64 = Buffer.from(bytes).toString("base64");
|
|
365
|
-
return `\u001b7\u001b[${row};${col}H\u001b]1337;File=inline=1;size=${bytes.byteLength};width=${w};height=${h};preserveAspectRatio=1:${b64}\u0007\u001b8`;
|
|
366
|
-
};
|
|
367
|
-
const CONTENT_ROW = 6;
|
|
368
|
-
/** both images as ONE escape string ('' when nothing to paint) */
|
|
369
|
-
const imageEscapes = () => {
|
|
370
|
-
const pv = st.preview;
|
|
371
|
-
const main = pv.protocolImage;
|
|
372
|
-
const corner = pv.protocolImageCorner;
|
|
373
|
-
if (main == null && corner == null) return "";
|
|
374
|
-
const col = Math.max(1, st.termCols - (pv.width + 4) + 3);
|
|
375
|
-
let out = "";
|
|
376
|
-
if (main != null) out += imageEscape(main, CONTENT_ROW, col, pv.width, pv.height);
|
|
377
|
-
if (corner != null) {
|
|
378
|
-
const box = pv.cornerBox;
|
|
379
|
-
out += imageEscape(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h);
|
|
246
|
+
if (corner == null) out += kittyCorner.drop();
|
|
247
|
+
else {
|
|
248
|
+
const box = pv.cornerBox;
|
|
249
|
+
out += kittyCorner.show(corner, CONTENT_ROW, col + pv.width - box.w, box.w, box.h, CORNER_Z);
|
|
380
250
|
}
|
|
381
251
|
return out;
|
|
382
252
|
};
|
|
@@ -404,6 +274,7 @@ function installProtocolImagePainter(st) {
|
|
|
404
274
|
const disposeReaction = reaction(() => [st.preview.protocolImage, st.preview.protocolImageCorner], schedule);
|
|
405
275
|
return () => {
|
|
406
276
|
disposed = true;
|
|
277
|
+
if (proto === "kitty") original(KITTY_DELETE_ALL);
|
|
407
278
|
process.stdout.write = original;
|
|
408
279
|
disposeReaction();
|
|
409
280
|
};
|
|
@@ -1274,6 +1145,39 @@ function fuzzyMatch(needle, hay) {
|
|
|
1274
1145
|
return i >= n.length;
|
|
1275
1146
|
}
|
|
1276
1147
|
//#endregion
|
|
1148
|
+
//#region src/utils/ansiImage.ts
|
|
1149
|
+
/**
|
|
1150
|
+
* render an image as truecolor half-block ANSI: each char cell is 1px wide and
|
|
1151
|
+
* 2px tall (bg color = top pixel, fg '▄' = bottom pixel). Works in any
|
|
1152
|
+
* truecolor terminal and — unlike protocol images (iTerm/kitty/sixel) —
|
|
1153
|
+
* survives ink's layout engine. width/height are CHAR CELLS.
|
|
1154
|
+
*/
|
|
1155
|
+
async function imageBufferToAnsi(input, p) {
|
|
1156
|
+
const { data, info } = await sharp(input).flatten({ background: p.background ?? "#1e1e1e" }).resize(p.width, p.height * 2, { fit: "inside" }).raw().toBuffer({ resolveWithObject: true });
|
|
1157
|
+
const w = info.width;
|
|
1158
|
+
const h = info.height;
|
|
1159
|
+
const c = info.channels;
|
|
1160
|
+
const px = (x, y) => {
|
|
1161
|
+
const i = (y * w + x) * c;
|
|
1162
|
+
return [
|
|
1163
|
+
data[i] ?? 0,
|
|
1164
|
+
data[i + 1] ?? 0,
|
|
1165
|
+
data[i + 2] ?? 0
|
|
1166
|
+
];
|
|
1167
|
+
};
|
|
1168
|
+
const rows = [];
|
|
1169
|
+
for (let y = 0; y < h; y += 2) {
|
|
1170
|
+
let row = "";
|
|
1171
|
+
for (let x = 0; x < w; x++) {
|
|
1172
|
+
const [tr, tg, tb] = px(x, y);
|
|
1173
|
+
const [br, bg, bb] = y + 1 < h ? px(x, y + 1) : px(x, y);
|
|
1174
|
+
row += `\x1b[48;2;${tr};${tg};${tb}m\x1b[38;2;${br};${bg};${bb}m▄`;
|
|
1175
|
+
}
|
|
1176
|
+
rows.push(row + "\x1B[0m");
|
|
1177
|
+
}
|
|
1178
|
+
return rows.join("\n");
|
|
1179
|
+
}
|
|
1180
|
+
//#endregion
|
|
1277
1181
|
//#region src/cli/tui/imagePicker/ImagePickerSt.ts
|
|
1278
1182
|
const PICKER_PANES = [
|
|
1279
1183
|
"browse",
|
|
@@ -1482,11 +1386,11 @@ var ImagePickerSt = class {
|
|
|
1482
1386
|
try {
|
|
1483
1387
|
const bytes = new Uint8Array(readFileSync(path));
|
|
1484
1388
|
if (this.st.preview.useNative) this.st.preview.setOverlayImage({
|
|
1485
|
-
bytes,
|
|
1389
|
+
bytes: await protocolReadyBytes(bytes),
|
|
1486
1390
|
ansi: null,
|
|
1487
1391
|
name: basename(path),
|
|
1488
1392
|
note: null
|
|
1489
|
-
});
|
|
1393
|
+
}, "overlay-image");
|
|
1490
1394
|
else {
|
|
1491
1395
|
const ansi = await imageBufferToAnsi(bytes, {
|
|
1492
1396
|
width: this.st.preview.width,
|
|
@@ -1497,7 +1401,7 @@ var ImagePickerSt = class {
|
|
|
1497
1401
|
ansi,
|
|
1498
1402
|
name: basename(path),
|
|
1499
1403
|
note: null
|
|
1500
|
-
});
|
|
1404
|
+
}, "overlay-image");
|
|
1501
1405
|
}
|
|
1502
1406
|
} catch (e) {
|
|
1503
1407
|
this.st.preview.setOverlayImage({
|
|
@@ -1505,7 +1409,7 @@ var ImagePickerSt = class {
|
|
|
1505
1409
|
ansi: null,
|
|
1506
1410
|
name: basename(path),
|
|
1507
1411
|
note: extractErrorMessage(e)
|
|
1508
|
-
});
|
|
1412
|
+
}, "overlay-image");
|
|
1509
1413
|
} finally {
|
|
1510
1414
|
this._busy = false;
|
|
1511
1415
|
if (this.st.mode === "overlay-image" && this.highlightedImage !== path) this.refreshPreview();
|
|
@@ -3545,18 +3449,18 @@ var LorasSt = class {
|
|
|
3545
3449
|
ansi: null,
|
|
3546
3450
|
name: `lora ${name}`,
|
|
3547
3451
|
note
|
|
3548
|
-
});
|
|
3452
|
+
}, "overlay-loras");
|
|
3549
3453
|
return;
|
|
3550
3454
|
}
|
|
3551
3455
|
const bytes = await fetchLoraPreviewBytes(host, url);
|
|
3552
3456
|
if (bytes == null) throw new Error("no image preview on the server");
|
|
3553
3457
|
if (this.st.preview.useNative) {
|
|
3554
3458
|
this.st.preview.setOverlayImage({
|
|
3555
|
-
bytes,
|
|
3459
|
+
bytes: await protocolReadyBytes(bytes),
|
|
3556
3460
|
ansi: null,
|
|
3557
3461
|
name: `lora ${name}`,
|
|
3558
3462
|
note: null
|
|
3559
|
-
});
|
|
3463
|
+
}, "overlay-loras");
|
|
3560
3464
|
return;
|
|
3561
3465
|
}
|
|
3562
3466
|
const ansi = await imageBufferToAnsi(bytes, {
|
|
@@ -3568,14 +3472,14 @@ var LorasSt = class {
|
|
|
3568
3472
|
ansi,
|
|
3569
3473
|
name: `lora ${name}`,
|
|
3570
3474
|
note: null
|
|
3571
|
-
});
|
|
3475
|
+
}, "overlay-loras");
|
|
3572
3476
|
} catch (e) {
|
|
3573
3477
|
this.st.preview.setOverlayImage({
|
|
3574
3478
|
bytes: null,
|
|
3575
3479
|
ansi: null,
|
|
3576
3480
|
name: `lora ${name}`,
|
|
3577
3481
|
note: extractErrorMessage(e)
|
|
3578
|
-
});
|
|
3482
|
+
}, "overlay-loras");
|
|
3579
3483
|
} finally {
|
|
3580
3484
|
this._busy = false;
|
|
3581
3485
|
if (this.st.mode === "overlay-loras" && this.selectedName !== name) this.refreshPreview();
|
|
@@ -3686,6 +3590,282 @@ var PickerSt = class {
|
|
|
3686
3590
|
}
|
|
3687
3591
|
};
|
|
3688
3592
|
//#endregion
|
|
3593
|
+
//#region src/cli/tui/state/PreviewSt.ts
|
|
3594
|
+
/** small-latent corner: fraction of the panel each dimension takes */
|
|
3595
|
+
const CORNER_FRACTION = .38;
|
|
3596
|
+
/** pixel 'latent small': the sharp-composited thumb takes this fraction of the panel */
|
|
3597
|
+
const PIXEL_SMALL_FRACTION = .4;
|
|
3598
|
+
/**
|
|
3599
|
+
* right-side preview panel + its `p` settings menu (mode 'preview').
|
|
3600
|
+
* Three independent axes live in SettingsSt: panel on/off, renderer
|
|
3601
|
+
* native/pixel, and what to show while running (latent / latent small /
|
|
3602
|
+
* last output). Sources: live latent while running, last output after,
|
|
3603
|
+
* selected lora while the loras overlay is open.
|
|
3604
|
+
*/
|
|
3605
|
+
var PreviewSt = class {
|
|
3606
|
+
constructor(st) {
|
|
3607
|
+
this.st = st;
|
|
3608
|
+
this.outputAnsi = null;
|
|
3609
|
+
this.latentAnsi = null;
|
|
3610
|
+
this.outputBytes = null;
|
|
3611
|
+
this.latentBytes = null;
|
|
3612
|
+
this.latentDims = null;
|
|
3613
|
+
this.latentSeenThisRun = false;
|
|
3614
|
+
this.lastOutput = null;
|
|
3615
|
+
this.overlay = null;
|
|
3616
|
+
this.menuIx = 0;
|
|
3617
|
+
this._busy = false;
|
|
3618
|
+
makeAutoObservable(this, { st: false });
|
|
3619
|
+
}
|
|
3620
|
+
get show() {
|
|
3621
|
+
return this.st.settings.previewPanel;
|
|
3622
|
+
}
|
|
3623
|
+
get renderer() {
|
|
3624
|
+
return this.st.settings.previewRenderer;
|
|
3625
|
+
}
|
|
3626
|
+
get useNative() {
|
|
3627
|
+
return this.renderer === "native";
|
|
3628
|
+
}
|
|
3629
|
+
get duringRun() {
|
|
3630
|
+
return this.st.settings.previewDuringRun;
|
|
3631
|
+
}
|
|
3632
|
+
get menuOpen() {
|
|
3633
|
+
return this.st.mode === "preview";
|
|
3634
|
+
}
|
|
3635
|
+
get overlayActive() {
|
|
3636
|
+
return this.st.mode === "overlay-loras" || this.st.mode === "overlay-image";
|
|
3637
|
+
}
|
|
3638
|
+
/** owner = the overlay mode the render was FOR: every writer awaits (file
|
|
3639
|
+
* read, fetch, transcode) before landing here, and by then another overlay
|
|
3640
|
+
* can own the slot — a stale write would overwrite its image */
|
|
3641
|
+
setOverlayImage(p, owner) {
|
|
3642
|
+
if (this.st.mode !== owner) return;
|
|
3643
|
+
this.overlay = p;
|
|
3644
|
+
}
|
|
3645
|
+
clearOverlayImage() {
|
|
3646
|
+
this.overlay = null;
|
|
3647
|
+
}
|
|
3648
|
+
/** running + latents wanted + sampling well underway + none arrived = server
|
|
3649
|
+
* sends none. The ≥20% gate keeps healthy runs from red-flashing: the first
|
|
3650
|
+
* progress tick lands a beat before the first preview frame */
|
|
3651
|
+
get latentsMissing() {
|
|
3652
|
+
return this.st.exec.running && this.duringRun !== "last-output" && (this.st.exec.progress?.percent ?? 0) >= 20 && !this.latentSeenThisRun;
|
|
3653
|
+
}
|
|
3654
|
+
get menuRows() {
|
|
3655
|
+
return [
|
|
3656
|
+
{
|
|
3657
|
+
key: "panel",
|
|
3658
|
+
label: "panel",
|
|
3659
|
+
value: this.show ? "on" : "off"
|
|
3660
|
+
},
|
|
3661
|
+
{
|
|
3662
|
+
key: "renderer",
|
|
3663
|
+
label: "renderer",
|
|
3664
|
+
value: this.renderer + (protocolCapable() ? "" : " (this terminal cannot show real images)")
|
|
3665
|
+
},
|
|
3666
|
+
{
|
|
3667
|
+
key: "during-run",
|
|
3668
|
+
label: "while running",
|
|
3669
|
+
value: this.duringRun === "latent" ? "latent" : this.duringRun === "latent-small" ? "latent small" : "last output"
|
|
3670
|
+
}
|
|
3671
|
+
];
|
|
3672
|
+
}
|
|
3673
|
+
beginMenu() {
|
|
3674
|
+
this.st.mode = "preview";
|
|
3675
|
+
this.menuIx = 0;
|
|
3676
|
+
}
|
|
3677
|
+
blurMenu() {
|
|
3678
|
+
this.st.mode = "nav";
|
|
3679
|
+
}
|
|
3680
|
+
menuMove(delta) {
|
|
3681
|
+
const len = this.menuRows.length;
|
|
3682
|
+
this.menuIx = (this.menuIx + delta + len) % len;
|
|
3683
|
+
}
|
|
3684
|
+
/** cycle the selected row's value (settings persist via SettingsSt reaction) */
|
|
3685
|
+
menuCycle(delta) {
|
|
3686
|
+
const row = this.menuRows[this.menuIx];
|
|
3687
|
+
if (row == null) return;
|
|
3688
|
+
const s = this.st.settings;
|
|
3689
|
+
if (row.key === "panel") s.previewPanel = !s.previewPanel;
|
|
3690
|
+
else if (row.key === "renderer") {
|
|
3691
|
+
if (protocolCapable()) s.previewRenderer = s.previewRenderer === "native" ? "pixel" : "native";
|
|
3692
|
+
} else {
|
|
3693
|
+
const order = [
|
|
3694
|
+
"latent",
|
|
3695
|
+
"latent-small",
|
|
3696
|
+
"last-output"
|
|
3697
|
+
];
|
|
3698
|
+
s.previewDuringRun = order[(order.indexOf(s.previewDuringRun) + delta + order.length) % order.length] ?? "latent";
|
|
3699
|
+
}
|
|
3700
|
+
this.onSettingsChanged();
|
|
3701
|
+
}
|
|
3702
|
+
reset() {
|
|
3703
|
+
this.outputAnsi = null;
|
|
3704
|
+
this.latentAnsi = null;
|
|
3705
|
+
this.outputBytes = null;
|
|
3706
|
+
this.latentBytes = null;
|
|
3707
|
+
this.latentDims = null;
|
|
3708
|
+
this.latentSeenThisRun = false;
|
|
3709
|
+
this.lastOutput = null;
|
|
3710
|
+
}
|
|
3711
|
+
/** run boundary: drop the latents so the next run never shows the previous one's */
|
|
3712
|
+
clearLatent() {
|
|
3713
|
+
this.latentAnsi = null;
|
|
3714
|
+
this.latentBytes = null;
|
|
3715
|
+
this.latentDims = null;
|
|
3716
|
+
this.latentSeenThisRun = false;
|
|
3717
|
+
}
|
|
3718
|
+
/** re-render the last output for the newly chosen settings */
|
|
3719
|
+
onSettingsChanged() {
|
|
3720
|
+
this.outputAnsi = null;
|
|
3721
|
+
this.outputBytes = null;
|
|
3722
|
+
if (this.show && this.lastOutput != null) this.renderOutput(this.lastOutput);
|
|
3723
|
+
}
|
|
3724
|
+
/** what the painter should show RIGHT NOW (native renderer only; mirrors the panel's source) */
|
|
3725
|
+
get protocolImage() {
|
|
3726
|
+
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
3727
|
+
if (this.overlayActive) return this.overlay?.bytes ?? null;
|
|
3728
|
+
if (this.st.exec.running) {
|
|
3729
|
+
if (this.duringRun === "latent") return this.latentBytes ?? this.outputBytes;
|
|
3730
|
+
return this.outputBytes;
|
|
3731
|
+
}
|
|
3732
|
+
return this.outputBytes;
|
|
3733
|
+
}
|
|
3734
|
+
/** small latent painted over the panel's top-right corner (native + 'latent small' only) */
|
|
3735
|
+
get protocolImageCorner() {
|
|
3736
|
+
if (!this.useNative || !this.show || this.menuOpen) return null;
|
|
3737
|
+
if (this.overlayActive) return null;
|
|
3738
|
+
if (this.st.exec.running && this.duringRun === "latent-small") return this.latentBytes;
|
|
3739
|
+
return null;
|
|
3740
|
+
}
|
|
3741
|
+
/** corner cell box matched to the latent's REAL aspect (a mismatched box
|
|
3742
|
+
* letterboxes in iTerm, showing a tall rectangle). Cells are
|
|
3743
|
+
* ~1:2 (w:h), hence the ×2 when converting image aspect to cells. */
|
|
3744
|
+
get cornerBox() {
|
|
3745
|
+
let w = Math.max(8, Math.floor(this.width * CORNER_FRACTION));
|
|
3746
|
+
const maxH = Math.max(4, Math.floor(this.height * CORNER_FRACTION));
|
|
3747
|
+
const dims = this.latentDims;
|
|
3748
|
+
if (dims == null || dims.width === 0 || dims.height === 0) return {
|
|
3749
|
+
w,
|
|
3750
|
+
h: maxH
|
|
3751
|
+
};
|
|
3752
|
+
const aspect = dims.width / dims.height;
|
|
3753
|
+
let h = Math.max(2, Math.round(w / aspect / 2));
|
|
3754
|
+
if (h > maxH) {
|
|
3755
|
+
h = maxH;
|
|
3756
|
+
w = Math.max(4, Math.round(h * aspect * 2));
|
|
3757
|
+
}
|
|
3758
|
+
return {
|
|
3759
|
+
w,
|
|
3760
|
+
h
|
|
3761
|
+
};
|
|
3762
|
+
}
|
|
3763
|
+
get width() {
|
|
3764
|
+
return Math.max(24, Math.min(80, this.st.termCols - 68 - this.st.treeWidth));
|
|
3765
|
+
}
|
|
3766
|
+
get height() {
|
|
3767
|
+
return Math.max(10, this.st.termRows - 12);
|
|
3768
|
+
}
|
|
3769
|
+
async renderOutput(src) {
|
|
3770
|
+
this.lastOutput = src;
|
|
3771
|
+
if (!this.show) return;
|
|
3772
|
+
try {
|
|
3773
|
+
if (this.useNative) {
|
|
3774
|
+
const shrunk = await sharp(src).resize(896, 896, {
|
|
3775
|
+
fit: "inside",
|
|
3776
|
+
withoutEnlargement: true
|
|
3777
|
+
}).png().toBuffer();
|
|
3778
|
+
runInAction(() => {
|
|
3779
|
+
this.outputBytes = new Uint8Array(shrunk);
|
|
3780
|
+
});
|
|
3781
|
+
return;
|
|
3782
|
+
}
|
|
3783
|
+
const rendered = await imageBufferToAnsi(src, {
|
|
3784
|
+
width: this.width,
|
|
3785
|
+
height: this.height
|
|
3786
|
+
});
|
|
3787
|
+
runInAction(() => {
|
|
3788
|
+
this.outputAnsi = rendered;
|
|
3789
|
+
});
|
|
3790
|
+
} catch (e) {
|
|
3791
|
+
runInAction(() => {
|
|
3792
|
+
this.st.exec.notice = `preview: ${extractErrorMessage(e)}`;
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
async renderLatent(bytes) {
|
|
3797
|
+
runInAction(() => {
|
|
3798
|
+
this.latentSeenThisRun = true;
|
|
3799
|
+
});
|
|
3800
|
+
if (!this.show || this.duringRun === "last-output") return;
|
|
3801
|
+
if (this.useNative) {
|
|
3802
|
+
const meta = imageMeta(bytes);
|
|
3803
|
+
const dims = meta.width != null && meta.height != null ? {
|
|
3804
|
+
width: meta.width,
|
|
3805
|
+
height: meta.height
|
|
3806
|
+
} : null;
|
|
3807
|
+
if (imageProtocol() !== "kitty") {
|
|
3808
|
+
this.latentBytes = bytes;
|
|
3809
|
+
this.latentDims = dims;
|
|
3810
|
+
return;
|
|
3811
|
+
}
|
|
3812
|
+
if (this._busy) return;
|
|
3813
|
+
this._busy = true;
|
|
3814
|
+
try {
|
|
3815
|
+
const png = await protocolReadyBytes(bytes);
|
|
3816
|
+
runInAction(() => {
|
|
3817
|
+
this.latentBytes = png;
|
|
3818
|
+
this.latentDims = dims;
|
|
3819
|
+
});
|
|
3820
|
+
} catch (e) {
|
|
3821
|
+
runInAction(() => {
|
|
3822
|
+
this.st.exec.notice = `latent preview: ${extractErrorMessage(e)}`;
|
|
3823
|
+
});
|
|
3824
|
+
} finally {
|
|
3825
|
+
this._busy = false;
|
|
3826
|
+
}
|
|
3827
|
+
return;
|
|
3828
|
+
}
|
|
3829
|
+
if (this._busy) return;
|
|
3830
|
+
this._busy = true;
|
|
3831
|
+
try {
|
|
3832
|
+
const ansi = this.duringRun === "latent-small" ? await this.renderLatentSmallPixel(bytes) : await imageBufferToAnsi(bytes, {
|
|
3833
|
+
width: this.width,
|
|
3834
|
+
height: this.height
|
|
3835
|
+
});
|
|
3836
|
+
runInAction(() => {
|
|
3837
|
+
this.latentAnsi = ansi;
|
|
3838
|
+
});
|
|
3839
|
+
} catch (e) {
|
|
3840
|
+
runInAction(() => {
|
|
3841
|
+
this.st.exec.notice = `latent preview: ${extractErrorMessage(e)}`;
|
|
3842
|
+
});
|
|
3843
|
+
} finally {
|
|
3844
|
+
this._busy = false;
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3847
|
+
/** pixel 'latent small': sharp-composite the latent thumb onto the last
|
|
3848
|
+
* output (top-right), then ONE half-block render — a string-level overlay
|
|
3849
|
+
* was tried and dropped: its space padding reads as black bars */
|
|
3850
|
+
async renderLatentSmallPixel(bytes) {
|
|
3851
|
+
const pxW = this.width;
|
|
3852
|
+
const pxH = this.height * 2;
|
|
3853
|
+
const thumb = await sharp(bytes).resize(Math.max(8, Math.floor(pxW * PIXEL_SMALL_FRACTION)), Math.max(8, Math.floor(pxH * PIXEL_SMALL_FRACTION)), { fit: "inside" }).png().toBuffer();
|
|
3854
|
+
const out = this.lastOutput;
|
|
3855
|
+
if (out == null) return imageBufferToAnsi(thumb, {
|
|
3856
|
+
width: this.width,
|
|
3857
|
+
height: this.height
|
|
3858
|
+
});
|
|
3859
|
+
return imageBufferToAnsi(await sharp(await sharp(out).resize(pxW, pxH, { fit: "inside" }).png().toBuffer()).composite([{
|
|
3860
|
+
input: thumb,
|
|
3861
|
+
gravity: "northeast"
|
|
3862
|
+
}]).png().toBuffer(), {
|
|
3863
|
+
width: this.width,
|
|
3864
|
+
height: this.height
|
|
3865
|
+
});
|
|
3866
|
+
}
|
|
3867
|
+
};
|
|
3868
|
+
//#endregion
|
|
3689
3869
|
//#region src/cli/tui/state/QueueSt.ts
|
|
3690
3870
|
/** live server queue length (ws 'status' messages) + queue actions */
|
|
3691
3871
|
var QueueSt = class {
|
|
@@ -4411,4 +4591,4 @@ async function runTui(args) {
|
|
|
4411
4591
|
//#endregion
|
|
4412
4592
|
export { runTui };
|
|
4413
4593
|
|
|
4414
|
-
//# sourceMappingURL=run-tui-
|
|
4594
|
+
//# sourceMappingURL=run-tui-JxlEbb_f.js.map
|