@hheei/pi-ext-ui 0.4.0 → 0.4.1

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/dist/diff-view.js CHANGED
@@ -153,9 +153,12 @@ export class DiffView {
153
153
  if (!this.#parsed.ok)
154
154
  rows.push(this.#theme.fg("warning", `! ${this.#parsed.diagnostic}`));
155
155
  for (const raw of (this.#rawText ?? "").split(/\r?\n/)) {
156
- rows.push(this.#theme.fg("dim", raw));
156
+ const wrapped = wrapTextWithAnsi(raw, width);
157
+ for (const line of wrapped.length > 0 ? wrapped : [""]) {
158
+ rows.push(this.#theme.fg("dim", line));
159
+ }
157
160
  }
158
- return rows.map((row) => truncateToWidth(row, width, "…"));
161
+ return rows;
159
162
  }
160
163
  #renderDiff(width, hunks) {
161
164
  const numberCol = numberWidth(hunks);
@@ -1,4 +1,4 @@
1
- import { truncateToWidth, } from "@earendil-works/pi-tui";
1
+ import { truncateToWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
2
2
  import { toContentRows, toSingleRow } from "./tool-view.js";
3
3
  /**
4
4
  * A transcript notice, not a tool execution.
@@ -38,7 +38,14 @@ function layRows(source, width) {
38
38
  const raw = isComponent(source)
39
39
  ? source.render(inner).flatMap((line) => toContentRows(line))
40
40
  : (typeof source === "string" ? [source] : source).flatMap((line) => toContentRows(line));
41
- return raw.map((line) => truncate(` ${line}`, width));
41
+ const rows = [];
42
+ for (const line of raw) {
43
+ const wrapped = wrapTextWithAnsi(line, inner);
44
+ for (const chunk of wrapped.length > 0 ? wrapped : [""]) {
45
+ rows.push(truncate(` ${chunk}`, width));
46
+ }
47
+ }
48
+ return rows;
42
49
  }
43
50
  function invalidateRows(source) {
44
51
  if (source !== undefined && isComponent(source))
@@ -1,5 +1,5 @@
1
1
  import { copyToClipboard as copyToSystemClipboard, getLanguageFromPath, highlightCode, } from "@earendil-works/pi-coding-agent";
2
- import { stripTerminalSequences, truncateToWidth, visibleWidth, } from "@earendil-works/pi-tui";
2
+ import { stripTerminalSequences, truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
3
3
  import { inlinePresentation } from "./renderer.js";
4
4
  import { formatToolHeaderText, ToolView, toContentRows, transitionFoldLevel, } from "./tool-view.js";
5
5
  function truncate(text, width) {
@@ -268,15 +268,20 @@ export class NestedCallsView {
268
268
  copyRegion: { startX: width - copySlotWidth - 1, endX: width },
269
269
  };
270
270
  if (isExpanded) {
271
- const bodyLines = this.#renderChildBody(call, Math.max(1, width - 2), expansionLevel);
271
+ const childWidth = Math.max(1, width - 2);
272
+ const bodyLines = this.#renderChildBody(call, childWidth, expansionLevel);
272
273
  for (const rawLine of bodyLines) {
273
274
  for (const bodyLine of toContentRows(rawLine)) {
274
- const bodyLineIdx = lines.length;
275
- lines.push(truncate(` ${bodyLine}`, width));
276
- this.#lineMapping[bodyLineIdx] = {
277
- callIndex: i,
278
- isHeader: false,
279
- };
275
+ const wrapped = wrapTextWithAnsi(bodyLine, childWidth);
276
+ const chunks = wrapped.length > 0 ? wrapped : [""];
277
+ for (const chunk of chunks) {
278
+ const bodyLineIdx = lines.length;
279
+ lines.push(truncate(` ${chunk}`, width));
280
+ this.#lineMapping[bodyLineIdx] = {
281
+ callIndex: i,
282
+ isHeader: false,
283
+ };
284
+ }
280
285
  }
281
286
  }
282
287
  }
package/dist/tool-view.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Buffer } from "node:buffer";
2
2
  import { copyToClipboard as copyToSystemClipboard, } from "@earendil-works/pi-coding-agent";
3
- import { truncateToWidth, visibleWidth, } from "@earendil-works/pi-tui";
3
+ import { truncateToWidth, visibleWidth, wrapTextWithAnsi, } from "@earendil-works/pi-tui";
4
4
  export function isCollapsible(value) {
5
5
  return (typeof value === "object" &&
6
6
  value !== null &&
@@ -384,10 +384,27 @@ export class ToolView {
384
384
  const rail = noRail ? "" : `${theme.fg(section.railToken, "▎")} `;
385
385
  const { rows: rawLines, isByteTruncated, totalBytes, } = resolveRows(section.content, innerWidth, toContentRows);
386
386
  const cap = level === 1 ? (section.maxLines ?? DEFAULT_MAX_SECTION_LINES) : MAX_LEVEL2_SECTION_LINES;
387
- const visibleLines = Number.isFinite(cap) && rawLines.length > cap ? rawLines.slice(0, cap) : rawLines;
388
- const omittedCount = rawLines.length - visibleLines.length;
389
- for (const line of visibleLines) {
390
- output.push(truncate(rail + line, safeWidth));
387
+ const sectionRows = [];
388
+ let logicalLinesCount = 0;
389
+ for (const line of rawLines) {
390
+ const wrapped = wrapTextWithAnsi(line, innerWidth);
391
+ const chunks = wrapped.length > 0 ? wrapped : [""];
392
+ if (Number.isFinite(cap) && sectionRows.length + chunks.length > cap) {
393
+ const canTake = Math.max(0, cap - sectionRows.length);
394
+ for (let i = 0; i < canTake; i++) {
395
+ const chunk = chunks[i];
396
+ if (chunk !== undefined) {
397
+ sectionRows.push(chunk);
398
+ }
399
+ }
400
+ break;
401
+ }
402
+ sectionRows.push(...chunks);
403
+ logicalLinesCount++;
404
+ }
405
+ const omittedCount = rawLines.length - logicalLinesCount;
406
+ for (const row of sectionRows) {
407
+ output.push(truncate(rail + row, safeWidth));
391
408
  }
392
409
  if (omittedCount > 0 || isByteTruncated) {
393
410
  const hint = isByteTruncated
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hheei/pi-ext-ui",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Collapsible tool rendering frame and tool renderer pilot for Pi.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",