@north-light/crouter 0.3.202 → 0.3.204

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.
@@ -24,10 +24,14 @@ export declare function rowCells(line: string): number;
24
24
  /** Plain text of cells `[from, to)` — every escape, link boundary, and cursor
25
25
  * marker dropped, exactly what a terminal copies out of that span. */
26
26
  export declare function sliceCells(line: string, from: number, to: number): string;
27
- /** The SGR pair `styleCells` asserts over a span. */
27
+ /** The SGR pair `styleCells` asserts over a span. A style that paints color
28
+ * sets `restore`, because its `off` cannot un-set one color without also
29
+ * discarding whatever color the row had underneath it — with `restore`, the
30
+ * span closes by resetting and replaying the SGRs the row had already asserted. */
28
31
  export type CellStyle = {
29
32
  on: string;
30
33
  off: string;
34
+ restore?: boolean;
31
35
  };
32
36
  export declare const INVERSE_STYLE: CellStyle;
33
37
  /** Style cells `[from, to)`, re-asserting `style.on` after any SGR inside the
@@ -89,19 +89,30 @@ export function styleCells(line, from, to, maxCells, style = INVERSE_STYLE) {
89
89
  return line;
90
90
  let out = '';
91
91
  let inside = false;
92
+ // The SGRs in force at the current point, so a color span can hand the row
93
+ // back exactly as it found it. A full reset clears the list.
94
+ const active = [];
92
95
  const open = () => { if (!inside) {
93
96
  out += style.on;
94
97
  inside = true;
95
98
  } };
96
- const close = () => { if (inside) {
97
- out += style.off;
99
+ const close = () => {
100
+ if (!inside)
101
+ return;
102
+ out += style.restore === true ? `\x1b[0m${active.join('')}` : style.off;
98
103
  inside = false;
99
- } };
104
+ };
100
105
  const cells = walkRow(line, {
101
106
  onEscape: (escape) => {
102
107
  out += escape;
108
+ if (!escape.endsWith('m'))
109
+ return;
110
+ if (escape === '\x1b[0m' || escape === '\x1b[m')
111
+ active.length = 0;
112
+ else
113
+ active.push(escape);
103
114
  // An SGR inside the span may have reset every attribute, including ours.
104
- if (inside && escape.endsWith('m'))
115
+ if (inside)
105
116
  out += style.on;
106
117
  },
107
118
  onGlyph: (glyph) => {
@@ -116,7 +127,7 @@ export function styleCells(line, from, to, maxCells, style = INVERSE_STYLE) {
116
127
  if (cells < end) {
117
128
  const gap = Math.max(0, from - cells);
118
129
  const styled = end - Math.max(from, cells);
119
- out += ' '.repeat(gap) + style.on + ' '.repeat(styled) + style.off;
130
+ out += ' '.repeat(gap) + style.on + ' '.repeat(styled) + (style.restore === true ? '\x1b[0m' : style.off);
120
131
  }
121
132
  return out;
122
133
  }
@@ -10,12 +10,11 @@
10
10
  // what the viewport needs to scroll to one and what `highlightCells` needs to
11
11
  // paint one.
12
12
  import { styleCells, walkRow } from '../ansi-cells.js';
13
- /** Every hit is reverse-video; the one you are standing on is also underlined,
14
- * so a screen with several hits still says which of them `n` will leave.
15
- * Closing a span restores nothing, so the extra attribute is underline rather
16
- * than bold: transcript text runs bold often and underlined almost never. */
17
- const HIT_STYLE = { on: '\x1b[7m', off: '\x1b[27m' };
18
- const SELECTED_HIT_STYLE = { on: '\x1b[7m\x1b[4m', off: '\x1b[24m\x1b[27m' };
13
+ /** Hits are painted as backgrounds with black text, the way an editor marks
14
+ * find results: white for every hit, amber for the one you are standing on, so
15
+ * a screen full of hits still says which of them `n` will leave. */
16
+ const HIT_STYLE = { on: '\x1b[107m\x1b[30m', off: '', restore: true };
17
+ const SELECTED_HIT_STYLE = { on: '\x1b[48;5;214m\x1b[30m', off: '', restore: true };
19
18
  function plainRow(line) {
20
19
  let text = '';
21
20
  const cells = [];