@xynogen/pix-pretty 3.2.0 → 3.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/renderers.ts CHANGED
@@ -2,7 +2,7 @@ import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works
2
2
  import { config } from "@xynogen/pix-runtime/config";
3
3
  import { prettySection } from "@xynogen/pix-runtime/sections";
4
4
 
5
- import { FG_DIM, FG_LNUM, FG_RULE, RST } from "./ansi.ts";
5
+ import { FG_DIM, FG_RULE, RST } from "./ansi.ts";
6
6
  import { MAX_PREVIEW_LINES } from "./config.ts";
7
7
  import { BODY_PAD, type ExpandHintCtx, expandHint, rule } from "./frame.ts";
8
8
  import { hlBlock } from "./highlight.ts";
@@ -10,7 +10,7 @@ import { dirIcon, fileColor, fileIcon } from "./icons.ts";
10
10
  import { lang } from "./lang.ts";
11
11
  import { type FadeTheme, fadeRowsOf, normalizeLineEndings, pluralize } from "./text.ts";
12
12
  import type { FgTheme } from "./types.ts";
13
- import { lineNumber, terminalWidth } from "./utils.ts";
13
+ import { gutterWidth, lineGutter, terminalWidth } from "./utils.ts";
14
14
 
15
15
  /** Layout controls for {@link renderFileContent}. */
16
16
  export interface RenderFileContentOptions {
@@ -49,7 +49,7 @@ export async function renderFileContent(
49
49
  const startLine = offset;
50
50
  const endLine = startLine + show.length - 1;
51
51
  const nw = Math.max(3, String(endLine).length);
52
- const gw = nw + 3; // num + " │ "
52
+ const gw = gutterWidth(nw);
53
53
  const cw = Math.max(1, tw - gw);
54
54
 
55
55
  const out: string[] = [];
@@ -62,15 +62,13 @@ export async function renderFileContent(
62
62
  // Expanded view: no tail is hidden. First row carries the line number,
63
63
  // continuation rows indent under the gutter so the code column aligns.
64
64
  const rows = wrapTextWithAnsi(code, cw);
65
- const pad = " ".repeat(nw);
66
65
  rows.forEach((rowText, r) => {
67
- const gutter = r === 0 ? lineNumber(ln, nw) : `${FG_LNUM}${pad}${RST}`;
68
- out.push(`${gutter} ${FG_RULE}│${RST} ${rowText}${RST}`);
66
+ out.push(`${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
69
67
  });
70
68
  continue;
71
69
  }
72
70
  const display = truncateToWidth(code, cw, `${FG_DIM}›`);
73
- out.push(`${lineNumber(ln, nw)} ${FG_RULE}│${RST} ${display}${RST}`);
71
+ out.push(`${lineGutter(ln, nw)}${display}${RST}`);
74
72
  }
75
73
 
76
74
  out.push(rule(tw));
package/src/utils.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isAbsolute, relative, resolve } from "node:path";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { getCapabilities, hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
4
- import { ANSI_CAPTURE_RE, BG_BASE, FG_LNUM, RST } from "./ansi.ts";
4
+ import { ANSI_CAPTURE_RE, BG_BASE, FG_LNUM, FG_RULE, RST } from "./ansi.ts";
5
5
  import { MAX_PREVIEW_LINES } from "./config.ts";
6
6
  import type { TextComponentCtor, TextComponentLike } from "./types.ts";
7
7
 
@@ -290,3 +290,14 @@ export function lineNumber(n: number, w: number): string {
290
290
  const v = String(n);
291
291
  return `${FG_LNUM}${" ".repeat(Math.max(0, w - v.length))}${v}${RST}`;
292
292
  }
293
+
294
+ /** Columns taken by a numbered gutter: the number, a space, the rule, a space. */
295
+ export function gutterWidth(numberWidth: number): number {
296
+ return numberWidth + 3;
297
+ }
298
+
299
+ /** One gutter cell in front of a code row; pass "" to blank a continuation row. */
300
+ export function lineGutter(n: number | "", numberWidth: number): string {
301
+ const cell = n === "" ? `${FG_LNUM}${" ".repeat(numberWidth)}${RST}` : lineNumber(n, numberWidth);
302
+ return `${cell} ${FG_RULE}│${RST} `;
303
+ }