@hncode/hncode 0.7.5 → 0.7.6
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 +1 -1
- package/src/colors.js +29 -0
- package/src/tui.js +147 -80
package/package.json
CHANGED
package/src/colors.js
CHANGED
|
@@ -267,6 +267,13 @@ export const C = {
|
|
|
267
267
|
// is rgb(48,48,48) = #303030 — clearly lifted off a near-black terminal without
|
|
268
268
|
// washing the text out. Truecolor gets `#2e2e2e`, the same shade written exactly.
|
|
269
269
|
bgPanel: TRUECOLOR ? '\x1b[48;2;46;46;46m' : '\x1b[48;5;236m',
|
|
270
|
+
// The code-surface background, set by setTheme from the theme's own page colour. A placeholder until then, so
|
|
271
|
+
// code drawn before the first setTheme still has a surface.
|
|
272
|
+
codeBg: TRUECOLOR ? '\x1b[48;2;12;20;26m' : '\x1b[48;5;233m',
|
|
273
|
+
// The terminal-surface background, set by setTheme from the theme's page colour. Placeholder until then.
|
|
274
|
+
termBg: TRUECOLOR ? '\x1b[48;2;0;14;21m' : '\x1b[48;5;234m',
|
|
275
|
+
// The composer's neutral-grey surface. Placeholder until setTheme runs.
|
|
276
|
+
composerBg: TRUECOLOR ? '\x1b[48;2;44;44;46m' : '\x1b[48;5;237m',
|
|
270
277
|
border: BORDER,
|
|
271
278
|
red: '\x1b[91m',
|
|
272
279
|
green: '\x1b[92m',
|
|
@@ -471,6 +478,28 @@ export function setTheme(name) {
|
|
|
471
478
|
C.diffAddFg = rgb(...mix(green, t.fg, 0.55));
|
|
472
479
|
C.diffDelFg = rgb(...mix(red, t.fg, 0.55));
|
|
473
480
|
|
|
481
|
+
// THE CODE-SURFACE BACKGROUND, one step off the page. Read rows, Write previews and diff CONTEXT lines sit on
|
|
482
|
+
// it; diff `+`/`-` rows keep their green/red wash on top. Mixed from this theme's own page colour rather than
|
|
483
|
+
// a fixed grey, so a light theme gets a light code surface and a dark one a dark one.
|
|
484
|
+
//
|
|
485
|
+
// The step depends on WHICH SIDE the page is. On a dark page the surface is one step LIGHTER (mix very little
|
|
486
|
+
// foreground in); on a light page it is one step DARKER (mix a little foreground in). Same small distance either
|
|
487
|
+
// way, because a code region must read as "same screen, slightly recessed", not as a panel.
|
|
488
|
+
C.codeBg = brgb(...mix(t.bg, t.fg, isLight ? 0.93 : 0.94));
|
|
489
|
+
// THE TERMINAL-SURFACE BACKGROUND: the same small step on the OTHER side of the page, so the ordering holds on
|
|
490
|
+
// both kinds of theme — page < terminal < code on a dark one, terminal < code < page on a light one. Bash output
|
|
491
|
+
// and the shell-mode echo sit on it: a command reads as "a terminal ran this" without becoming a black band,
|
|
492
|
+
// which is what a deeper well looked like — a hole in the screen rather than a region of it.
|
|
493
|
+
//
|
|
494
|
+
// Towards BLACK on a dark theme and towards the foreground on a light one: mixing a dark page further towards its
|
|
495
|
+
// own foreground would make it lighter, which is `codeBg`'s job, not this one.
|
|
496
|
+
C.termBg = brgb(...mix(t.bg, isLight ? t.fg : [0, 0, 0], isLight ? 0.88 : 0.94));
|
|
497
|
+
// THE COMPOSER SURFACE: a NEUTRAL GREY, not a tint of the page. The input area is the one region that should not
|
|
498
|
+
// follow the theme's hue — a cyan-tinted box on a dark-teal page reads as "more page", while a grey one reads as
|
|
499
|
+
// an input field. Neutral means equal RGB, so it is written as a grey and adjusted only for light vs dark. A
|
|
500
|
+
// theme may override it with its own `composer` triple.
|
|
501
|
+
C.composerBg = brgb(...(t.composer || (isLight ? [232, 232, 232] : [44, 44, 46])));
|
|
502
|
+
|
|
474
503
|
// A comment: the palette's foreground, pulled most of the way towards its background so it reads as quiet. A dark
|
|
475
504
|
// page can afford a looser mix; a light one cannot — solar's foreground is already a muted blue-grey, and at the
|
|
476
505
|
// dark theme's ratio its comments came within 8 of the removal wash.
|
package/src/tui.js
CHANGED
|
@@ -2758,11 +2758,17 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2758
2758
|
const MAX_RUN_LINES = expanded ? Infinity : 8;
|
|
2759
2759
|
const shown = rawLines.slice(-MAX_RUN_LINES); // running: show the newest output
|
|
2760
2760
|
if (rawLines.length > MAX_RUN_LINES) {
|
|
2761
|
-
|
|
2761
|
+
const more = col(`… ${rawLines.length - MAX_RUN_LINES} earlier line(s)`, C.gray);
|
|
2762
|
+
out.push({ text: C.termBg + fitAnsi(more.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`), bodyW) + C.bgReset, ind: indent, raw: true });
|
|
2762
2763
|
}
|
|
2764
|
+
// THE TERMINAL SURFACE APPLIES WHILE IT RUNS TOO, not only once the result lands. The row is the same thing
|
|
2765
|
+
// before and after — a command's output — so switching its background on completion made the block jump as
|
|
2766
|
+
// the call finished.
|
|
2763
2767
|
for (const ln of shown) {
|
|
2764
2768
|
for (const t of (ln === '' ? [''] : wrapWords(ln, bodyW))) {
|
|
2765
|
-
|
|
2769
|
+
const painted = col(t, C.gray);
|
|
2770
|
+
const surfaced = painted.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
2771
|
+
out.push({ text: C.termBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: indent, raw: true });
|
|
2766
2772
|
}
|
|
2767
2773
|
}
|
|
2768
2774
|
}
|
|
@@ -2824,13 +2830,15 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2824
2830
|
// and letting it through at full width made the terminal wrap it itself — which pushes every later row down
|
|
2825
2831
|
// by one and desynchronises the frame, so the screen scrolled while the file was still arriving.
|
|
2826
2832
|
const room = Math.max(1, width - visualCol(indent) - num.length - 1);
|
|
2833
|
+
// The whole preview sits on the CODE SURFACE, number included, so the block reads as one recessed field.
|
|
2827
2834
|
if (!writeLang) {
|
|
2828
|
-
out.push({ text: col(`${num} ${fitAnsi(ln, room)}
|
|
2835
|
+
out.push({ text: C.codeBg + col(`${num} ${fitAnsi(ln, room)}`.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`), C.gray) + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2829
2836
|
return;
|
|
2830
2837
|
}
|
|
2831
2838
|
const painted = paintCode(ln, writeLang, '', writeInComment);
|
|
2832
2839
|
writeInComment = painted.inComment;
|
|
2833
|
-
|
|
2840
|
+
const writeRow = (col(num + ' ', C.gray) + fitAnsi(painted.text, room)).replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
2841
|
+
out.push({ text: C.codeBg + writeRow + C.bgReset, ind: i === 0 ? '↳ ' : indent, raw: true });
|
|
2834
2842
|
});
|
|
2835
2843
|
const shown = Math.min(lines.length, MAX);
|
|
2836
2844
|
if (totalLines > shown) out.push({ text: col(`… ${totalLines - shown} more lines, ctrl+o to expand`, C.gray), ind: indent, raw: true });
|
|
@@ -2933,6 +2941,11 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2933
2941
|
// recolouring the transcript, resetting styles mid-row, moving the cursor or
|
|
2934
2942
|
// clearing the screen over the composer.
|
|
2935
2943
|
const rawLines = sanitizeText(msg.text).replace(/\r\n/g, '\n').split('\n');
|
|
2944
|
+
// A TAB counts as ZERO columns in our width maths but advances to the next tab stop in a real terminal.
|
|
2945
|
+
// A row containing one was therefore padded short and the terminal kept the old frame's glyphs in the gap —
|
|
2946
|
+
// the "residue" under tool output. Read rows are the exception: their first tab is the line-number separator
|
|
2947
|
+
// and is handled in the Read branch below, where the CONTENT half is expanded too.
|
|
2948
|
+
if (!msg.readPath) for (let k = 0; k < rawLines.length; k++) rawLines[k] = expandTabs(rawLines[k]);
|
|
2936
2949
|
// Trim blank lines at BOTH ends: commands typically emit a trailing
|
|
2937
2950
|
// newline, and some tools emit a leading one. A stray blank line would
|
|
2938
2951
|
// render as a lone "↳ " with no content.
|
|
@@ -2995,10 +3008,12 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
2995
3008
|
|
|
2996
3009
|
if (!lineBg) {
|
|
2997
3010
|
// CONTEXT LINES ARE CODE TOO. They are the most of a diff and the part a reader scans to place the
|
|
2998
|
-
// change, so they get the same highlighter
|
|
3011
|
+
// the change, so they get the same highlighter, on the CODE SURFACE rather than the raw page — a changed
|
|
3012
|
+
// block sits on one recessed field. The +/- rows around it keep their green/red wash.
|
|
2999
3013
|
const ctxPainted = paintCode(text, d.lang, '', inComment);
|
|
3000
3014
|
inComment = ctxPainted.inComment;
|
|
3001
|
-
|
|
3015
|
+
const ctxRow = (lead + ctxPainted.text).replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
3016
|
+
diffRows.push({ text: C.codeBg + fitAnsi(ctxRow, bodyW) + C.bgReset, ind: cont, raw: true });
|
|
3002
3017
|
emitted++;
|
|
3003
3018
|
continue;
|
|
3004
3019
|
}
|
|
@@ -3047,22 +3062,46 @@ function messageLines(msg, width, workspace, expanded, spin, pulseStart, rawMode
|
|
|
3047
3062
|
const numbered = readLang && !isErr ? /^(\d+)\t([\s\S]*)$/.exec(ln) : null;
|
|
3048
3063
|
if (numbered) {
|
|
3049
3064
|
// `wrapAnsiWords` measures VISIBLE columns, so the colour codes do not count towards the wrap.
|
|
3050
|
-
|
|
3065
|
+
// THE FILE'S OWN INDENTATION IS OFTEN TABS. Left as tabs, `visualCol` counted them as zero columns
|
|
3066
|
+
// while the terminal advanced to the next stop: the row was padded short and the previous frame's
|
|
3067
|
+
// glyphs stayed visible behind it. Expand before measuring, but keep the first tab as the separator
|
|
3068
|
+
// — the regex above already split on it.
|
|
3069
|
+
const painted = paintCode(expandTabs(numbered[2]), readLang, '', inComment);
|
|
3051
3070
|
inComment = painted.inComment;
|
|
3052
3071
|
// THE SEPARATOR IS A TAB, AND `visualCol` COUNTS A TAB AS ZERO COLUMNS. A terminal advances it to the
|
|
3053
3072
|
// next stop, so the row was measured several columns short, the terminal wrapped it itself, and the tail
|
|
3054
3073
|
// landed on the next row as a fragment — `921d` under a `920`-numbered row is exactly that. A fixed
|
|
3055
3074
|
// two-space gap is what the width maths needs and what reads better.
|
|
3056
3075
|
const text = `${numbered[1]} ${painted.text}`;
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3076
|
+
// A Read row is TRUNCATED, not wrapped. `wrapAnsiWords` used to fold an overlong line onto a second
|
|
3077
|
+
// row, and that second row — padded to full width by the frame, without a line number — was exactly
|
|
3078
|
+
// what a differential painter could not reconcile with the previous frame: the leftover glyphs stayed
|
|
3079
|
+
// under it as residue. One source line is one display row.
|
|
3080
|
+
//
|
|
3081
|
+
// THE CODE SURFACE: the whole row sits on `codeBg`, one step off the page. The number keeps its grey,
|
|
3082
|
+
// the content keeps its syntax colours, and the wash reaches the right edge. Diff `+`/`-` rows are
|
|
3083
|
+
// NOT affected — they keep their green/red.
|
|
3084
|
+
//
|
|
3085
|
+
// The background has to survive the row's own resets: every syntax token closes with `ESC[0m`, and the
|
|
3086
|
+
// padding `fitAnsi` adds sits AFTER the last one. Re-asserting after each reset — the same trick
|
|
3087
|
+
// `paintCode` uses for a diff wash — keeps the surface on the padding too, so the block reads solid.
|
|
3088
|
+
const surfaced = text.replace(/\x1b\[0m/g, `\x1b[0m${C.codeBg}`);
|
|
3089
|
+
diffRows.push({ text: C.codeBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: idx === 0 ? pre : cont, raw: true });
|
|
3061
3090
|
return;
|
|
3062
3091
|
}
|
|
3063
3092
|
const wrapped = ln === '' ? [''] : wrapWords(ln, bodyW);
|
|
3093
|
+
// BASH OUTPUT SITS ON THE TERMINAL SURFACE, like text inside a real terminal emulator: the darkest recess
|
|
3094
|
+
// on screen. Other tools keep the plain page background, so a command's output reads as "a terminal ran
|
|
3095
|
+
// this" rather than as an ordinary result. The row keeps its grey text and the surface survives its own
|
|
3096
|
+
// resets the same way the code surface does.
|
|
3097
|
+
const termSurface = msg.toolName === 'Bash' || msg.toolName === 'Shell';
|
|
3064
3098
|
wrapped.forEach((t, i) => {
|
|
3065
|
-
|
|
3099
|
+
if (termSurface) {
|
|
3100
|
+
const surfaced = t.replace(/\x1b\[0m/g, `\x1b[0m${C.termBg}`);
|
|
3101
|
+
diffRows.push({ text: C.termBg + fitAnsi(surfaced, bodyW) + C.bgReset, ind: idx === 0 && i === 0 ? pre : cont, raw: true });
|
|
3102
|
+
} else {
|
|
3103
|
+
diffRows.push({ text: t, ind: idx === 0 && i === 0 ? pre : cont, color });
|
|
3104
|
+
}
|
|
3066
3105
|
});
|
|
3067
3106
|
});
|
|
3068
3107
|
if (visible.length > MAX_RESULT_LINES) {
|
|
@@ -4289,16 +4328,22 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4289
4328
|
msgLen.set(mem.msgLen.subarray(0, reuse), 0);
|
|
4290
4329
|
sigs.set(prevSigs.subarray(0, reuse), 0);
|
|
4291
4330
|
cursor = rowStart[reuse - 1] + msgLen[reuse - 1];
|
|
4292
|
-
prevBordered = chat[reuse - 1].role === '
|
|
4293
|
-
|| chat[reuse - 1].role === 'bash';
|
|
4331
|
+
prevBordered = chat[reuse - 1].role === 'queued';
|
|
4294
4332
|
}
|
|
4295
4333
|
for (let mi = reuse; mi < n; mi++) {
|
|
4296
4334
|
const m = chat[mi];
|
|
4297
|
-
|
|
4335
|
+
// ONLY `queued` IS DRAWN INSIDE A FRAME. A user message and a shell echo are a filled surface with no walls, so
|
|
4336
|
+
// their text uses the full inner width — leaving them in `border` narrowed it by two columns and this pass's row
|
|
4337
|
+
// count drifted from what the layout actually paints.
|
|
4338
|
+
const border = m.role === 'queued';
|
|
4298
4339
|
const ww = border ? Math.max(1, Math.min(1, innerW - 4)) : innerW; // placeholder
|
|
4299
4340
|
void ww;
|
|
4300
4341
|
rowStart[mi] = cursor;
|
|
4301
|
-
|
|
4342
|
+
// THE RULES BELONG TO THE FRAME, and only `queued` still draws one: a user message and a shell echo are a
|
|
4343
|
+
// filled surface now. Counting two rules for them made this pass's row count disagree with what the layout
|
|
4344
|
+
// actually paints, which is what `chatRowTotal` compares against.
|
|
4345
|
+
const drawsFrame = m.role === 'queued';
|
|
4346
|
+
const rules = drawsFrame ? (prevBordered ? 1 : 2) : 0;
|
|
4302
4347
|
sigs[mi] = messageSignature(m);
|
|
4303
4348
|
// Reuse/minimal layout for the row count: same width/border arithmetic as
|
|
4304
4349
|
// the layout path below. We need boxText for bordered messages.
|
|
@@ -4372,7 +4417,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4372
4417
|
if (!hasFence && !valid && !cached && !animating && m._count && m._count.key === countKey && m._count.textLen === countLen) {
|
|
4373
4418
|
msgLen[mi] = m._count.len + rules;
|
|
4374
4419
|
cursor += msgLen[mi];
|
|
4375
|
-
|
|
4420
|
+
prevBordered = drawsFrame;
|
|
4376
4421
|
continue;
|
|
4377
4422
|
}
|
|
4378
4423
|
if (valid) {
|
|
@@ -4441,7 +4486,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4441
4486
|
m._cache = null;
|
|
4442
4487
|
}
|
|
4443
4488
|
cursor += msgLen[mi];
|
|
4444
|
-
prevBordered =
|
|
4489
|
+
prevBordered = drawsFrame;
|
|
4445
4490
|
}
|
|
4446
4491
|
}
|
|
4447
4492
|
const total = cursor;
|
|
@@ -4538,11 +4583,14 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4538
4583
|
boxText = Math.max(1, boxInner - boxPad * 2);
|
|
4539
4584
|
}
|
|
4540
4585
|
// Shared wall with the previous bordered message (its bottom rule is ours).
|
|
4586
|
+
//
|
|
4587
|
+
// A USER MESSAGE AND A SHELL ECHO NO LONGER DRAW A FRAME, so they have no wall to share. Leaving them in made the
|
|
4588
|
+
// second of two adjacent rows skip its filled surface and fall through to the frame branch — the shell echo
|
|
4589
|
+
// came out with walls and no background. Only `queued` still draws a box.
|
|
4541
4590
|
let shared = false;
|
|
4542
4591
|
if (bordered && mi > 0) {
|
|
4543
4592
|
const prev = chat[mi - 1];
|
|
4544
|
-
shared =
|
|
4545
|
-
&& rowStart[mi - 1] + msgLen[mi - 1] === cursor;
|
|
4593
|
+
shared = prev.role === 'queued' && rowStart[mi - 1] + msgLen[mi - 1] === cursor;
|
|
4546
4594
|
}
|
|
4547
4595
|
const len = msgLen[mi];
|
|
4548
4596
|
// A message that may contain a bitmap is always built, visible or not: a row COUNT cannot represent a
|
|
@@ -4572,8 +4620,20 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4572
4620
|
}
|
|
4573
4621
|
const spinRows = ccc.spinRows;
|
|
4574
4622
|
const liveAt = (r, i) => (spinRows && spinRows.has(i) ? r.split(SPIN_PLACEHOLDER).join(spinFrame) : r);
|
|
4575
|
-
|
|
4576
|
-
if (bordered)
|
|
4623
|
+
const asSurface = msg.role === 'user' || msg.role === 'bash';
|
|
4624
|
+
if (bordered && !shared && !asSurface) out.push(rule(true, boxColor));
|
|
4625
|
+
// A USER MESSAGE IS DRAWN AS A FILLED SURFACE, the same one the composer uses: what was typed and what is
|
|
4626
|
+
// being typed read as one kind of thing. The frame is gone for the same reason it left the composer — a box
|
|
4627
|
+
// competes with the transcript and spends rows on chrome. A shell echo keeps its terminal surface instead.
|
|
4628
|
+
const surfaceFor = msg.role === 'bash' ? C.termBg : (msg.role === 'user' ? C.composerBg : '');
|
|
4629
|
+
if (bordered && surfaceFor && !shared) {
|
|
4630
|
+
for (let i = 0; i < ccc.rows.length; i++) {
|
|
4631
|
+
const rowText = liveAt(ccc.rows[i], i);
|
|
4632
|
+
if (isImageRow(rowText)) { out.push(rowText); continue; }
|
|
4633
|
+
const surfaced = rowText.replace(/\x1b\[0m/g, `\x1b[0m${surfaceFor}`);
|
|
4634
|
+
out.push(PAD + surfaceFor + fitAnsi(surfaced, innerW) + C.bgReset);
|
|
4635
|
+
}
|
|
4636
|
+
} else if (bordered) {
|
|
4577
4637
|
const pad = ' '.repeat(boxPad);
|
|
4578
4638
|
const wall = col('│', boxColor);
|
|
4579
4639
|
for (let i = 0; i < ccc.rows.length; i++) {
|
|
@@ -4592,7 +4652,7 @@ export function renderChatLines(state, w, viewport) {
|
|
|
4592
4652
|
out.push(isImageRow(rowText) ? rowText : PAD + rowText);
|
|
4593
4653
|
}
|
|
4594
4654
|
}
|
|
4595
|
-
if (bordered) out.push(rule(false, boxColor));
|
|
4655
|
+
if (bordered && !asSurface) out.push(rule(false, boxColor));
|
|
4596
4656
|
} else {
|
|
4597
4657
|
for (let i = 0; i < len; i++) out.push('');
|
|
4598
4658
|
}
|
|
@@ -5049,7 +5109,7 @@ function justify(left, right, w) {
|
|
|
5049
5109
|
// Height of the composer box (top border + content rows + bottom border).
|
|
5050
5110
|
export function composerHeight(state, cols) {
|
|
5051
5111
|
const insideW = Math.max(0, (cols | 0) - 2);
|
|
5052
|
-
return composerLayout(state, insideW
|
|
5112
|
+
return composerLayout(state, insideW).rows.length;
|
|
5053
5113
|
}
|
|
5054
5114
|
|
|
5055
5115
|
// UNCLAMPED height of the AskUserQuestion box. `composeFrame` caps the real
|
|
@@ -6036,7 +6096,11 @@ export function composeFrame(state, cols, rows) {
|
|
|
6036
6096
|
const takeover = state.editor || state.panel || null;
|
|
6037
6097
|
|
|
6038
6098
|
// ---- geometry ----
|
|
6039
|
-
const composer = composerLayout(state, insideW
|
|
6099
|
+
const composer = composerLayout(state, insideW);
|
|
6100
|
+
// ONE ROW PER INPUT ROW. It used to be `rows.length + 2` for the top and bottom rules; the composer is now a
|
|
6101
|
+
// filled surface with no frame, so reserving those two rows would leave a gap above and below it.
|
|
6102
|
+
// One row per input row, PLUS the separator rule above the composer.
|
|
6103
|
+
// One row per input row, PLUS a rule above and below the composer.
|
|
6040
6104
|
const composerBoxH = takeover ? 0 : composer.rows.length + 2;
|
|
6041
6105
|
const menuItems = (state.menuOpen && state.menuList.length && !takeover)
|
|
6042
6106
|
? Math.min(state.menuList.length, MAX_MENU) + 1
|
|
@@ -7364,33 +7428,30 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7364
7428
|
|
|
7365
7429
|
let composerFirstRow = -1;
|
|
7366
7430
|
if (!takeover) {
|
|
7367
|
-
|
|
7368
|
-
//
|
|
7369
|
-
//
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
//
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
//
|
|
7378
|
-
|
|
7379
|
-
|
|
7431
|
+
// A SEPARATOR BETWEEN THE TRANSCRIPT AND THE INPUT. With the border gone, the last line of the conversation sat
|
|
7432
|
+
// directly on top of the composer, and a paragraph against a grey block reads as one crowded mass. One faint
|
|
7433
|
+
// rule says "the conversation ends here" without drawing a frame.
|
|
7434
|
+
lines.push(col('─'.repeat(w), C.border));
|
|
7435
|
+
composerFirstRow = lines.length;
|
|
7436
|
+
// THE COMPOSER SPANS THE FULL WIDTH. It used to keep the transcript's 1-column left margin so its walls
|
|
7437
|
+
// lined up with a sent user message's box; with no walls there is nothing to line up, and a filled surface
|
|
7438
|
+
// that stops one column short of an edge reads as a damaged block rather than as an input field.
|
|
7439
|
+
const CPAD = '';
|
|
7440
|
+
const cInner = Math.max(1, insideW + 2); // the full terminal width: insideW is w - 2
|
|
7441
|
+
// NO BORDER: the composer is a BLOCK OF BACKGROUND, one row per input row. A box drawn in characters competes
|
|
7442
|
+
// with the transcript's own boxes (a sent user message is boxed too) and spends rows on chrome; a filled
|
|
7443
|
+
// surface says the same thing — "this is the input, and it is this wide" — without drawing a frame.
|
|
7380
7444
|
for (let ri = 0; ri < composer.rows.length; ri++) {
|
|
7381
|
-
addHit(lines.length,
|
|
7382
|
-
// Colour the prompt glyph like the transcript's user marker
|
|
7383
|
-
//
|
|
7384
|
-
// continuation rows are padded with spaces instead).
|
|
7445
|
+
addHit(lines.length, 0, cInner, { kind: 'composerRow', rowIdx: ri });
|
|
7446
|
+
// Colour the prompt glyph like the transcript's user marker and keep the typed TEXT white. The prefix is the
|
|
7447
|
+
// first `> ` of the row (the continuation rows are padded with spaces instead).
|
|
7385
7448
|
const rawRow = composer.rows[ri];
|
|
7386
|
-
// Which chip the pointer is over, if any. `state.pasteHover` is the paste NUMBER, set by the
|
|
7387
|
-
//
|
|
7388
|
-
//
|
|
7449
|
+
// Which chip the pointer is over, if any. `state.pasteHover` is the paste NUMBER, set by the mousehover
|
|
7450
|
+
// handler from the same index maths the expand gesture uses, so the highlight and the click can never
|
|
7451
|
+
// disagree about which chip they mean.
|
|
7389
7452
|
const styledRow = highlightPasteMarkers(rawRow, state.pasteHover);
|
|
7390
|
-
// One space of padding after the left wall (and before the right wall), the
|
|
7391
|
-
// same as the transcript's user/queue boxes, so the geometry is identical.
|
|
7392
7453
|
const pre = composerInput(state).prefix;
|
|
7393
|
-
const textW = Math.max(1, cInner - 2);
|
|
7454
|
+
const textW = Math.max(1, cInner - 2);
|
|
7394
7455
|
// Apply composer text selection highlight if a selection is active.
|
|
7395
7456
|
const sel = state.composerSel;
|
|
7396
7457
|
const rowMeta = composer.meta[ri] || {};
|
|
@@ -7401,18 +7462,16 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7401
7462
|
const highlighted = (sel && sel.anchor !== sel.head)
|
|
7402
7463
|
? highlightSelection(textPart, textStart, sel.anchor, sel.head)
|
|
7403
7464
|
: textPart;
|
|
7404
|
-
// The `!` (shell mode) prefix is BOLD: it is a mode marker, not punctuation,
|
|
7405
|
-
//
|
|
7465
|
+
// The `!` (shell mode) prefix is BOLD: it is a mode marker, not punctuation, and it should out-weigh
|
|
7466
|
+
// the `>` prompt glyph at a glance.
|
|
7406
7467
|
const preCol = state.inputMode === 'bash' ? (C.shellMode + C.bold) : C.cyan;
|
|
7407
|
-
rowAnsi = ' ' + col(pre, preCol) + C.white
|
|
7408
|
-
fitAnsi(highlighted, Math.max(1, textW - visualCol(pre))) + ' ';
|
|
7468
|
+
rowAnsi = ' ' + col(pre, preCol) + C.white
|
|
7469
|
+
+ fitAnsi(highlighted, Math.max(1, textW - visualCol(pre))) + ' ';
|
|
7409
7470
|
} else {
|
|
7410
7471
|
// THE INDENT IS NOT TEXT. A continuation row arrives as `cont + text` — two spaces standing in for
|
|
7411
7472
|
// `> ` — and `rowMeta.start` is the offset of the TEXT, not of the row. Handing the whole row to
|
|
7412
7473
|
// `highlightSelection` therefore shifted the selection by the prefix's width: the two blank columns lit
|
|
7413
7474
|
// up and the highlight ran two characters early, which is the offset seen on every wrapped line.
|
|
7414
|
-
//
|
|
7415
|
-
// The first-row branch above already strips its prefix; this one has to strip the continuation's.
|
|
7416
7475
|
const contWidth = rowMeta.preWidth != null ? rowMeta.preWidth : visualCol(pre);
|
|
7417
7476
|
const indent = styledRow.slice(0, contWidth);
|
|
7418
7477
|
const textPart = styledRow.slice(contWidth);
|
|
@@ -7422,13 +7481,15 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7422
7481
|
: textPart;
|
|
7423
7482
|
rowAnsi = ' ' + indent + C.white + fitAnsi(highlighted, Math.max(1, textW - contWidth)) + ' ';
|
|
7424
7483
|
}
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
);
|
|
7484
|
+
// THE SURFACE SURVIVES THE ROW'S OWN RESETS: every colour span closes with \x1b[0m, so the background is
|
|
7485
|
+
// re-asserted after each one — the same trick the code and terminal surfaces use.
|
|
7486
|
+
const surfaced = rowAnsi.replace(/\x1b\[0m/g, `\x1b[0m${C.composerBg}`);
|
|
7487
|
+
lines.push(C.composerBg + fitAnsi(surfaced, insideW + 2) + C.bgReset);
|
|
7428
7488
|
}
|
|
7429
|
-
|
|
7489
|
+
// AND THE RULE UNDER IT, mirroring the one above: the input is bounded by two faint rules, so it reads as a
|
|
7490
|
+
// field between the conversation and the status line rather than as a block touching both.
|
|
7491
|
+
lines.push(col('─'.repeat(w), C.border));
|
|
7430
7492
|
}
|
|
7431
|
-
|
|
7432
7493
|
|
|
7433
7494
|
const MPAD = ' ';
|
|
7434
7495
|
const mInner = Math.max(1, insideW - 3);
|
|
@@ -7759,10 +7820,12 @@ const queueH = takeover ? 0 : queuePanelHeight(state);
|
|
|
7759
7820
|
// The confirm prompt is NOT a term here: it shares the tip row, which is already inside
|
|
7760
7821
|
// STATUS_H, so counting it made the caret jump up a line every time Ctrl+C was pressed.
|
|
7761
7822
|
const bottomChrome = STATUS_H + CTX_H + menuH + mentionH;
|
|
7823
|
+
// `- 2`: the two rules that bound the composer. The input's last row sits above the lower rule, which sits above
|
|
7824
|
+
// the status line.
|
|
7762
7825
|
const caretScreenRow = h - bottomChrome - 2 - (composer.rows.length - 1 - composer.caretRow);
|
|
7763
7826
|
cursor = {
|
|
7764
7827
|
row: Math.max(0, Math.min(caretScreenRow, h - 1)),
|
|
7765
|
-
col: Math.min(composer.caretCol
|
|
7828
|
+
col: Math.min(Math.max(0, composer.caretCol), w - 1),
|
|
7766
7829
|
};
|
|
7767
7830
|
cursorVisible = true;
|
|
7768
7831
|
}
|
|
@@ -8960,6 +9023,23 @@ function ensureMenuVisible(state) {
|
|
|
8960
9023
|
}
|
|
8961
9024
|
|
|
8962
9025
|
// ---- command dispatch ----
|
|
9026
|
+
/**
|
|
9027
|
+
* Fire a TUI-side hook and FORGET it. These are notifications, not decisions: a slow or failing hook must not
|
|
9028
|
+
* hold up a permission prompt, a directory move or a settings save. The config is loaded fresh so an edit made
|
|
9029
|
+
* while the session was running is picked up without a restart.
|
|
9030
|
+
*
|
|
9031
|
+
* MODULE-LEVEL ON PURPOSE. `runTurn` and `dispatch` are both module-level functions, and the onEvent callbacks
|
|
9032
|
+
* in runTurn reach this helper too. A version scoped inside either one is invisible to the other, and the bare
|
|
9033
|
+
* name then throws a ReferenceError right after a tool result has arrived — which used to kill the process.
|
|
9034
|
+
*/
|
|
9035
|
+
function fireHook(event, payload, ws) {
|
|
9036
|
+
try {
|
|
9037
|
+
const { hooks } = loadHooks(ws);
|
|
9038
|
+
if (!(hooks[event] || []).length) return;
|
|
9039
|
+
void runShellHooks({ hooks }, event, payload, ws).catch(() => {});
|
|
9040
|
+
} catch { /* a broken hook config is a reason to carry on, not to fail the command */ }
|
|
9041
|
+
}
|
|
9042
|
+
|
|
8963
9043
|
export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdout, renderFrameArg) {
|
|
8964
9044
|
const { addChat, openPicker, openForm, notice, sendPrompt, quit, saveSession, openEditor } = h;
|
|
8965
9045
|
|
|
@@ -9026,19 +9106,6 @@ export async function dispatch(cmdRaw, arg, state, cfg, session, h, submit, stdo
|
|
|
9026
9106
|
* Every surface lands here — `/set`, the /settings browser, and the web's setConfig — so
|
|
9027
9107
|
* they cannot disagree about what a value means or which keys exist.
|
|
9028
9108
|
*/
|
|
9029
|
-
/**
|
|
9030
|
-
* Fire a TUI-side hook and FORGET it. These are notifications, not decisions: a slow or failing hook must not
|
|
9031
|
-
* hold up a permission prompt, a directory move or a settings save. The config is loaded fresh so an edit made
|
|
9032
|
-
* while the session was running is picked up without a restart.
|
|
9033
|
-
*/
|
|
9034
|
-
function fireHook(event, payload, ws) {
|
|
9035
|
-
try {
|
|
9036
|
-
const { hooks } = loadHooks(ws);
|
|
9037
|
-
if (!(hooks[event] || []).length) return;
|
|
9038
|
-
void runShellHooks({ hooks }, event, payload, ws).catch(() => {});
|
|
9039
|
-
} catch { /* a broken hook config is a reason to carry on, not to fail the command */ }
|
|
9040
|
-
}
|
|
9041
|
-
|
|
9042
9109
|
function applySetting(key, value) {
|
|
9043
9110
|
const def = SETTING_BY_KEY.get(key);
|
|
9044
9111
|
if (!def) { appErr(`Unknown setting: ${key}. Try /settings.`); return false; }
|
|
@@ -18303,7 +18370,7 @@ export async function startTUI(opts) {
|
|
|
18303
18370
|
case 'composerRow': {
|
|
18304
18371
|
const { cols } = dims();
|
|
18305
18372
|
const insideW = Math.max(0, cols - 2);
|
|
18306
|
-
const layout = composerLayout(state, insideW
|
|
18373
|
+
const layout = composerLayout(state, insideW);
|
|
18307
18374
|
const t = state._lastMouse;
|
|
18308
18375
|
const clickCol = t ? (t.col || 1) - 1 : 1;
|
|
18309
18376
|
// The column is measured from the row's PREFIX, because `composerTextIndexAt`
|
|
@@ -18673,7 +18740,7 @@ export async function startTUI(opts) {
|
|
|
18673
18740
|
if (hb && hb.kind === 'composerRow') {
|
|
18674
18741
|
const { cols } = dims();
|
|
18675
18742
|
const insideW = Math.max(0, cols - 2);
|
|
18676
|
-
const layout = composerLayout(state, insideW
|
|
18743
|
+
const layout = composerLayout(state, insideW);
|
|
18677
18744
|
const clickCol = Math.max(0, (t.col || 1) - 1 - 3);
|
|
18678
18745
|
pasteHover = pasteMarkerIdAt(state.input || '', composerTextIndexAt(layout, hb.rowIdx, clickCol));
|
|
18679
18746
|
}
|
|
@@ -18745,7 +18812,7 @@ export async function startTUI(opts) {
|
|
|
18745
18812
|
if (hb && hb.kind === 'composerRow') {
|
|
18746
18813
|
const { cols } = dims();
|
|
18747
18814
|
const insideW = Math.max(0, cols - 2);
|
|
18748
|
-
const layout = composerLayout(state, insideW
|
|
18815
|
+
const layout = composerLayout(state, insideW);
|
|
18749
18816
|
const clickCol = (t.col || 1) - 1;
|
|
18750
18817
|
const colInContent = Math.max(0, clickCol - 1);
|
|
18751
18818
|
const idx = composerTextIndexAt(layout, hb.rowIdx, colInContent);
|
|
@@ -19930,7 +19997,7 @@ export async function startTUI(opts) {
|
|
|
19930
19997
|
}
|
|
19931
19998
|
}
|
|
19932
19999
|
const insideW = Math.max(0, dims().cols - 2);
|
|
19933
|
-
const layout = composerLayout(state, insideW
|
|
20000
|
+
const layout = composerLayout(state, insideW);
|
|
19934
20001
|
const dir = t.key === 'down' ? 1 : -1;
|
|
19935
20002
|
const targetRow = layout.caretRow + dir;
|
|
19936
20003
|
if (targetRow >= 0 && targetRow < layout.rows.length) {
|
|
@@ -19958,7 +20025,7 @@ export async function startTUI(opts) {
|
|
|
19958
20025
|
if (!overlay) {
|
|
19959
20026
|
const cur = state.input || '';
|
|
19960
20027
|
const insideW = Math.max(0, dims().cols - 2);
|
|
19961
|
-
const layout = composerLayout(state, insideW
|
|
20028
|
+
const layout = composerLayout(state, insideW);
|
|
19962
20029
|
const dir = t.key === 'down' ? 1 : -1;
|
|
19963
20030
|
const targetRow = layout.caretRow + dir;
|
|
19964
20031
|
// The composer is MULTI-LINE: ↑/↓ move the caret between its rows
|
|
@@ -20386,7 +20453,7 @@ export async function startTUI(opts) {
|
|
|
20386
20453
|
return;
|
|
20387
20454
|
}
|
|
20388
20455
|
const insideW = Math.max(0, dims().cols - 2);
|
|
20389
|
-
const layout = composerLayout(state, insideW
|
|
20456
|
+
const layout = composerLayout(state, insideW);
|
|
20390
20457
|
const dir = t.key === 'down' ? 1 : -1;
|
|
20391
20458
|
const targetRow = layout.caretRow + dir;
|
|
20392
20459
|
if (targetRow >= 0 && targetRow < layout.rows.length) {
|
|
@@ -20514,7 +20581,7 @@ export async function startTUI(opts) {
|
|
|
20514
20581
|
// a multi-line prompt can be selected across lines. Same sticky column as
|
|
20515
20582
|
// the plain ↑/↓ (see verticalCaretIndex).
|
|
20516
20583
|
const insideW = Math.max(0, dims().cols - 2);
|
|
20517
|
-
const layout = composerLayout(state, insideW
|
|
20584
|
+
const layout = composerLayout(state, insideW);
|
|
20518
20585
|
const targetRow = layout.caretRow + (dirName === 'down' ? 1 : -1);
|
|
20519
20586
|
if (targetRow < 0 || targetRow >= layout.rows.length) { renderFrame(); return; }
|
|
20520
20587
|
next = verticalCaretIndex(state, cur, layout, targetRow);
|