@xynogen/pix-display 0.1.5 → 0.1.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/package.json +1 -1
- package/src/paste-chips.ts +19 -44
- package/src/thinking.ts +4 -7
package/package.json
CHANGED
package/src/paste-chips.ts
CHANGED
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
* The display rewrite is purely visual (render layer); buffer is untouched.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import type {
|
|
17
|
-
ExtensionAPI,
|
|
18
|
-
KeybindingsManager,
|
|
19
|
-
} from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import type { ExtensionAPI, KeybindingsManager } from "@earendil-works/pi-coding-agent";
|
|
20
17
|
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
21
18
|
import type { EditorTheme, TUI } from "@earendil-works/pi-tui";
|
|
22
19
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
@@ -97,10 +94,7 @@ type ExpandPasteHandler = { expandPasteMarkers(text: string): string };
|
|
|
97
94
|
|
|
98
95
|
// Mirror of the base Editor's paste-marker grammar, per-id at expand time.
|
|
99
96
|
function markerReFor(pasteId: number): RegExp {
|
|
100
|
-
return new RegExp(
|
|
101
|
-
`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`,
|
|
102
|
-
"g",
|
|
103
|
-
);
|
|
97
|
+
return new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
|
|
104
98
|
}
|
|
105
99
|
|
|
106
100
|
/**
|
|
@@ -109,10 +103,7 @@ function markerReFor(pasteId: number): RegExp {
|
|
|
109
103
|
* boundary per blob (text and image alike) so adjacent pastes can't merge
|
|
110
104
|
* into one indistinguishable wall in the model-facing text.
|
|
111
105
|
*/
|
|
112
|
-
export function expandPasteMarkers(
|
|
113
|
-
text: string,
|
|
114
|
-
pastes: Map<number, string>,
|
|
115
|
-
): string {
|
|
106
|
+
export function expandPasteMarkers(text: string, pastes: Map<number, string>): string {
|
|
116
107
|
let result = text;
|
|
117
108
|
for (const [pasteId, pasteContent] of pastes) {
|
|
118
109
|
result = result.replace(
|
|
@@ -162,35 +153,22 @@ export function restyleMarkers(line: string, imageIds: Set<number>): string {
|
|
|
162
153
|
// Strip cursor inversion codes the TUI embeds when the cursor
|
|
163
154
|
// intersects a marker — plain MARKER_RE handles the rest.
|
|
164
155
|
const clean = line.includes("\x1b") ? line.replace(CURSOR_RE, "") : line;
|
|
165
|
-
return clean.replace(
|
|
166
|
-
|
|
167
|
-
(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
icon("paste.text"),
|
|
179
|
-
"text",
|
|
180
|
-
`${compactNumber(charsStr)} chars`,
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
return chip(FG_GREEN, icon("paste.text"), "text", `#${id}`);
|
|
184
|
-
},
|
|
185
|
-
);
|
|
156
|
+
return clean.replace(MARKER_RE, (_full, idStr, _g2, _g3, linesStr, charsStr) => {
|
|
157
|
+
const id = Number.parseInt(idStr, 10);
|
|
158
|
+
if (imageIds.has(id)) {
|
|
159
|
+
return chip(FG_BLUE, icon("paste.image"), "image", `#${id}`);
|
|
160
|
+
}
|
|
161
|
+
if (linesStr) {
|
|
162
|
+
return chip(FG_GREEN, icon("paste.text"), "text", `${linesStr} lines`);
|
|
163
|
+
}
|
|
164
|
+
if (charsStr) {
|
|
165
|
+
return chip(FG_GREEN, icon("paste.text"), "text", `${compactNumber(charsStr)} chars`);
|
|
166
|
+
}
|
|
167
|
+
return chip(FG_GREEN, icon("paste.text"), "text", `#${id}`);
|
|
168
|
+
});
|
|
186
169
|
}
|
|
187
170
|
|
|
188
|
-
function chip(
|
|
189
|
-
color: string,
|
|
190
|
-
icon: string,
|
|
191
|
-
label: string,
|
|
192
|
-
meta: string,
|
|
193
|
-
): string {
|
|
171
|
+
function chip(color: string, icon: string, label: string, meta: string): string {
|
|
194
172
|
return `${color}${BOLD}${icon} ${label}${RST}${FG_DIM} ${meta}${RST}`;
|
|
195
173
|
}
|
|
196
174
|
|
|
@@ -228,9 +206,7 @@ class ChipEditor extends CustomEditor {
|
|
|
228
206
|
const replaced = replaceImagePaths(text, internals, this.imageIds);
|
|
229
207
|
// Append a trailing space when the insertion ends with a paste marker so
|
|
230
208
|
// the cursor lands after the chip rather than inside it.
|
|
231
|
-
super.insertTextAtCursor(
|
|
232
|
-
endsWithMarker(replaced) ? `${replaced} ` : replaced,
|
|
233
|
-
);
|
|
209
|
+
super.insertTextAtCursor(endsWithMarker(replaced) ? `${replaced} ` : replaced);
|
|
234
210
|
}
|
|
235
211
|
|
|
236
212
|
/**
|
|
@@ -243,8 +219,7 @@ class ChipEditor extends CustomEditor {
|
|
|
243
219
|
private patchExpandPasteMarkers(): void {
|
|
244
220
|
const internals = this as unknown as ExpandInternals;
|
|
245
221
|
const self = this as unknown as ExpandPasteHandler;
|
|
246
|
-
self.expandPasteMarkers = (text: string): string =>
|
|
247
|
-
expandPasteMarkers(text, internals.pastes);
|
|
222
|
+
self.expandPasteMarkers = (text: string): string => expandPasteMarkers(text, internals.pastes);
|
|
248
223
|
}
|
|
249
224
|
|
|
250
225
|
private patchHandlePaste(): void {
|
package/src/thinking.ts
CHANGED
|
@@ -71,7 +71,7 @@ const PARTIAL_TAIL_RE = /<\/?([a-zA-Z]*)$/;
|
|
|
71
71
|
function stripPartialTailTag(text: string): string {
|
|
72
72
|
const match = text.match(PARTIAL_TAIL_RE);
|
|
73
73
|
if (!match) return text;
|
|
74
|
-
const fragment = match[1].toLowerCase();
|
|
74
|
+
const fragment = (match[1] ?? "").toLowerCase();
|
|
75
75
|
if (TAG_NAMES.some((tag) => tag.startsWith(fragment))) {
|
|
76
76
|
return text.slice(0, match.index);
|
|
77
77
|
}
|
|
@@ -120,7 +120,7 @@ function splitThinking(text: string): Block[] {
|
|
|
120
120
|
let match = CLOSED_BLOCK_RE.exec(rest);
|
|
121
121
|
while (match) {
|
|
122
122
|
pushText(blocks, rest.slice(0, match.index));
|
|
123
|
-
pushThinking(blocks, match[2]);
|
|
123
|
+
pushThinking(blocks, match[2] ?? "");
|
|
124
124
|
rest = rest.slice(match.index + match[0].length);
|
|
125
125
|
CLOSED_BLOCK_RE.lastIndex = 0;
|
|
126
126
|
match = CLOSED_BLOCK_RE.exec(rest);
|
|
@@ -131,11 +131,8 @@ function splitThinking(text: string): Block[] {
|
|
|
131
131
|
const openMatch = OPEN_TAIL_RE.exec(rest);
|
|
132
132
|
if (openMatch) {
|
|
133
133
|
// Leading text may still carry orphan tags (e.g. a stray `</think>`).
|
|
134
|
-
pushText(
|
|
135
|
-
|
|
136
|
-
openMatch.input.slice(0, openMatch.index).replace(ORPHAN_TAG_RE, ""),
|
|
137
|
-
);
|
|
138
|
-
pushThinking(blocks, openMatch[2].replace(ORPHAN_TAG_RE, ""));
|
|
134
|
+
pushText(blocks, openMatch.input.slice(0, openMatch.index).replace(ORPHAN_TAG_RE, ""));
|
|
135
|
+
pushThinking(blocks, (openMatch[2] ?? "").replace(ORPHAN_TAG_RE, ""));
|
|
139
136
|
} else {
|
|
140
137
|
// Strip any orphan tags from the trailing text.
|
|
141
138
|
pushText(blocks, rest.replace(ORPHAN_TAG_RE, ""));
|