@aiwayds/dsh-tui-pi 0.8.1 → 0.8.2

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.
@@ -2,12 +2,22 @@
2
2
  * Terminal write-stream decorator painting the canvas via BCE.
3
3
  *
4
4
  * pi-tui renders rows as `\x1b[{row};1H\x1b[2K{line}` and full redraws as
5
- * `\x1b[2J` — no background of their own. Terminals with BCE (back color
6
- * erase) fill erased regions with the current SGR background, so prefixing
7
- * the canvas background before every erase sequence paints the whole screen
8
- * without touching pi-tui. Rows the diff renderer skips keep the background
9
- * of their last paint, which is correct until the canvas color changes —
10
- * the caller must then force a full redraw (requestRender(true)).
5
+ * `\x1b[2J` — no background of their own. Two injections make the whole
6
+ * screen carry the theme canvas color without touching pi-tui:
7
+ *
8
+ * 1. Before every erase sequence (`\x1b[2K`/`\x1b[2J`): terminals with BCE
9
+ * (back color erase) fill the erased region with the current SGR
10
+ * background, painting row tails the erase never reaches.
11
+ * 2. After every background-clearing SGR reset (`\x1b[0m`, `\x1b[m`,
12
+ * `\x1b[0;…m`, `\x1b[49m`): content following a reset would otherwise
13
+ * print with the terminal default background, punching holes into the
14
+ * canvas (invisible with a dark theme on a dark terminal, glaring after
15
+ * a switch to light). Re-injecting restores the canvas so every printed
16
+ * cell keeps it; spans that set their own background still override it.
17
+ *
18
+ * Rows the diff renderer skips keep the background of their last paint,
19
+ * which is correct until the canvas color changes — the caller must then
20
+ * force a full redraw (requestRender(true)).
11
21
  */
12
22
  import type { Terminal } from '@earendil-works/pi-tui';
13
23
  export declare class CanvasTerminal implements Terminal {
@@ -2,15 +2,38 @@
2
2
  * Terminal write-stream decorator painting the canvas via BCE.
3
3
  *
4
4
  * pi-tui renders rows as `\x1b[{row};1H\x1b[2K{line}` and full redraws as
5
- * `\x1b[2J` — no background of their own. Terminals with BCE (back color
6
- * erase) fill erased regions with the current SGR background, so prefixing
7
- * the canvas background before every erase sequence paints the whole screen
8
- * without touching pi-tui. Rows the diff renderer skips keep the background
9
- * of their last paint, which is correct until the canvas color changes —
10
- * the caller must then force a full redraw (requestRender(true)).
5
+ * `\x1b[2J` — no background of their own. Two injections make the whole
6
+ * screen carry the theme canvas color without touching pi-tui:
7
+ *
8
+ * 1. Before every erase sequence (`\x1b[2K`/`\x1b[2J`): terminals with BCE
9
+ * (back color erase) fill the erased region with the current SGR
10
+ * background, painting row tails the erase never reaches.
11
+ * 2. After every background-clearing SGR reset (`\x1b[0m`, `\x1b[m`,
12
+ * `\x1b[0;…m`, `\x1b[49m`): content following a reset would otherwise
13
+ * print with the terminal default background, punching holes into the
14
+ * canvas (invisible with a dark theme on a dark terminal, glaring after
15
+ * a switch to light). Re-injecting restores the canvas so every printed
16
+ * cell keeps it; spans that set their own background still override it.
17
+ *
18
+ * Rows the diff renderer skips keep the background of their last paint,
19
+ * which is correct until the canvas color changes — the caller must then
20
+ * force a full redraw (requestRender(true)).
11
21
  */
12
22
  const ENTER_ALT_SCREEN = '\x1b[?1049h';
13
23
  const EXIT_ALT_SCREEN = '\x1b[?1049l';
24
+ const SGR = /\x1b\[([0-9;]*)m/g;
25
+ /**
26
+ * Whether an SGR sequence clears the background: the full reset forms
27
+ * (`\x1b[0m`, `\x1b[m`, `\x1b[0;…m` combined resets) and the explicit
28
+ * background-default (`\x1b[49m`). Color-set sequences whose parameter list
29
+ * merely contains a 0 channel (`\x1b[38;5;0m`, `\x1b[48;2;0;121;107m`) do
30
+ * NOT clear — treating them as resets paints over intentional surfaces.
31
+ */
32
+ function clearsBackground(params) {
33
+ if (params === '' || params === '49')
34
+ return true;
35
+ return params.split(';', 1)[0] === '0';
36
+ }
14
37
  export class CanvasTerminal {
15
38
  /** '' = transparent passthrough (DSH_TUI_TRANSPARENT). */
16
39
  background = '';
@@ -39,11 +62,14 @@ export class CanvasTerminal {
39
62
  this.inner.write(data);
40
63
  return;
41
64
  }
42
- // Injection happens only at erase-sequence boundaries; kitty image
43
- // payloads are APC base64/hex and never contain ESC bytes.
65
+ // Injection happens only at erase-sequence boundaries and after
66
+ // background-clearing resets; kitty image payloads are APC base64/hex
67
+ // and never contain ESC bytes.
68
+ const bg = this.background;
44
69
  this.inner.write(data
45
- .replaceAll('\x1b[2K', `${this.background}\x1b[2K`)
46
- .replaceAll('\x1b[2J', `${this.background}\x1b[2J`));
70
+ .replaceAll('\x1b[2K', `${bg}\x1b[2K`)
71
+ .replaceAll('\x1b[2J', `${bg}\x1b[2J`)
72
+ .replace(SGR, (seq, params) => (clearsBackground(params) ? seq + bg : seq)));
47
73
  }
48
74
  start(onInput, onResize) {
49
75
  this.inner.start(onInput, onResize);
@@ -1 +1 @@
1
- {"version":3,"file":"canvas-terminal.js","sourceRoot":"","sources":["../src/canvas-terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,MAAM,gBAAgB,GAAG,aAAa,CAAA;AACtC,MAAM,eAAe,GAAG,aAAa,CAAA;AAErC,MAAM,OAAO,cAAc;IACzB,0DAA0D;IAClD,UAAU,GAAG,EAAE,CAAA;IACvB,oHAAoH;IAC5G,MAAM,GAAG,IAAI,CAAA;IACJ,KAAK,CAAU;IAEhC,YAAY,KAAe;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,uEAAuE;IACvE,mBAAmB,CAAC,EAAsB;QACxC,IAAI,CAAC,UAAU,GAAG,EAAE,IAAI,EAAE,CAAA;IAC5B,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACnC,sEAAsE;YACtE,sEAAsE;YACtE,kCAAkC;YAClC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;YACnB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACtB,OAAM;QACR,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;YAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAA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CAAC,KAAK,CAAC,OAAO,CAAA;IAC3B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACxB,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAA;IACvC,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IAED,UAAU;QACR,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;IACzB,CAAC;IAED,UAAU;QACR,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAA;IACzB,CAAC;IAED,SAAS;QACP,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAA;IACxB,CAAC;IAED,eAAe;QACb,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAA;IAC9B,CAAC;IAED,WAAW;QACT,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAA;IAC1B,CAAC;IAED,QAAQ,CAAC,KAAa;QACpB,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC5B,CAAC;IAED,WAAW,CAAC,MAAe;QACzB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiwayds/dsh-tui-pi",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "pi-style terminal UI for DeepSeek Harness (dsh) — pi-tui look & feel, dsh slash commands, GitHub light/dark themes, powerline footer",
5
5
  "repository": {
6
6
  "type": "git",