pi-zentui 0.2.6 → 0.2.7
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/extensions/zentui/ui.ts +51 -14
- package/package.json +1 -1
package/extensions/zentui/ui.ts
CHANGED
|
@@ -56,6 +56,7 @@ type PolishedFrameOptions = {
|
|
|
56
56
|
uiTheme: Theme;
|
|
57
57
|
config: PolishedTuiConfig;
|
|
58
58
|
modelMeta: EditorMeta;
|
|
59
|
+
previousModelMeta?: EditorMeta;
|
|
59
60
|
thinkingLevel: string | undefined;
|
|
60
61
|
rightStatus?: string;
|
|
61
62
|
};
|
|
@@ -149,29 +150,53 @@ function isRenderedModelMetaLine(line: string, modelMeta: EditorMeta): boolean {
|
|
|
149
150
|
return plain.includes(modelMeta.modelLabel) && plain.includes(modelMeta.providerLabel);
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
function
|
|
153
|
-
|
|
153
|
+
function matchesAnyModelMeta(
|
|
154
|
+
line: string,
|
|
155
|
+
modelMeta: EditorMeta,
|
|
156
|
+
previousMeta?: EditorMeta,
|
|
157
|
+
): boolean {
|
|
158
|
+
if (isRenderedModelMetaLine(line, modelMeta)) return true;
|
|
159
|
+
if (previousMeta && isRenderedModelMetaLine(line, previousMeta)) return true;
|
|
160
|
+
return false;
|
|
154
161
|
}
|
|
155
162
|
|
|
156
|
-
function
|
|
163
|
+
function hasRenderedModelMetaLine(
|
|
164
|
+
lines: string[],
|
|
165
|
+
modelMeta: EditorMeta,
|
|
166
|
+
previousMeta?: EditorMeta,
|
|
167
|
+
): boolean {
|
|
168
|
+
return lines.some((line) => matchesAnyModelMeta(line, modelMeta, previousMeta));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isAlreadyPolishedFrame(
|
|
172
|
+
lines: string[],
|
|
173
|
+
modelMeta: EditorMeta,
|
|
174
|
+
previousMeta?: EditorMeta,
|
|
175
|
+
): boolean {
|
|
157
176
|
return (
|
|
158
177
|
lines.length >= 3 &&
|
|
159
178
|
isHorizontalBorder(lines[0] ?? "") &&
|
|
160
179
|
isHorizontalBorder(lines.at(-1) ?? "") &&
|
|
161
|
-
hasRenderedModelMetaLine(lines.slice(1, -1), modelMeta)
|
|
180
|
+
hasRenderedModelMetaLine(lines.slice(1, -1), modelMeta, previousMeta)
|
|
162
181
|
);
|
|
163
182
|
}
|
|
164
183
|
|
|
165
|
-
function removeRenderedModelMetaLines(
|
|
184
|
+
function removeRenderedModelMetaLines(
|
|
185
|
+
lines: string[],
|
|
186
|
+
modelMeta: EditorMeta,
|
|
187
|
+
previousMeta?: EditorMeta,
|
|
188
|
+
): string[] {
|
|
166
189
|
const result: string[] = [];
|
|
167
190
|
for (let index = 0; index < lines.length; index++) {
|
|
168
191
|
const line = lines[index] ?? "";
|
|
169
|
-
if (
|
|
192
|
+
if (matchesAnyModelMeta(line, modelMeta, previousMeta)) continue;
|
|
170
193
|
|
|
171
194
|
const plain = plainRenderedText(line).trim();
|
|
172
|
-
const previousWasMeta =
|
|
195
|
+
const previousWasMeta =
|
|
196
|
+
index > 0 && matchesAnyModelMeta(lines[index - 1] ?? "", modelMeta, previousMeta);
|
|
173
197
|
const nextIsMeta =
|
|
174
|
-
index < lines.length - 1 &&
|
|
198
|
+
index < lines.length - 1 &&
|
|
199
|
+
matchesAnyModelMeta(lines[index + 1] ?? "", modelMeta, previousMeta);
|
|
175
200
|
if (!plain && (previousWasMeta || nextIsMeta)) continue;
|
|
176
201
|
|
|
177
202
|
result.push(line);
|
|
@@ -219,6 +244,7 @@ function renderPolishedFrame({
|
|
|
219
244
|
uiTheme,
|
|
220
245
|
config,
|
|
221
246
|
modelMeta,
|
|
247
|
+
previousModelMeta,
|
|
222
248
|
thinkingLevel,
|
|
223
249
|
rightStatus,
|
|
224
250
|
}: PolishedFrameOptions): string[] {
|
|
@@ -251,9 +277,9 @@ function renderPolishedFrame({
|
|
|
251
277
|
: [];
|
|
252
278
|
if (editorFrame.length < 2) return clampRenderedLines(baseRendered, width);
|
|
253
279
|
|
|
254
|
-
const stalePolishedFrame = isAlreadyPolishedFrame(editorFrame, modelMeta);
|
|
280
|
+
const stalePolishedFrame = isAlreadyPolishedFrame(editorFrame, modelMeta, previousModelMeta);
|
|
255
281
|
const editorLines = removeStalePolishedLeadingSpacer(
|
|
256
|
-
removeRenderedModelMetaLines(editorFrame.slice(1, -1), modelMeta),
|
|
282
|
+
removeRenderedModelMetaLines(editorFrame.slice(1, -1), modelMeta, previousModelMeta),
|
|
257
283
|
stalePolishedFrame,
|
|
258
284
|
);
|
|
259
285
|
const model = renderStyleForSourceOrFallback(
|
|
@@ -332,6 +358,7 @@ export class PolishedEditor extends CustomEditor {
|
|
|
332
358
|
private readonly getThinkingLevel: () => string | undefined;
|
|
333
359
|
private readonly getConfig: () => PolishedTuiConfig;
|
|
334
360
|
private readonly uiTheme: Theme;
|
|
361
|
+
private previousModelMeta?: EditorMeta;
|
|
335
362
|
|
|
336
363
|
constructor(
|
|
337
364
|
tui: TUI,
|
|
@@ -359,19 +386,25 @@ export class PolishedEditor extends CustomEditor {
|
|
|
359
386
|
const { railWidth } = getEditorChromeWidths(config, this.uiTheme, "\x1b[0m");
|
|
360
387
|
const innerWidth = Math.max(0, width - railWidth);
|
|
361
388
|
const rendered = super.render(innerWidth);
|
|
362
|
-
|
|
389
|
+
const modelMeta = this.getModelMeta();
|
|
390
|
+
const result = renderPolishedFrame({
|
|
363
391
|
width,
|
|
364
392
|
baseRendered: rendered,
|
|
365
393
|
autocompleteSource: this as unknown as AutocompleteEditorInternals,
|
|
366
394
|
uiTheme: this.uiTheme,
|
|
367
395
|
config,
|
|
368
|
-
modelMeta
|
|
396
|
+
modelMeta,
|
|
397
|
+
previousModelMeta: this.previousModelMeta,
|
|
369
398
|
thinkingLevel: this.getThinkingLevel(),
|
|
370
399
|
});
|
|
400
|
+
this.previousModelMeta = modelMeta;
|
|
401
|
+
return result;
|
|
371
402
|
}
|
|
372
403
|
}
|
|
373
404
|
|
|
374
405
|
export class WrappedPolishedEditor implements EditorComponent {
|
|
406
|
+
private previousModelMeta?: EditorMeta;
|
|
407
|
+
|
|
375
408
|
constructor(
|
|
376
409
|
private readonly base: WrappedEditor,
|
|
377
410
|
private readonly uiTheme: Theme,
|
|
@@ -465,16 +498,20 @@ export class WrappedPolishedEditor implements EditorComponent {
|
|
|
465
498
|
const innerWidth = Math.max(0, width - railWidth);
|
|
466
499
|
const rendered = this.base.render(innerWidth);
|
|
467
500
|
const vimStatus = readVimStatus(this.base, this.uiTheme);
|
|
468
|
-
|
|
501
|
+
const modelMeta = this.getModelMeta();
|
|
502
|
+
const result = renderPolishedFrame({
|
|
469
503
|
width,
|
|
470
504
|
baseRendered: rendered,
|
|
471
505
|
autocompleteSource: this.base,
|
|
472
506
|
uiTheme: this.uiTheme,
|
|
473
507
|
config,
|
|
474
|
-
modelMeta
|
|
508
|
+
modelMeta,
|
|
509
|
+
previousModelMeta: this.previousModelMeta,
|
|
475
510
|
thinkingLevel: this.getThinkingLevel(),
|
|
476
511
|
rightStatus: vimStatus,
|
|
477
512
|
});
|
|
513
|
+
this.previousModelMeta = modelMeta;
|
|
514
|
+
return result;
|
|
478
515
|
}
|
|
479
516
|
|
|
480
517
|
invalidate(): void {
|