@hncode/hncode 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.
- package/README.md +18 -0
- package/README_CN.md +14 -0
- package/package.json +1 -1
- package/src/agent-task.js +354 -337
- package/src/agent.js +19 -3
- package/src/animate.js +35 -0
- package/src/config.js +25 -7
- package/src/file-tree.js +4 -3
- package/src/highlight.js +20 -6
- package/src/i18n.js +825 -0
- package/src/image-row.js +11 -2
- package/src/index.js +730 -610
- package/src/llm.js +146 -21
- package/src/log-file.js +112 -0
- package/src/markdown.js +619 -567
- package/src/migrate-index.js +175 -0
- package/src/migrate.js +392 -0
- package/src/panels.js +9 -7
- package/src/rows-plan-bg.js +3 -2
- package/src/rows-status.js +20 -6
- package/src/rows-tool-result.js +35 -8
- package/src/screen-paint.js +153 -128
- package/src/session-recover.js +317 -0
- package/src/session.js +203 -13
- package/src/swarm-progress.js +5 -1
- package/src/tasks-browser.js +9 -8
- package/src/team-panel.js +12 -11
- package/src/text.js +192 -149
- package/src/tool-line.js +7 -2
- package/src/tool-result.js +400 -327
- package/src/tools/ask-user-question.js +1 -2
- package/src/tools/bash.js +15 -9
- package/src/tools/edit.js +640 -665
- package/src/tools/goal.js +130 -93
- package/src/tools/read.js +141 -133
- package/src/tools/tasks.js +214 -214
- package/src/tools/utils.js +143 -104
- package/src/tui.js +20689 -19943
package/src/rows-status.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { C } from './colors.js';
|
|
7
7
|
import { col, visualCol, wrapWords } from './text.js';
|
|
8
|
+
import { uiText } from './i18n.js';
|
|
8
9
|
import { fmtTokens } from './format.js';
|
|
9
10
|
import { SPIN_PLACEHOLDER } from './animate.js';
|
|
10
11
|
|
|
@@ -32,15 +33,28 @@ export function compactionRows(msg, width, expanded, spin) {
|
|
|
32
33
|
const detail = (msg.tokensBefore != null && msg.tokensAfter != null)
|
|
33
34
|
? col(` (${fmtTokens(msg.tokensBefore)} → ${fmtTokens(msg.tokensAfter)} tokens)`, C.gray) : '';
|
|
34
35
|
const hint = (msg.text || '').trim()
|
|
35
|
-
? col(` (Ctrl-O to ${expanded ? 'hide' : 'show'} compaction summary)
|
|
36
|
-
head = bullet + col('Compaction complete', C.green + C.bold) + detail + hint;
|
|
36
|
+
? col(uiText(` (Ctrl-O to ${expanded ? 'hide' : 'show'} compaction summary)`), C.gray) : '';
|
|
37
|
+
head = bullet + col(uiText('Compaction complete'), C.green + C.bold) + detail + hint;
|
|
37
38
|
} else if (canceled) {
|
|
38
|
-
head = bullet + col('Compaction cancelled', C.yellow + C.bold)
|
|
39
|
+
head = bullet + col(uiText('Compaction cancelled'), C.yellow + C.bold)
|
|
39
40
|
+ (msg.reason ? col(' (' + msg.reason + ')', C.gray) : '');
|
|
40
41
|
} else {
|
|
41
|
-
head = bullet + col('Compacting context…', C.cyan + C.bold);
|
|
42
|
+
head = bullet + col(uiText('Compacting context…'), C.cyan + C.bold);
|
|
42
43
|
}
|
|
43
44
|
const out = [{ text: head, ind: '', raw: true }];
|
|
45
|
+
// WHERE THE EARLIER CONVERSATION WENT.
|
|
46
|
+
//
|
|
47
|
+
// Compaction drops the oldest messages from the model's history AND the oldest rows from the displayed transcript, so
|
|
48
|
+
// a long conversation visibly loses its top. The row above only reported token counts, which reads as "something was
|
|
49
|
+
// deleted". This says what actually happened: the history was summarised, it is still in the session file, and
|
|
50
|
+
// `/recap` reads it back.
|
|
51
|
+
if (done) {
|
|
52
|
+
const trimmed = Number(msg.trimmed) || 0;
|
|
53
|
+
const note = trimmed > 0
|
|
54
|
+
? uiText(`${trimmed} earlier message${trimmed === 1 ? '' : 's'} left the screen — summarised above, still in the session file (/recap to read it back)`)
|
|
55
|
+
: uiText('the full conversation is still in the session file (/recap to read it back)');
|
|
56
|
+
out.push({ text: INDENT + col(note, C.gray), ind: INDENT, raw: true });
|
|
57
|
+
}
|
|
44
58
|
if (msg.instruction) {
|
|
45
59
|
out.push({ text: INDENT + col(String(msg.instruction), C.gray), ind: INDENT, raw: true });
|
|
46
60
|
}
|
|
@@ -90,14 +104,14 @@ export function thinkingRows(msg, width, expanded) {
|
|
|
90
104
|
// The spinner frame is NOT baked in here: a glyph that changes every tick would invalidate this row's cache and
|
|
91
105
|
// re-wrap the whole reasoning block each time, which is what made long thinking look laggy. The caller substitutes
|
|
92
106
|
// the live frame outside the cache instead.
|
|
93
|
-
out.push({ text: SPIN_PLACEHOLDER + ' thinking…', ind: '', color: C.gray });
|
|
107
|
+
out.push({ text: SPIN_PLACEHOLDER + uiText(' thinking…'), ind: '', color: C.gray });
|
|
94
108
|
const vis = contentLines.length > PREVIEW ? contentLines.slice(-PREVIEW) : contentLines;
|
|
95
109
|
for (const l of vis) out.push({ text: it(l), ind: INDENT, color: C.gray });
|
|
96
110
|
} else {
|
|
97
111
|
const shown = contentLines.slice(0, PREVIEW);
|
|
98
112
|
shown.forEach((l, i) => out.push({ text: it(l), ind: i === 0 ? '● ' : INDENT, color: C.gray }));
|
|
99
113
|
if (contentLines.length > PREVIEW) {
|
|
100
|
-
out.push({ text: `… (${contentLines.length - PREVIEW} more lines, ctrl+o to expand)
|
|
114
|
+
out.push({ text: uiText(`… (${contentLines.length - PREVIEW} more lines, ctrl+o to expand)`), ind: INDENT, color: C.gray });
|
|
101
115
|
}
|
|
102
116
|
}
|
|
103
117
|
return out;
|
package/src/rows-tool-result.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { C } from './colors.js';
|
|
14
14
|
import { col, expandTabs, fitAnsi, sanitizeText, visualCol, wrapWords } from './text.js';
|
|
15
|
+
import { uiText } from './i18n.js';
|
|
15
16
|
import { langForPath } from './highlight.js';
|
|
16
17
|
import { paintCode } from './diff.js';
|
|
17
18
|
|
|
@@ -33,7 +34,13 @@ export function toolResultRows(msg, width, expanded) {
|
|
|
33
34
|
// stray blank line would render as a lone "↳ " with no content.
|
|
34
35
|
while (rawLines.length && rawLines[0].trim() === '') rawLines.shift();
|
|
35
36
|
while (rawLines.length && rawLines[rawLines.length - 1].trim() === '') rawLines.pop();
|
|
36
|
-
|
|
37
|
+
// COLLAPSED IS A GLANCE; EXPANDED IS A READ, NOT A DUMP.
|
|
38
|
+
//
|
|
39
|
+
// Expanded used to be `Infinity`, so Ctrl+O on a command that printed 3000 lines put all 3000 into the transcript: the
|
|
40
|
+
// conversation above it scrolled away, the scrollbar became meaningless, and every frame afterwards paid to lay out
|
|
41
|
+
// rows nobody would read. The cap here is what a person can actually scan; past that the output belongs in a file,
|
|
42
|
+
// which is what the hint says.
|
|
43
|
+
const MAX_RESULT_LINES = expanded ? 400 : 12;
|
|
37
44
|
// The exit-code line is bookkeeping for the AGENT and is NEVER shown to the user — success or failure. A failure is
|
|
38
45
|
// already legible from the RED result text below. `[error: …]` is kept: it carries the message, not just a code.
|
|
39
46
|
const visible = rawLines.filter((ln) => !/^\[exit code:/.test(ln.trim()));
|
|
@@ -49,7 +56,7 @@ export function toolResultRows(msg, width, expanded) {
|
|
|
49
56
|
if (hasDiff) {
|
|
50
57
|
// Same collapse rule as elsewhere: a short preview by default, everything once Ctrl+O expands. 16 rows (not 12)
|
|
51
58
|
// because a change renders as a PAIR: `- old` then `+ new`.
|
|
52
|
-
const MAX = expanded ?
|
|
59
|
+
const MAX = expanded ? 400 : 16;
|
|
53
60
|
// Show the unified diff WITH context rows (ctx = dim) so a change is not two orphaned blocks; `gap` rows mark where
|
|
54
61
|
// unchanged lines were elided.
|
|
55
62
|
const total = msg.diff.length;
|
|
@@ -104,7 +111,11 @@ export function toolResultRows(msg, width, expanded) {
|
|
|
104
111
|
}
|
|
105
112
|
if (total > emitted) {
|
|
106
113
|
diffRows.push({
|
|
107
|
-
|
|
114
|
+
// A DEAD-END Ctrl+O IS WORSE THAN NO HINT. Collapsed it expands; already expanded there is nothing left to
|
|
115
|
+
// reveal, so the line says how much was withheld instead of inviting a key that would do nothing.
|
|
116
|
+
text: col(expanded
|
|
117
|
+
? uiText(`… (${total - emitted} more lines not shown; press ctrl+e for the whole thing)`)
|
|
118
|
+
: uiText(`… (${total - emitted} more lines, ctrl+o to expand)`), C.gray),
|
|
108
119
|
ind: cont, raw: true,
|
|
109
120
|
});
|
|
110
121
|
}
|
|
@@ -168,18 +179,34 @@ export function toolResultRows(msg, width, expanded) {
|
|
|
168
179
|
const termSurface = msg.toolName === 'Bash' || msg.toolName === 'Shell';
|
|
169
180
|
wrapped.forEach((t, i) => {
|
|
170
181
|
if (termSurface) {
|
|
171
|
-
const surfaced = t.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
172
|
-
|
|
182
|
+
const surfaced = t.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}${color}`);
|
|
183
|
+
// A FOREGROUND IS NOT OPTIONAL HERE.
|
|
184
|
+
//
|
|
185
|
+
// This set only the background, so the text fell back to the terminal's own default colour. Against the very
|
|
186
|
+
// dark `termBg` that is readable on a light default and invisible on a dark one — which is exactly what a
|
|
187
|
+
// dark-background terminal showed: a solid dark block with no words in it.
|
|
188
|
+
//
|
|
189
|
+
// The `\x1b[0m` inside the row closes EVERYTHING, background included, so both have to be re-asserted after
|
|
190
|
+
// each one: the wash and the colour.
|
|
191
|
+
diffRows.push({ text: C.termBg + color + fitAnsi(surfaced, bodyW) + C.bgReset, ind: idx === 0 && i === 0 ? pre : cont, raw: true });
|
|
173
192
|
} else {
|
|
174
193
|
diffRows.push({ text: t, ind: idx === 0 && i === 0 ? pre : cont, color });
|
|
175
194
|
}
|
|
176
195
|
});
|
|
177
196
|
});
|
|
178
197
|
if (visible.length > MAX_RESULT_LINES) {
|
|
179
|
-
//
|
|
180
|
-
//
|
|
198
|
+
// THE HINT SAYS HOW TO SEE THE REST, and what "the rest" is depends on where we are.
|
|
199
|
+
//
|
|
200
|
+
// Collapsed: Ctrl+O expands — that is the whole point of the line.
|
|
201
|
+
// Already expanded: there is no more to reveal here, so inviting another Ctrl+O would be a dead end. Say how much
|
|
202
|
+
// was withheld and where it does live, which is the tool result the model was given (and, when the result was
|
|
203
|
+
// spilled, the file it was written to).
|
|
204
|
+
const rest = visible.length - MAX_RESULT_LINES;
|
|
205
|
+
const text = expanded
|
|
206
|
+
? uiText(`… ${rest} more line${rest === 1 ? '' : 's'} not shown; ctrl+o collapses, ctrl+e shows all of it`)
|
|
207
|
+
: uiText(`… ${rest} more lines, ctrl+o to expand`);
|
|
181
208
|
diffRows.push({
|
|
182
|
-
text
|
|
209
|
+
text,
|
|
183
210
|
ind: cont,
|
|
184
211
|
color: failed ? C.red : C.gray,
|
|
185
212
|
});
|
package/src/screen-paint.js
CHANGED
|
@@ -1,128 +1,153 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text and styled strings → a Screen.
|
|
3
|
-
*
|
|
4
|
-
* The frame composer produces rows of ANSI-decorated strings, because that is how every surface in this app was
|
|
5
|
-
* written. Rather than rewrite all of them at once, this module paints those rows into a cell grid: it parses
|
|
6
|
-
* the SGR runs, interns each style once, and writes the characters with their widths.
|
|
7
|
-
*
|
|
8
|
-
* The result is what the painter wants — a grid it can diff cell by cell, and in which a bitmap is a region
|
|
9
|
-
* with no characters in it rather than a row with bytes in it.
|
|
10
|
-
*/
|
|
11
|
-
import { charWidth, CELL_WIDTH } from './screen.js';
|
|
12
|
-
|
|
13
|
-
/** Matches an SGR sequence: `ESC [ params m`. */
|
|
14
|
-
const SGR = /\x1b\[([0-9;]*)m/g;
|
|
15
|
-
|
|
16
|
-
/** Matches any other escape sequence, which the painter does not place as text. */
|
|
17
|
-
const OTHER_ESCAPE = /\x1b(\[[0-9;?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[@-_])/g;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Split a line into runs of `{ text, styleId }`, interning each style.
|
|
21
|
-
*
|
|
22
|
-
* Styles are tracked as the CURRENT sgr string in effect, accumulated until a reset. Two runs that end up with
|
|
23
|
-
* the same accumulated string share an id, so a row of plain text costs one lookup.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} line
|
|
26
|
-
* @param {import('./screen.js').StylePool} stylePool
|
|
27
|
-
* @returns {Array<{text: string, styleId: number}>}
|
|
28
|
-
*/
|
|
29
|
-
export function styledRuns(line, stylePool) {
|
|
30
|
-
const runs = [];
|
|
31
|
-
let current = '';
|
|
32
|
-
let pos = 0;
|
|
33
|
-
SGR.lastIndex = 0;
|
|
34
|
-
|
|
35
|
-
const push = (text) => {
|
|
36
|
-
if (!text) return;
|
|
37
|
-
runs.push({ text, styleId: stylePool.intern(current) });
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
let m;
|
|
41
|
-
while ((m = SGR.exec(line))) {
|
|
42
|
-
push(line.slice(pos, m.index));
|
|
43
|
-
const params = m[1];
|
|
44
|
-
// `0` and an empty parameter both mean "reset everything".
|
|
45
|
-
if (params === '' || params === '0') current = '';
|
|
46
|
-
else current += `\x1b[${params}m`;
|
|
47
|
-
pos = m.index + m[0].length;
|
|
48
|
-
}
|
|
49
|
-
push(line.slice(pos));
|
|
50
|
-
return runs;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** Strip every escape sequence from a string, leaving what the terminal would draw as text. */
|
|
54
|
-
export function stripEscapes(line) {
|
|
55
|
-
return String(line)
|
|
56
|
-
.replace(SGR, '')
|
|
57
|
-
.replace(OTHER_ESCAPE, '')
|
|
58
|
-
.replace(/\x1b/g, '');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Terminal width of a string once its escapes are ignored. */
|
|
62
|
-
export function displayWidth(line) {
|
|
63
|
-
let w = 0;
|
|
64
|
-
for (const ch of stripEscapes(line)) {
|
|
65
|
-
const cw = charWidth(ch);
|
|
66
|
-
if (cw > 0) w += cw;
|
|
67
|
-
}
|
|
68
|
-
return w;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Paint rows of styled text into a screen.
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Text and styled strings → a Screen.
|
|
3
|
+
*
|
|
4
|
+
* The frame composer produces rows of ANSI-decorated strings, because that is how every surface in this app was
|
|
5
|
+
* written. Rather than rewrite all of them at once, this module paints those rows into a cell grid: it parses
|
|
6
|
+
* the SGR runs, interns each style once, and writes the characters with their widths.
|
|
7
|
+
*
|
|
8
|
+
* The result is what the painter wants — a grid it can diff cell by cell, and in which a bitmap is a region
|
|
9
|
+
* with no characters in it rather than a row with bytes in it.
|
|
10
|
+
*/
|
|
11
|
+
import { charWidth, CELL_WIDTH } from './screen.js';
|
|
12
|
+
|
|
13
|
+
/** Matches an SGR sequence: `ESC [ params m`. */
|
|
14
|
+
const SGR = /\x1b\[([0-9;]*)m/g;
|
|
15
|
+
|
|
16
|
+
/** Matches any other escape sequence, which the painter does not place as text. */
|
|
17
|
+
const OTHER_ESCAPE = /\x1b(\[[0-9;?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[@-_])/g;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Split a line into runs of `{ text, styleId }`, interning each style.
|
|
21
|
+
*
|
|
22
|
+
* Styles are tracked as the CURRENT sgr string in effect, accumulated until a reset. Two runs that end up with
|
|
23
|
+
* the same accumulated string share an id, so a row of plain text costs one lookup.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} line
|
|
26
|
+
* @param {import('./screen.js').StylePool} stylePool
|
|
27
|
+
* @returns {Array<{text: string, styleId: number}>}
|
|
28
|
+
*/
|
|
29
|
+
export function styledRuns(line, stylePool) {
|
|
30
|
+
const runs = [];
|
|
31
|
+
let current = '';
|
|
32
|
+
let pos = 0;
|
|
33
|
+
SGR.lastIndex = 0;
|
|
34
|
+
|
|
35
|
+
const push = (text) => {
|
|
36
|
+
if (!text) return;
|
|
37
|
+
runs.push({ text, styleId: stylePool.intern(current) });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
let m;
|
|
41
|
+
while ((m = SGR.exec(line))) {
|
|
42
|
+
push(line.slice(pos, m.index));
|
|
43
|
+
const params = m[1];
|
|
44
|
+
// `0` and an empty parameter both mean "reset everything".
|
|
45
|
+
if (params === '' || params === '0') current = '';
|
|
46
|
+
else current += `\x1b[${params}m`;
|
|
47
|
+
pos = m.index + m[0].length;
|
|
48
|
+
}
|
|
49
|
+
push(line.slice(pos));
|
|
50
|
+
return runs;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Strip every escape sequence from a string, leaving what the terminal would draw as text. */
|
|
54
|
+
export function stripEscapes(line) {
|
|
55
|
+
return String(line)
|
|
56
|
+
.replace(SGR, '')
|
|
57
|
+
.replace(OTHER_ESCAPE, '')
|
|
58
|
+
.replace(/\x1b/g, '');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Terminal width of a string once its escapes are ignored. */
|
|
62
|
+
export function displayWidth(line) {
|
|
63
|
+
let w = 0;
|
|
64
|
+
for (const ch of stripEscapes(line)) {
|
|
65
|
+
const cw = charWidth(ch);
|
|
66
|
+
if (cw > 0) w += cw;
|
|
67
|
+
}
|
|
68
|
+
return w;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Paint rows of styled text into a screen.
|
|
73
|
+
*
|
|
74
|
+
* NO INTERMEDIATE RUNS. This used to call `styledRuns`, which built a `{ text, styleId }` object per SGR run and
|
|
75
|
+
* sliced a fresh string for each one — a hundred-odd throwaway objects per frame for a 40-row screen, on top of the
|
|
76
|
+
* per-character `for…of` that allocates a one-character string per glyph.
|
|
77
|
+
*
|
|
78
|
+
* The loop below walks the escapes in place and copies each run straight into the cell grid, so the only allocation
|
|
79
|
+
* left is whatever `screen.set` interns. The painted cells are identical.
|
|
80
|
+
*
|
|
81
|
+
* @param {import('./screen.js').Screen} screen Destination, already the right size.
|
|
82
|
+
* @param {string[]} rows One string per row; extra rows are ignored, missing ones stay blank.
|
|
83
|
+
* @param {import('./screen.js').StylePool} stylePool
|
|
84
|
+
*/
|
|
85
|
+
export function paintRows(screen, rows, stylePool) {
|
|
86
|
+
screen._rowCount = rows.length;
|
|
87
|
+
const n = Math.min(rows.length, screen.height);
|
|
88
|
+
const width = screen.width;
|
|
89
|
+
// A style is interned only when it CHANGES, so a run of plain text costs one lookup for the whole row.
|
|
90
|
+
let curStyle = '';
|
|
91
|
+
let curStyleId = -1;
|
|
92
|
+
for (let y = 0; y < n; y++) {
|
|
93
|
+
const line = rows[y];
|
|
94
|
+
if (!line) continue;
|
|
95
|
+
let x = 0;
|
|
96
|
+
let pos = 0;
|
|
97
|
+
let internedForRun = false;
|
|
98
|
+
SGR.lastIndex = 0;
|
|
99
|
+
for (;;) {
|
|
100
|
+
const m = SGR.exec(line);
|
|
101
|
+
const end = m ? m.index : line.length;
|
|
102
|
+
if (end > pos && x < width) {
|
|
103
|
+
if (!internedForRun) { curStyleId = stylePool.intern(curStyle); internedForRun = true; }
|
|
104
|
+
for (let i = pos; i < end; i++) {
|
|
105
|
+
const ch = line[i];
|
|
106
|
+
const w = charWidth(ch);
|
|
107
|
+
if (w === 0) continue; // a combining mark has no column of its own
|
|
108
|
+
if (x + w > width) break;
|
|
109
|
+
screen.set(x, y, ch, curStyleId, w);
|
|
110
|
+
x += w;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!m) break;
|
|
114
|
+
const params = m[1];
|
|
115
|
+
if (params === '' || params === '0') curStyle = '';
|
|
116
|
+
else curStyle += `\x1b[${params}m`;
|
|
117
|
+
pos = m.index + m[0].length;
|
|
118
|
+
internedForRun = false;
|
|
119
|
+
}
|
|
120
|
+
screen._mark(0, y, width);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Turn a screen back into rows of ANSI strings, for the paths that still expect text.
|
|
126
|
+
*
|
|
127
|
+
* This is the inverse of `paintRows` and is meant for the web mirror and for plugins that read the frame's
|
|
128
|
+
* lines; the terminal itself is written from the cell diff, not from these strings.
|
|
129
|
+
*
|
|
130
|
+
* @param {import('./screen.js').Screen} screen
|
|
131
|
+
* @returns {string[]}
|
|
132
|
+
*/
|
|
133
|
+
export function screenToRows(screen) {
|
|
134
|
+
const rows = [];
|
|
135
|
+
for (let y = 0; y < screen.height; y++) {
|
|
136
|
+
let out = '';
|
|
137
|
+
let styleId = -1;
|
|
138
|
+
for (let x = 0; x < screen.width; x++) {
|
|
139
|
+
if (screen.isSpacer(x, y)) continue;
|
|
140
|
+
const cell = screen.at(x, y);
|
|
141
|
+
if (cell.styleId !== styleId) {
|
|
142
|
+
out += '\x1b[0m' + screen.stylePool.get(cell.styleId);
|
|
143
|
+
styleId = cell.styleId;
|
|
144
|
+
}
|
|
145
|
+
out += cell.ch;
|
|
146
|
+
}
|
|
147
|
+
if (styleId !== -1) out += '\x1b[0m';
|
|
148
|
+
rows.push(out);
|
|
149
|
+
}
|
|
150
|
+
return rows;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { CELL_WIDTH };
|