@heyhuynhgiabuu/pi-diff 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +19 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heyhuynhgiabuu/pi-diff",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Shiki-powered terminal diff renderer for pi — syntax-highlighted, word-level diffs in split and unified views.",
5
5
  "author": "huynhgiabuu",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -225,6 +225,10 @@ function autoDeriveBgFromTheme(theme: any): void {
225
225
  // Empty filler and context — match the base
226
226
  BG_EMPTY = BG_BASE;
227
227
 
228
+ // Update RST to re-apply base bg after every reset — prevents black
229
+ // flashes between styled segments when toolSuccessBg is non-black
230
+ RST = `\x1b[0m${BG_BASE}`;
231
+
228
232
  // Rebuild derived constants
229
233
  DIVIDER = `${FG_RULE}│${RST}`;
230
234
  } catch {
@@ -370,7 +374,7 @@ const MAX_WRAP_ROWS_NARROW = 1; // <120 cols (truncate, no wrap)
370
374
  // ANSI
371
375
  // ---------------------------------------------------------------------------
372
376
 
373
- const RST = "\x1b[0m";
377
+ let RST = "\x1b[0m";
374
378
  const BOLD = "\x1b[1m";
375
379
  const DIM = "\x1b[2m";
376
380
 
@@ -400,7 +404,7 @@ const BORDER_BAR = "▌";
400
404
  /** Generate a dense diagonal stripe fill for empty filler cells.
401
405
  * Solid ╱ characters — uniform direction like CSS diagonal hatching. */
402
406
  function stripes(w: number, _rowOffset: number): string {
403
- return FG_STRIPE + "╱".repeat(w) + RST;
407
+ return BG_BASE + FG_STRIPE + "╱".repeat(w) + RST;
404
408
  }
405
409
 
406
410
  let DIVIDER = `${FG_RULE}│${RST}`;
@@ -433,7 +437,10 @@ function resolveDiffColors(theme?: any): DiffColors {
433
437
  try {
434
438
  const bgAnsi = theme.getBgAnsi("toolSuccessBg");
435
439
  const parsed = parseAnsiRgb(bgAnsi);
436
- if (parsed) BG_BASE = bgAnsi;
440
+ if (parsed) {
441
+ BG_BASE = bgAnsi;
442
+ RST = `\x1b[0m${BG_BASE}`;
443
+ }
437
444
  } catch { /* ignore */ }
438
445
  }
439
446
 
@@ -665,7 +672,7 @@ function summarize(a: number, d: number): string {
665
672
  }
666
673
 
667
674
  function rule(w: number): string {
668
- return `${FG_RULE}${"─".repeat(w)}${RST}`;
675
+ return `${BG_BASE}${FG_RULE}${"─".repeat(w)}${RST}`;
669
676
  }
670
677
 
671
678
  /**
@@ -1002,7 +1009,7 @@ async function renderUnified(
1002
1009
  const pad = Math.max(0, totalW - label.length - 2);
1003
1010
  const half1 = Math.floor(pad / 2),
1004
1011
  half2 = pad - half1;
1005
- out.push(`${FG_DIM}${"─".repeat(half1)}${label}${"─".repeat(half2)}${RST}`);
1012
+ out.push(`${BG_BASE}${FG_DIM}${"─".repeat(half1)}${label}${"─".repeat(half2)}${RST}`);
1006
1013
  idx++;
1007
1014
  continue;
1008
1015
  }
@@ -1062,7 +1069,7 @@ async function renderUnified(
1062
1069
 
1063
1070
  out.push(rule(tw));
1064
1071
  if (diff.lines.length > vis.length) {
1065
- out.push(`${FG_DIM} … ${diff.lines.length - vis.length} more lines${RST}`);
1072
+ out.push(`${BG_BASE}${FG_DIM} … ${diff.lines.length - vis.length} more lines${RST}`);
1066
1073
  }
1067
1074
  return out.join("\n");
1068
1075
  }
@@ -1148,8 +1155,8 @@ async function renderSplit(
1148
1155
  if (line.type === "sep") {
1149
1156
  const gap = line.newNum;
1150
1157
  const label = gap && gap > 0 ? `··· ${gap} lines ···` : "···";
1151
- const g = ` ${FG_DIM}${fit("", nw + 2)}${RST}${FG_RULE}│${RST} `;
1152
- return { gutter: g, contGutter: g, bodyRows: [`${FG_DIM}${fit(label, cw)}${RST}`] };
1158
+ const g = `${BG_BASE} ${FG_DIM}${fit("", nw + 2)}${RST}${FG_RULE}│${RST} `;
1159
+ return { gutter: g, contGutter: g, bodyRows: [`${BG_BASE}${FG_DIM}${fit(label, cw)}${RST}`] };
1153
1160
  }
1154
1161
 
1155
1162
  const isDel = line.type === "del",
@@ -1182,9 +1189,9 @@ async function renderSplit(
1182
1189
 
1183
1190
  const out: string[] = [];
1184
1191
  // Column headers — "old" / "new" positioned above line numbers
1185
- const hdrOld = `${" ".repeat(Math.max(0, nw - 2))}${dc.fgDel}${DIM}old${RST}`;
1186
- const hdrNew = `${" ".repeat(Math.max(0, nw - 2))}${dc.fgAdd}${DIM}new${RST}`;
1187
- out.push(`${hdrOld}${" ".repeat(Math.max(0, half - nw - 1))}${FG_RULE}┊${RST}${hdrNew}`);
1192
+ const hdrOld = `${BG_BASE}${" ".repeat(Math.max(0, nw - 2))}${dc.fgDel}${DIM}old${RST}`;
1193
+ const hdrNew = `${BG_BASE}${" ".repeat(Math.max(0, nw - 2))}${dc.fgAdd}${DIM}new${RST}`;
1194
+ out.push(`${BG_BASE}${hdrOld}${" ".repeat(Math.max(0, half - nw - 1))}${FG_RULE}┊${RST}${hdrNew}`);
1188
1195
  out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
1189
1196
 
1190
1197
  for (const r of vis) {
@@ -1230,7 +1237,7 @@ async function renderSplit(
1230
1237
 
1231
1238
  out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
1232
1239
  if (rows.length > vis.length) {
1233
- out.push(`${FG_DIM} … ${rows.length - vis.length} more lines${RST}`);
1240
+ out.push(`${BG_BASE}${FG_DIM} … ${rows.length - vis.length} more lines${RST}`);
1234
1241
  }
1235
1242
  return out.join("\n");
1236
1243
  }