forge-terminal 0.1.0 → 0.2.0
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 +305 -24
- package/dist/chunks/adm-zip-SQKLKBDP.js +3 -0
- package/dist/chunks/available-2VX7K7W6.js +3 -0
- package/dist/chunks/boot-ODZZHFUI.js +3 -0
- package/dist/chunks/cfb-V6M2PYOD.js +13 -0
- package/dist/chunks/chunk-2WYHI73Y.js +3 -0
- package/dist/chunks/chunk-4YHKTP7I.js +3 -0
- package/dist/chunks/chunk-5PYTOHLZ.js +3 -0
- package/dist/chunks/chunk-7YQR2MVH.js +3 -0
- package/dist/chunks/chunk-DRBA23IQ.js +3 -0
- package/dist/chunks/chunk-EOYBXOCV.js +4 -0
- package/dist/chunks/chunk-FQV57RMH.js +3 -0
- package/dist/chunks/chunk-IMKI5F4I.js +4 -0
- package/dist/chunks/chunk-J7FLFHQJ.js +3 -0
- package/dist/chunks/chunk-L2WK7CJG.js +3 -0
- package/dist/chunks/chunk-LFE3WRU4.js +3 -0
- package/dist/chunks/chunk-MHFY7HF6.js +10 -0
- package/dist/chunks/chunk-PBIS2ONZ.js +3 -0
- package/dist/chunks/chunk-QVACE4IE.js +3 -0
- package/dist/chunks/chunk-TMUK2DD3.js +3 -0
- package/dist/chunks/chunk-UNVHKJW4.js +41 -0
- package/dist/chunks/chunk-V4GHQGQM.js +4 -0
- package/dist/chunks/chunk-VB665HTV.js +3 -0
- package/dist/chunks/chunk-YHK5VE5R.js +3 -0
- package/dist/chunks/colour-QV2C3R7R.js +3 -0
- package/dist/chunks/config-command-UXJY623L.js +3 -0
- package/dist/chunks/dist-J2V6ITHG.js +29 -0
- package/dist/chunks/es-T2U7NBLD.js +3 -0
- package/dist/chunks/execute-4WJCUM7J.js +3 -0
- package/dist/chunks/extensions-command-6WZV2AES.js +3 -0
- package/dist/chunks/launch-2OI4ZLBQ.js +66 -0
- package/dist/chunks/lib-TPEJ5CJJ.js +46 -0
- package/dist/chunks/lock-R6GZXCCW.js +3 -0
- package/dist/chunks/manager-H52ENJOH.js +4 -0
- package/dist/chunks/paths-XY2345OS.js +3 -0
- package/dist/chunks/pdf-compress-IMRFBLZF.js +3 -0
- package/dist/chunks/react-devtools-core-UM4FS6CU.js +3 -0
- package/dist/chunks/run-N3F4EM7E.js +4 -0
- package/dist/chunks/server-5RWSVTOM.js +73 -0
- package/dist/chunks/theme-GW7CQPUO.js +3 -0
- package/dist/chunks/word-OGQ2KZAJ.js +24 -0
- package/dist/index.js +67 -95
- package/dist/third-party-licenses.txt +2856 -0
- package/package.json +28 -21
- package/skills/forge/SKILL.md +128 -0
- package/dist/cli/args.js +0 -278
- package/dist/cli/args.js.map +0 -1
- package/dist/cli/config-command.js +0 -55
- package/dist/cli/config-command.js.map +0 -1
- package/dist/cli/execute.js +0 -377
- package/dist/cli/execute.js.map +0 -1
- package/dist/cli/report.js +0 -123
- package/dist/cli/report.js.map +0 -1
- package/dist/cli/spinner.js +0 -60
- package/dist/cli/spinner.js.map +0 -1
- package/dist/cli/stdin.js +0 -47
- package/dist/cli/stdin.js.map +0 -1
- package/dist/config/preferences.js +0 -143
- package/dist/config/preferences.js.map +0 -1
- package/dist/core/actions/compress.js +0 -157
- package/dist/core/actions/compress.js.map +0 -1
- package/dist/core/actions/convert.js +0 -270
- package/dist/core/actions/convert.js.map +0 -1
- package/dist/core/actions/extract.js +0 -94
- package/dist/core/actions/extract.js.map +0 -1
- package/dist/core/actions/index.js +0 -23
- package/dist/core/actions/index.js.map +0 -1
- package/dist/core/actions/merge.js +0 -16
- package/dist/core/actions/merge.js.map +0 -1
- package/dist/core/actions/rotate.js +0 -36
- package/dist/core/actions/rotate.js.map +0 -1
- package/dist/core/actions/split.js +0 -65
- package/dist/core/actions/split.js.map +0 -1
- package/dist/core/atomic.js +0 -61
- package/dist/core/atomic.js.map +0 -1
- package/dist/core/capabilities.js +0 -59
- package/dist/core/capabilities.js.map +0 -1
- package/dist/core/compress.js +0 -76
- package/dist/core/compress.js.map +0 -1
- package/dist/core/describe.js +0 -49
- package/dist/core/describe.js.map +0 -1
- package/dist/core/errors.js +0 -469
- package/dist/core/errors.js.map +0 -1
- package/dist/core/execute-jobs.js +0 -122
- package/dist/core/execute-jobs.js.map +0 -1
- package/dist/core/formats.js +0 -108
- package/dist/core/formats.js.map +0 -1
- package/dist/core/order.js +0 -44
- package/dist/core/order.js.map +0 -1
- package/dist/core/output-path.js +0 -176
- package/dist/core/output-path.js.map +0 -1
- package/dist/core/pages.js +0 -107
- package/dist/core/pages.js.map +0 -1
- package/dist/core/pdf-compress.js +0 -206
- package/dist/core/pdf-compress.js.map +0 -1
- package/dist/core/plan.js +0 -42
- package/dist/core/plan.js.map +0 -1
- package/dist/core/resolve.js +0 -115
- package/dist/core/resolve.js.map +0 -1
- package/dist/core/run.js +0 -66
- package/dist/core/run.js.map +0 -1
- package/dist/core/suggest.js +0 -50
- package/dist/core/suggest.js.map +0 -1
- package/dist/core/types.js +0 -2
- package/dist/core/types.js.map +0 -1
- package/dist/core/units.js +0 -94
- package/dist/core/units.js.map +0 -1
- package/dist/core/write-safety.js +0 -128
- package/dist/core/write-safety.js.map +0 -1
- package/dist/engines/heic.js +0 -166
- package/dist/engines/heic.js.map +0 -1
- package/dist/engines/image.js +0 -342
- package/dist/engines/image.js.map +0 -1
- package/dist/engines/pdf.js +0 -444
- package/dist/engines/pdf.js.map +0 -1
- package/dist/engines/pdfium.js +0 -161
- package/dist/engines/pdfium.js.map +0 -1
- package/dist/engines/registry.js +0 -65
- package/dist/engines/registry.js.map +0 -1
- package/dist/engines/types.js +0 -2
- package/dist/engines/types.js.map +0 -1
- package/dist/engines/word.js +0 -385
- package/dist/engines/word.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/shell/App.js +0 -1972
- package/dist/shell/App.js.map +0 -1
- package/dist/shell/ClickTargets.js +0 -183
- package/dist/shell/ClickTargets.js.map +0 -1
- package/dist/shell/ThemeContext.js +0 -21
- package/dist/shell/ThemeContext.js.map +0 -1
- package/dist/shell/blocks.js +0 -160
- package/dist/shell/blocks.js.map +0 -1
- package/dist/shell/clipboard.js +0 -64
- package/dist/shell/clipboard.js.map +0 -1
- package/dist/shell/commands.js +0 -51
- package/dist/shell/commands.js.map +0 -1
- package/dist/shell/components/Banner.js +0 -73
- package/dist/shell/components/Banner.js.map +0 -1
- package/dist/shell/components/CommandPalette.js +0 -37
- package/dist/shell/components/CommandPalette.js.map +0 -1
- package/dist/shell/components/FileCard.js +0 -59
- package/dist/shell/components/FileCard.js.map +0 -1
- package/dist/shell/components/HintBar.js +0 -18
- package/dist/shell/components/HintBar.js.map +0 -1
- package/dist/shell/components/Hints.js +0 -21
- package/dist/shell/components/Hints.js.map +0 -1
- package/dist/shell/components/MergeList.js +0 -268
- package/dist/shell/components/MergeList.js.map +0 -1
- package/dist/shell/components/ModeHeader.js +0 -21
- package/dist/shell/components/ModeHeader.js.map +0 -1
- package/dist/shell/components/PageGrid.js +0 -324
- package/dist/shell/components/PageGrid.js.map +0 -1
- package/dist/shell/components/PathInput.js +0 -147
- package/dist/shell/components/PathInput.js.map +0 -1
- package/dist/shell/components/Progress.js +0 -43
- package/dist/shell/components/Progress.js.map +0 -1
- package/dist/shell/components/Prompt.js +0 -667
- package/dist/shell/components/Prompt.js.map +0 -1
- package/dist/shell/components/ResultLinks.js +0 -26
- package/dist/shell/components/ResultLinks.js.map +0 -1
- package/dist/shell/components/Select.js +0 -152
- package/dist/shell/components/Select.js.map +0 -1
- package/dist/shell/components/Slider.js +0 -48
- package/dist/shell/components/Slider.js.map +0 -1
- package/dist/shell/components/StagedFiles.js +0 -92
- package/dist/shell/components/StagedFiles.js.map +0 -1
- package/dist/shell/components/ThemePicker.js +0 -18
- package/dist/shell/components/ThemePicker.js.map +0 -1
- package/dist/shell/components/UnitRow.js +0 -30
- package/dist/shell/components/UnitRow.js.map +0 -1
- package/dist/shell/flows/pdf.js +0 -424
- package/dist/shell/flows/pdf.js.map +0 -1
- package/dist/shell/frame-geometry.js +0 -56
- package/dist/shell/frame-geometry.js.map +0 -1
- package/dist/shell/hyperlink.js +0 -27
- package/dist/shell/hyperlink.js.map +0 -1
- package/dist/shell/intro.js +0 -101
- package/dist/shell/intro.js.map +0 -1
- package/dist/shell/launch.js +0 -75
- package/dist/shell/launch.js.map +0 -1
- package/dist/shell/mark.js +0 -134
- package/dist/shell/mark.js.map +0 -1
- package/dist/shell/mouse.js +0 -209
- package/dist/shell/mouse.js.map +0 -1
- package/dist/shell/redraw.js +0 -36
- package/dist/shell/redraw.js.map +0 -1
- package/dist/shell/reveal.js +0 -24
- package/dist/shell/reveal.js.map +0 -1
- package/dist/shell/stage.js +0 -34
- package/dist/shell/stage.js.map +0 -1
- package/dist/shell/terminal-write.js +0 -16
- package/dist/shell/terminal-write.js.map +0 -1
- package/dist/shell/theme.js +0 -178
- package/dist/shell/theme.js.map +0 -1
- package/dist/shell/useFrameOrigin.js +0 -175
- package/dist/shell/useFrameOrigin.js.map +0 -1
- package/dist/shell/useKeys.js +0 -28
- package/dist/shell/useKeys.js.map +0 -1
- package/dist/shell/useMouse.js +0 -150
- package/dist/shell/useMouse.js.map +0 -1
- package/dist/shell/useMouseRouting.js +0 -69
- package/dist/shell/useMouseRouting.js.map +0 -1
- package/dist/shell/width.js +0 -62
- package/dist/shell/width.js.map +0 -1
- package/dist/utils/display-path.js +0 -31
- package/dist/utils/display-path.js.map +0 -1
- package/dist/utils/unescape-path.js +0 -68
- package/dist/utils/unescape-path.js.map +0 -1
|
@@ -1,667 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Text } from 'ink';
|
|
3
|
-
import { useRef, useState } from 'react';
|
|
4
|
-
import stringWidth from 'string-width';
|
|
5
|
-
import { unescapePath } from '../../utils/unescape-path.js';
|
|
6
|
-
import { useClickTarget } from '../ClickTargets.js';
|
|
7
|
-
import { copy, paste } from '../clipboard.js';
|
|
8
|
-
import { positionInFrame } from '../frame-geometry.js';
|
|
9
|
-
import { isStrayEscapeSequence, offsetForColumn } from '../mouse.js';
|
|
10
|
-
import { useTheme } from '../ThemeContext.js';
|
|
11
|
-
import { colourProp } from '../theme.js';
|
|
12
|
-
import { useKeys } from '../useKeys.js';
|
|
13
|
-
/**
|
|
14
|
-
* Consumes as many characters starting at `from` as fit within `maxWidth`
|
|
15
|
-
* display cells, always taking at least one. Mirrors `wrapWord`'s own
|
|
16
|
-
* per-token accumulation in wrap-ansi (the library `wrap-text.js` calls for
|
|
17
|
-
* Ink's `wrap="wrap"`): the first character placed on a row is kept even if
|
|
18
|
-
* it alone is wider than the row, which is what stops a single wide glyph
|
|
19
|
-
* from starving the loop.
|
|
20
|
-
*/
|
|
21
|
-
function takeByWidth(chars, from, maxWidth) {
|
|
22
|
-
let width = stringWidth(chars[from] ?? '');
|
|
23
|
-
let i = from + 1;
|
|
24
|
-
while (i < chars.length) {
|
|
25
|
-
const w = stringWidth(chars[i] ?? '');
|
|
26
|
-
if (width + w > maxWidth)
|
|
27
|
-
break;
|
|
28
|
-
width += w;
|
|
29
|
-
i++;
|
|
30
|
-
}
|
|
31
|
-
return i;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Where a wrapped, space-free `value` breaks across visual rows, given a
|
|
35
|
-
* `<Text wrap="wrap">` that is `columns` cells wide and a marker occupying
|
|
36
|
-
* `markerWidth` of those cells on row 0 only.
|
|
37
|
-
*
|
|
38
|
-
* Returns the EXCLUSIVE end index (into `Array.from(value)`) of each row's
|
|
39
|
-
* slice of `value`, in row order: row 0's slice is `value.slice(0,
|
|
40
|
-
* bounds[0])`, row `r`'s (`r > 0`) is `value.slice(bounds[r - 1],
|
|
41
|
-
* bounds[r])`. Row 0's slice can be empty — see below.
|
|
42
|
-
*
|
|
43
|
-
* This exists because `wrap-text.js` wraps with wrap-ansi's `{ trim: false,
|
|
44
|
-
* hard: true }` (checked against the installed wrap-ansi@10, which Ink
|
|
45
|
-
* 7.1.1 depends on), and a `value` with no space is one unbreakable "word":
|
|
46
|
-
* `hard: true` then degrades wrap-ansi's word-wrap to plain fixed-width
|
|
47
|
-
* chunking, via the exact same `wrapWord` routine this function mirrors.
|
|
48
|
-
* `trim: false` (Ink's choice, not the default) is what makes the mapping
|
|
49
|
-
* possible at all — it turns off wrap-ansi's end-of-row trimming, so every
|
|
50
|
-
* row's characters concatenate back into `value` exactly, in order, with
|
|
51
|
-
* none dropped or added, and a row-by-row walk can reconstruct `value`'s
|
|
52
|
-
* indices losslessly.
|
|
53
|
-
*
|
|
54
|
-
* Two things decide the split, both taken from wrap-ansi's own `exec`:
|
|
55
|
-
* 1. If `value` fits in `columns` at all, it either sits packed right
|
|
56
|
-
* after the marker (small enough for the leftover room), or — if not —
|
|
57
|
-
* moves whole to row 1, leaving row 0 as marker only.
|
|
58
|
-
* 2. If `value` is wider than a full row, it hard-wraps in `columns`-wide
|
|
59
|
-
* chunks. Whether the first chunk starts packed after the marker or on
|
|
60
|
-
* a fresh row follows wrap-ansi's own tie-break: pack there only when
|
|
61
|
-
* doing so does not cost an extra row overall.
|
|
62
|
-
*
|
|
63
|
-
* NOT attempted when `value` contains a space: wrap-ansi then wraps at word
|
|
64
|
-
* boundaries, which can end a row short of a full `columns` cells, and
|
|
65
|
-
* reproducing that exactly would mean re-implementing wrap-ansi's whole
|
|
66
|
-
* word-splitting pass — a second wrapping engine to keep forever in sync
|
|
67
|
-
* with whatever Ink bundles. Given how rarely a dropped or typed path
|
|
68
|
-
* actually contains a literal space, that cost is not worth paying here;
|
|
69
|
-
* callers fall back to clamping instead (see the click handler below).
|
|
70
|
-
*/
|
|
71
|
-
function hardWrapBounds(value, columns, markerWidth) {
|
|
72
|
-
const chars = Array.from(value);
|
|
73
|
-
const total = chars.length;
|
|
74
|
-
const remaining = columns - markerWidth;
|
|
75
|
-
const wordWidth = stringWidth(value);
|
|
76
|
-
if (wordWidth <= columns) {
|
|
77
|
-
return wordWidth <= remaining ? [total] : [0, total];
|
|
78
|
-
}
|
|
79
|
-
const breaksPackedHere = 1 + Math.floor((wordWidth - remaining - 1) / columns);
|
|
80
|
-
const breaksFromNextRow = Math.floor((wordWidth - 1) / columns);
|
|
81
|
-
const bounds = [];
|
|
82
|
-
let budget = remaining;
|
|
83
|
-
if (breaksFromNextRow < breaksPackedHere) {
|
|
84
|
-
bounds.push(0);
|
|
85
|
-
budget = columns;
|
|
86
|
-
}
|
|
87
|
-
let i = 0;
|
|
88
|
-
while (i < total) {
|
|
89
|
-
const end = takeByWidth(chars, i, budget);
|
|
90
|
-
bounds.push(end);
|
|
91
|
-
i = end;
|
|
92
|
-
budget = columns;
|
|
93
|
-
}
|
|
94
|
-
return bounds;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The drop area: where a file gets dropped or a path gets typed.
|
|
98
|
-
*
|
|
99
|
-
* Fully controlled — `value` is owned by the caller — but the text an
|
|
100
|
-
* in-flight `useInput` event must act on is mirrored into `valueRef` on every
|
|
101
|
-
* render, so a burst of stdin events delivered through the same handler
|
|
102
|
-
* closure before React re-renders still accumulates onto the real current
|
|
103
|
-
* value rather than a stale one, and a caller-driven reset (e.g. clearing the
|
|
104
|
-
* field after submit) is picked up the moment it renders. See Select.tsx and
|
|
105
|
-
* PathInput.tsx for the same pattern and its rationale.
|
|
106
|
-
*
|
|
107
|
-
* On submission the buffer is also reset right here, synchronously, rather
|
|
108
|
-
* than only via the caller clearing `value` and that flowing back through a
|
|
109
|
-
* re-render: two Enter-terminated events delivered in the same synchronous
|
|
110
|
-
* tick (e.g. two paths pasted back to back, or a fast burst of separate
|
|
111
|
-
* writes) reach this same closure before React ever gets a chance to
|
|
112
|
-
* re-render and resync `valueRef` from a cleared `value` prop. Without this,
|
|
113
|
-
* the second event's text would concatenate onto the just-submitted first
|
|
114
|
-
* event's text instead of starting clean, producing a path that exists
|
|
115
|
-
* nowhere on disk.
|
|
116
|
-
*/
|
|
117
|
-
export function Prompt({ value, onChange, onSubmit, placeholder, isActive, variant, width, rawOnSubmit = false, disableSubmit = false, }) {
|
|
118
|
-
const palette = useTheme();
|
|
119
|
-
const valueRef = useRef(value);
|
|
120
|
-
// Deliberately a plain assignment in the render body, not a `useEffect`:
|
|
121
|
-
// Ink's renderer has no browser paint to tear before, so there is no
|
|
122
|
-
// "render without committing" hazard `useLayoutEffect` guards against
|
|
123
|
-
// elsewhere. `useInput`'s handler (below) runs between renders, and by
|
|
124
|
-
// reading `valueRef.current` — never the `value` prop directly — it always
|
|
125
|
-
// sees whatever this line last wrote, which is current as of the most
|
|
126
|
-
// recent render, synchronously, with no effect-scheduling delay.
|
|
127
|
-
valueRef.current = value;
|
|
128
|
-
/**
|
|
129
|
-
* Insertion point, counted in code points from the start. A ref for the
|
|
130
|
-
* same reason `valueRef` is: arrow keys and text can arrive in one flush,
|
|
131
|
-
* and each must act on where the caret genuinely is now.
|
|
132
|
-
*
|
|
133
|
-
* Clamped on every read rather than only on write, because the caller can
|
|
134
|
-
* replace `value` from underneath us — Tab completion does exactly that —
|
|
135
|
-
* and a caret left past the new end would insert into nothing.
|
|
136
|
-
*/
|
|
137
|
-
// Initialised to the end of whatever the field was mounted with. The rename
|
|
138
|
-
// field is seeded by its parent before this component exists, so the
|
|
139
|
-
// "value changed from outside" check below never fires for that first
|
|
140
|
-
// value — starting at 0 is what put typed text in front of the name.
|
|
141
|
-
const caretRef = useRef(Array.from(value).length);
|
|
142
|
-
/**
|
|
143
|
-
* A caret move changes no text, so `onChange(value)` hands React the string
|
|
144
|
-
* it already has and it bails out of re-rendering — the caret would move in
|
|
145
|
-
* the ref and never on screen. This counter exists solely to give those
|
|
146
|
-
* renders something that actually changed.
|
|
147
|
-
*/
|
|
148
|
-
const [, bump] = useState(0);
|
|
149
|
-
const rerender = () => bump((n) => n + 1);
|
|
150
|
-
/**
|
|
151
|
-
* The last value this component itself produced. When `value` arrives
|
|
152
|
-
* different from it, the parent replaced the text from outside — seeding
|
|
153
|
-
* the rename field with a filename, or Tab completing a path — and the
|
|
154
|
-
* caret belongs at the end of the new text, not wherever it happened to sit
|
|
155
|
-
* in the old. Without this the rename field opened with the caret at 0 and
|
|
156
|
-
* everything typed landed in front of the name.
|
|
157
|
-
*/
|
|
158
|
-
const ownRef = useRef(value);
|
|
159
|
-
if (value !== ownRef.current) {
|
|
160
|
-
ownRef.current = value;
|
|
161
|
-
caretRef.current = Array.from(value).length;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* The fixed end of a selection; the caret is the moving end. `null` means
|
|
165
|
-
* nothing is selected.
|
|
166
|
-
*
|
|
167
|
-
* Anchor-and-head rather than start-and-end, which is what lets Shift+Left
|
|
168
|
-
* *shrink* a selection built with Shift+Right instead of always growing it:
|
|
169
|
-
* the pair remembers which end the user is dragging. Start/end would have
|
|
170
|
-
* thrown that away on the first normalisation.
|
|
171
|
-
*/
|
|
172
|
-
const anchorRef = useRef(null);
|
|
173
|
-
const chars = () => Array.from(valueRef.current);
|
|
174
|
-
const caret = () => Math.min(Math.max(caretRef.current, 0), chars().length);
|
|
175
|
-
/** The selected span as a half-open range, or null when nothing is selected. */
|
|
176
|
-
const selection = () => {
|
|
177
|
-
const anchor = anchorRef.current;
|
|
178
|
-
if (anchor === null)
|
|
179
|
-
return null;
|
|
180
|
-
const at = caret();
|
|
181
|
-
const from = Math.min(anchor, at);
|
|
182
|
-
const to = Math.max(anchor, at);
|
|
183
|
-
return from === to ? null : { from, to };
|
|
184
|
-
};
|
|
185
|
-
const commit = (next, at) => {
|
|
186
|
-
valueRef.current = next;
|
|
187
|
-
caretRef.current = at;
|
|
188
|
-
ownRef.current = next;
|
|
189
|
-
anchorRef.current = null;
|
|
190
|
-
onChange(next);
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Moves the caret, either extending the selection or dropping it.
|
|
194
|
-
*
|
|
195
|
-
* Every motion goes through here so the "plain motion collapses, shifted
|
|
196
|
-
* motion extends" rule is stated once rather than repeated at a dozen call
|
|
197
|
-
* sites, where one omission would leave a selection stranded on screen.
|
|
198
|
-
*/
|
|
199
|
-
const moveTo = (position, extend) => {
|
|
200
|
-
if (extend) {
|
|
201
|
-
if (anchorRef.current === null)
|
|
202
|
-
anchorRef.current = caret();
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
anchorRef.current = null;
|
|
206
|
-
}
|
|
207
|
-
caretRef.current = position;
|
|
208
|
-
rerender();
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Removes the selected span and returns what it held, or null if there was
|
|
212
|
-
* no selection. Callers use the return value to decide whether they still
|
|
213
|
-
* have their own work to do — typing over a selection replaces it, but
|
|
214
|
-
* Backspace with a selection is *only* the deletion.
|
|
215
|
-
*/
|
|
216
|
-
const deleteSelection = () => {
|
|
217
|
-
const span = selection();
|
|
218
|
-
if (!span)
|
|
219
|
-
return null;
|
|
220
|
-
const c = chars();
|
|
221
|
-
const removed = c.slice(span.from, span.to).join('');
|
|
222
|
-
commit([...c.slice(0, span.from), ...c.slice(span.to)].join(''), span.from);
|
|
223
|
-
return removed;
|
|
224
|
-
};
|
|
225
|
-
useKeys((input, key) => {
|
|
226
|
-
/**
|
|
227
|
-
* Escape clears the field rather than acting as a second "back" key
|
|
228
|
-
* alongside whatever the owning step already does with it: with text
|
|
229
|
-
* still in the field there is nothing further back to fall to, so the
|
|
230
|
-
* first press only clears. Once the field is empty there is nothing
|
|
231
|
-
* left for this component to do, so it no-ops and leaves the
|
|
232
|
-
* keystroke for the owning step's own escape handler — delivered to
|
|
233
|
-
* every mounted `useInput` the same way — to treat as "back a step".
|
|
234
|
-
*/
|
|
235
|
-
if (key.escape) {
|
|
236
|
-
if (chars().length === 0)
|
|
237
|
-
return;
|
|
238
|
-
commit('', 0);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Every branch below matches on what Ink *delivers*, which is not what
|
|
243
|
-
* the terminal sends. `use-input.js` strips a leading ESC from any
|
|
244
|
-
* sequence `parse-keypress` did not fully resolve, so a comparison like
|
|
245
|
-
* `input === '\x1bb'` can never be true — the handler sees `'b'` with
|
|
246
|
-
* `key.meta` set. An earlier version of this file was written against
|
|
247
|
-
* the raw sequences and every one of those branches was dead code.
|
|
248
|
-
*
|
|
249
|
-
* Measured against Ink 7.1.1 (see tests/shell/prompt-shortcuts.test.tsx
|
|
250
|
-
* for the sequences, which are the ones Terminal.app's shipped
|
|
251
|
-
* keyMappings.plist and iTerm2/xterm actually emit):
|
|
252
|
-
*
|
|
253
|
-
* Option+Left ESC b -> input 'b', key.meta
|
|
254
|
-
* Option+Left CSI 1;3D -> input '', key.meta + key.leftArrow
|
|
255
|
-
* Ctrl+Left CSI 1;5D -> input '', key.ctrl + key.leftArrow
|
|
256
|
-
* Option+Bksp ESC DEL -> input '', key.meta + key.backspace
|
|
257
|
-
* fn+Delete CSI 3~ -> input '', key.delete
|
|
258
|
-
* Home / End CSI H / F -> input '', key.home / key.end
|
|
259
|
-
* Ctrl+U/K/W/A/E -> input 'u'/'k'/'w'/'a'/'e', key.ctrl
|
|
260
|
-
*
|
|
261
|
-
* `key.meta` means only "the bytes were ESC-prefixed" — which is what
|
|
262
|
-
* Option sends. It can therefore never identify Cmd, and in Terminal.app
|
|
263
|
-
* Cmd is unreachable outright: its key-mapping UI does not offer Command
|
|
264
|
-
* as a modifier, so no Cmd chord produces bytes at all.
|
|
265
|
-
*
|
|
266
|
-
* Cmd is still reachable elsewhere, through a different channel: the
|
|
267
|
-
* kitty keyboard protocol reports a modifier bitmask instead of an ESC
|
|
268
|
-
* prefix, and Ink surfaces its Cmd bit as `key.super`. `launch.tsx`
|
|
269
|
-
* negotiates that protocol, so the `key.super` branches below are live
|
|
270
|
-
* in iTerm2, Ghostty, WezTerm, kitty and VS Code's terminal, and inert
|
|
271
|
-
* in Terminal.app.
|
|
272
|
-
*/
|
|
273
|
-
const wordBack = (c, from) => {
|
|
274
|
-
let i = from;
|
|
275
|
-
while (i > 0 && c[i - 1] === ' ')
|
|
276
|
-
i--;
|
|
277
|
-
while (i > 0 && c[i - 1] !== ' ' && c[i - 1] !== '/')
|
|
278
|
-
i--;
|
|
279
|
-
return i;
|
|
280
|
-
};
|
|
281
|
-
const wordForward = (c, from) => {
|
|
282
|
-
let i = from;
|
|
283
|
-
while (i < c.length && c[i] === ' ')
|
|
284
|
-
i++;
|
|
285
|
-
while (i < c.length && c[i] !== ' ' && c[i] !== '/')
|
|
286
|
-
i++;
|
|
287
|
-
return i;
|
|
288
|
-
};
|
|
289
|
-
/**
|
|
290
|
-
* Cmd, reported as `key.super` by the kitty keyboard protocol that
|
|
291
|
-
* `launch.tsx` asks for. Checked before the Option and plain branches
|
|
292
|
-
* because on macOS Cmd is the *line*-scoped modifier and Option the
|
|
293
|
-
* word-scoped one — Cmd+Left goes to the start of the line, not back a
|
|
294
|
-
* word — and `key.super` arrives alongside `key.leftArrow`, which the
|
|
295
|
-
* branches below would otherwise claim first.
|
|
296
|
-
*
|
|
297
|
-
* Silent no-ops in a terminal without the protocol (Terminal.app), where
|
|
298
|
-
* Cmd cannot be reported at all and these are simply never true.
|
|
299
|
-
*/
|
|
300
|
-
if (key.super && key.leftArrow) {
|
|
301
|
-
moveTo(0, key.shift);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (key.super && key.rightArrow) {
|
|
305
|
-
moveTo(chars().length, key.shift);
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
// Cmd+Backspace — delete to line start, the macOS counterpart of Ctrl+U.
|
|
309
|
-
if (key.super && key.backspace) {
|
|
310
|
-
const c = chars();
|
|
311
|
-
const at = caret();
|
|
312
|
-
copy(c.slice(0, at).join(''));
|
|
313
|
-
commit(c.slice(at).join(''), 0);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
// Cmd+fn+Delete — delete to line end.
|
|
317
|
-
if (key.super && key.delete) {
|
|
318
|
-
const c = chars();
|
|
319
|
-
const at = caret();
|
|
320
|
-
copy(c.slice(at).join(''));
|
|
321
|
-
commit(c.slice(0, at).join(''), at);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
// Cmd+A — select all. Ctrl+A stays line-start (readline), which is why
|
|
325
|
-
// this needs the protocol to be distinguishable at all.
|
|
326
|
-
if (key.super && input === 'a') {
|
|
327
|
-
anchorRef.current = 0;
|
|
328
|
-
caretRef.current = chars().length;
|
|
329
|
-
rerender();
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* The kill commands put what they removed on the system clipboard, and
|
|
334
|
-
* Ctrl+Y puts it back. That is readline's kill-ring model, mapped onto
|
|
335
|
-
* the clipboard the rest of the machine shares — and it is the only
|
|
336
|
-
* copy route available here, because Cmd+C never reaches a terminal
|
|
337
|
-
* app: the terminal keeps it for copying *its* selection, which is not
|
|
338
|
-
* this field's.
|
|
339
|
-
*/
|
|
340
|
-
// Ctrl+X — cut the selection.
|
|
341
|
-
if (key.ctrl && input === 'x') {
|
|
342
|
-
const cut = deleteSelection();
|
|
343
|
-
if (cut !== null)
|
|
344
|
-
copy(cut);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
// Ctrl+Y — yank: insert the clipboard at the caret, replacing any
|
|
348
|
-
// selection. Cmd+V still works too; the terminal turns it into ordinary
|
|
349
|
-
// typed input, which the text branch below already handles.
|
|
350
|
-
if (key.ctrl && input === 'y') {
|
|
351
|
-
const pasted = paste();
|
|
352
|
-
if (pasted === '')
|
|
353
|
-
return;
|
|
354
|
-
deleteSelection();
|
|
355
|
-
const c = chars();
|
|
356
|
-
const at = caret();
|
|
357
|
-
// A clipboard holding several lines is one line's worth of path here;
|
|
358
|
-
// the rest would be silently mangled, so only the first is taken.
|
|
359
|
-
const flat = pasted.split(/[\r\n]/)[0] ?? '';
|
|
360
|
-
const typed = Array.from(flat);
|
|
361
|
-
commit([...c.slice(0, at), ...typed, ...c.slice(at)].join(''), at + typed.length);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
// Ctrl+U — kill to line start.
|
|
365
|
-
if (key.ctrl && input === 'u') {
|
|
366
|
-
const c = chars();
|
|
367
|
-
const at = caret();
|
|
368
|
-
copy(c.slice(0, at).join(''));
|
|
369
|
-
commit(c.slice(at).join(''), 0);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
// Ctrl+K — kill to line end.
|
|
373
|
-
if (key.ctrl && input === 'k') {
|
|
374
|
-
const c = chars();
|
|
375
|
-
const at = caret();
|
|
376
|
-
copy(c.slice(at).join(''));
|
|
377
|
-
commit(c.slice(0, at).join(''), at);
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
// Option+Backspace / Ctrl+W — delete the word before the caret, or the
|
|
381
|
-
// selection if there is one.
|
|
382
|
-
if ((key.meta && key.backspace) || (key.ctrl && input === 'w')) {
|
|
383
|
-
const cut = deleteSelection();
|
|
384
|
-
if (cut !== null) {
|
|
385
|
-
copy(cut);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
const c = chars();
|
|
389
|
-
const at = caret();
|
|
390
|
-
const i = wordBack(c, at);
|
|
391
|
-
copy(c.slice(i, at).join(''));
|
|
392
|
-
commit([...c.slice(0, i), ...c.slice(at)].join(''), i);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
// Option+fn+Delete — delete the word after the caret.
|
|
396
|
-
if (key.meta && key.delete) {
|
|
397
|
-
const c = chars();
|
|
398
|
-
const at = caret();
|
|
399
|
-
const i = wordForward(c, at);
|
|
400
|
-
commit([...c.slice(0, at), ...c.slice(i)].join(''), at);
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* `key.shift` on an arrow extends the selection instead of collapsing
|
|
405
|
-
* it. Terminal.app sends Shift+Left/Right (`CSI 1;2D`/`C`) but has no
|
|
406
|
-
* mapping at all for Shift+Up/Down, so horizontal selection is the only
|
|
407
|
-
* kind this field can offer — which costs nothing, because the field is
|
|
408
|
-
* one line.
|
|
409
|
-
*/
|
|
410
|
-
// Option+Left / Ctrl+Left — word back.
|
|
411
|
-
if (((key.meta || key.ctrl) && key.leftArrow) || (key.meta && input === 'b')) {
|
|
412
|
-
moveTo(wordBack(chars(), caret()), key.shift);
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
// Option+Right / Ctrl+Right — word forward.
|
|
416
|
-
if (((key.meta || key.ctrl) && key.rightArrow) || (key.meta && input === 'f')) {
|
|
417
|
-
moveTo(wordForward(chars(), caret()), key.shift);
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
// Home / Ctrl+A — line start. Terminal.app does not map Home by
|
|
421
|
-
// default (it scrolls the view), so Ctrl+A carries this there.
|
|
422
|
-
if (key.home || (key.ctrl && input === 'a')) {
|
|
423
|
-
moveTo(0, key.shift);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
// End / Ctrl+E — line end.
|
|
427
|
-
if (key.end || (key.ctrl && input === 'e')) {
|
|
428
|
-
moveTo(chars().length, key.shift);
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
if (key.leftArrow) {
|
|
432
|
-
/**
|
|
433
|
-
* A plain arrow with a selection up collapses to that selection's
|
|
434
|
-
* edge rather than stepping one further, which is what every text
|
|
435
|
-
* field does — pressing Left after selecting "bar" puts the caret
|
|
436
|
-
* before the b, not before the a.
|
|
437
|
-
*/
|
|
438
|
-
const span = selection();
|
|
439
|
-
moveTo(span && !key.shift ? span.from : Math.max(0, caret() - 1), key.shift);
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
if (key.rightArrow) {
|
|
443
|
-
const span = selection();
|
|
444
|
-
moveTo(span && !key.shift ? span.to : Math.min(chars().length, caret() + 1), key.shift);
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
if (key.return) {
|
|
448
|
-
// Left to `CommandPalette`'s own `Select` — see `disableSubmit`'s doc
|
|
449
|
-
// comment. Not even a buffer clear: `Select`'s `onSubmit` already
|
|
450
|
-
// routes through `runCommand`, which clears it.
|
|
451
|
-
if (disableSubmit)
|
|
452
|
-
return;
|
|
453
|
-
onSubmit(rawOnSubmit ? valueRef.current : unescapePath(valueRef.current));
|
|
454
|
-
valueRef.current = '';
|
|
455
|
-
caretRef.current = 0;
|
|
456
|
-
onChange('');
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
459
|
-
/**
|
|
460
|
-
* Forward delete is its own branch, not folded in with backspace. Ink
|
|
461
|
-
* reports fn+Delete as `key.delete` and Backspace as `key.backspace`;
|
|
462
|
-
* treating them alike made fn+Delete eat the character *before* the
|
|
463
|
-
* caret, which is the opposite of what the key does.
|
|
464
|
-
*/
|
|
465
|
-
if (key.delete) {
|
|
466
|
-
if (deleteSelection() !== null)
|
|
467
|
-
return;
|
|
468
|
-
const c = chars();
|
|
469
|
-
const at = caret();
|
|
470
|
-
if (at >= c.length)
|
|
471
|
-
return;
|
|
472
|
-
commit([...c.slice(0, at), ...c.slice(at + 1)].join(''), at);
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
if (key.backspace) {
|
|
476
|
-
if (deleteSelection() !== null)
|
|
477
|
-
return;
|
|
478
|
-
const c = chars();
|
|
479
|
-
const at = caret();
|
|
480
|
-
if (at === 0)
|
|
481
|
-
return;
|
|
482
|
-
commit([...c.slice(0, at - 1), ...c.slice(at)].join(''), at - 1);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
// An unhandled Ctrl chord (every letter this component gives a job to
|
|
486
|
-
// — a/e/u/k/w/x/y — already returned above) is not text: falling
|
|
487
|
-
// through to the branch below would type the bare letter, which is
|
|
488
|
-
// what let Ctrl+N land an 'n' in the field instead of doing nothing.
|
|
489
|
-
if (key.ctrl)
|
|
490
|
-
return;
|
|
491
|
-
if (input) {
|
|
492
|
-
/**
|
|
493
|
-
* An unresolved control sequence reaches here with its ESC already
|
|
494
|
-
* stripped, so it looks like ordinary text beginning with `[` — a
|
|
495
|
-
* mouse report arrives as `"[<0;12;34M"`. The old guard tested
|
|
496
|
-
* `input.startsWith('\x1b')`, which can never be true, so any
|
|
497
|
-
* terminal with mouse reporting on typed its own mouse events into
|
|
498
|
-
* the path.
|
|
499
|
-
*
|
|
500
|
-
* Matched narrowly on purpose: a lone `[`, and `[` followed by
|
|
501
|
-
* anything that is not a CSI parameter run, stay typeable, because
|
|
502
|
-
* brackets are legal in filenames — `shot[1].png` must still work.
|
|
503
|
-
*/
|
|
504
|
-
if (isStrayEscapeSequence(input)) {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
// Typing over a selection replaces it, so the removal happens before
|
|
508
|
-
// the buffer is read back below.
|
|
509
|
-
deleteSelection();
|
|
510
|
-
const breakIndex = input.search(/[\r\n]/);
|
|
511
|
-
const c = chars();
|
|
512
|
-
const at = caret();
|
|
513
|
-
if (breakIndex !== -1) {
|
|
514
|
-
const next = [...c.slice(0, at), ...input.slice(0, breakIndex), ...c.slice(at)].join('');
|
|
515
|
-
onSubmit(rawOnSubmit ? next : unescapePath(next));
|
|
516
|
-
valueRef.current = '';
|
|
517
|
-
caretRef.current = 0;
|
|
518
|
-
onChange('');
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
const typed = Array.from(input);
|
|
522
|
-
commit([...c.slice(0, at), ...typed, ...c.slice(at)].join(''), at + typed.length);
|
|
523
|
-
}
|
|
524
|
-
}, { isActive });
|
|
525
|
-
const cells = Array.from(value);
|
|
526
|
-
const at = Math.min(Math.max(caretRef.current, 0), cells.length);
|
|
527
|
-
/**
|
|
528
|
-
* Click-to-position the caret.
|
|
529
|
-
*
|
|
530
|
-
* This was once impossible for a stated reason: mapping a click needs the
|
|
531
|
-
* frame's absolute position, which Ink never exposes, and the apparent way
|
|
532
|
-
* around it — parking the *real* terminal cursor on the caret and asking the
|
|
533
|
-
* terminal where its cursor is — showed a second cursor, because Ink cannot
|
|
534
|
-
* place the cursor without making it visible.
|
|
535
|
-
*
|
|
536
|
-
* What changed is that the query never needed the caret. Ink hides the cursor
|
|
537
|
-
* while rendering and leaves it one line below the frame, so asking where it
|
|
538
|
-
* is locates the *frame* — invisibly, and without moving anything. The caret
|
|
539
|
-
* is then plain arithmetic from there. See `useFrameOrigin.ts`.
|
|
540
|
-
*/
|
|
541
|
-
const lineRef = useRef(null);
|
|
542
|
-
/**
|
|
543
|
-
* The prompt marker (`› `, or ` › ` in the plain variant) sits between the
|
|
544
|
-
* Box's left edge and the first character of row 0 ONLY. `value` renders
|
|
545
|
-
* inside `<Text wrap="wrap">`, so a value longer than the available width
|
|
546
|
-
* spans several visual rows — the normal case for a real path, not an edge
|
|
547
|
-
* case — and a continuation row has no marker at all: it starts at column
|
|
548
|
-
* 0. Both the click inset below and the continuation-row math in `onClick`
|
|
549
|
-
* need this number, so it is computed once.
|
|
550
|
-
*/
|
|
551
|
-
const markerWidth = variant === 'plain' ? 4 : 2;
|
|
552
|
-
useClickTarget({
|
|
553
|
-
id: 'prompt-line',
|
|
554
|
-
ref: lineRef,
|
|
555
|
-
isActive,
|
|
556
|
-
// Shrinks the registered rect past the marker, which is only ever
|
|
557
|
-
// correct for row 0 — `onClick` below corrects for that on every other
|
|
558
|
-
// row.
|
|
559
|
-
inset: { col: markerWidth },
|
|
560
|
-
onClick: (point) => {
|
|
561
|
-
/**
|
|
562
|
-
* Row 0: `point.col` is already target-relative and already past the
|
|
563
|
-
* marker (the registered rect is inset by `markerWidth`), so it is a
|
|
564
|
-
* column straight into `value`, and `offsetForColumn` finds the
|
|
565
|
-
* character by display width exactly as it always has — unchanged
|
|
566
|
-
* from before this row-aware handling existed.
|
|
567
|
-
*/
|
|
568
|
-
if (point.row === 0) {
|
|
569
|
-
moveTo(offsetForColumn(valueRef.current, point.col), false);
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
// A continuation row has no marker, so its true on-screen column is
|
|
573
|
-
// `point.col` with the inset added back — the inset only ever applied
|
|
574
|
-
// to row 0.
|
|
575
|
-
const colInRow = point.col + markerWidth;
|
|
576
|
-
// The same width the `<Text wrap="wrap">` actually wrapped against:
|
|
577
|
-
// the registered click rect is this width minus `markerWidth` (see
|
|
578
|
-
// the inset above), so re-deriving it here from the live layout, the
|
|
579
|
-
// same way `useClickTarget` itself does, is the only way to recover
|
|
580
|
-
// it without hardcoding the padding math for each variant.
|
|
581
|
-
const rect = positionInFrame(lineRef.current);
|
|
582
|
-
const columns = rect?.width;
|
|
583
|
-
if (columns === undefined || columns < markerWidth || /\s/.test(valueRef.current)) {
|
|
584
|
-
/**
|
|
585
|
-
* FALLBACK, not the full mapping — see `hardWrapBounds` above for
|
|
586
|
-
* why a value containing whitespace is not attempted (word-wrap
|
|
587
|
-
* boundaries, not fixed columns) and why a terminal narrower than
|
|
588
|
-
* the marker itself is not either (the tie-break arithmetic assumes
|
|
589
|
-
* non-negative leftover room). Landing at the end is predictable;
|
|
590
|
-
* guessing a column-based offset that ignores how this row actually
|
|
591
|
-
* wrapped would not be — see the reviewer's repro in
|
|
592
|
-
* prompt-mouse.test.tsx for exactly what that looked like.
|
|
593
|
-
*/
|
|
594
|
-
moveTo(chars().length, false);
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
const bounds = hardWrapBounds(valueRef.current, columns, markerWidth);
|
|
598
|
-
const start = bounds[point.row - 1] ?? chars().length;
|
|
599
|
-
const end = bounds[point.row] ?? chars().length;
|
|
600
|
-
const rowText = chars().slice(start, end).join('');
|
|
601
|
-
moveTo(start + offsetForColumn(rowText, colInRow), false);
|
|
602
|
-
},
|
|
603
|
-
});
|
|
604
|
-
/**
|
|
605
|
-
* The caret is drawn as an inverse block on the character it sits on, and
|
|
606
|
-
* on a trailing space when it is at the end. `inverse` rather than a
|
|
607
|
-
* palette colour: it swaps whatever foreground and background the terminal
|
|
608
|
-
* is already using, so it is visible in either theme and under NO_COLOR,
|
|
609
|
-
* where a coloured caret would vanish along with everything else.
|
|
610
|
-
*/
|
|
611
|
-
const before = cells.slice(0, at).join('');
|
|
612
|
-
const under = cells[at] ?? ' ';
|
|
613
|
-
const after = cells.slice(at + 1).join('');
|
|
614
|
-
/**
|
|
615
|
-
* `inverse` is an SGR attribute, so with colour suppressed it emits nothing
|
|
616
|
-
* and the caret disappears — leaving no way to tell where typing will land
|
|
617
|
-
* in the middle of a name. Under NO_COLOR the caret becomes a literal
|
|
618
|
-
* glyph instead, which is the same rule the rest of the shell follows:
|
|
619
|
-
* meaning never rides on colour alone (spec §13).
|
|
620
|
-
*/
|
|
621
|
-
const noColour = process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== '';
|
|
622
|
-
const caretGlyph = (ch) => noColour ? _jsx(Text, { color: colourProp(palette.fg), children: `▏${ch}` }) : _jsx(Text, { inverse: true, children: ch });
|
|
623
|
-
/**
|
|
624
|
-
* A selection is drawn as a background band, not with `inverse`. `inverse`
|
|
625
|
-
* is a flag rather than a toggle — nesting it inside an already-inverted run
|
|
626
|
-
* renders identically, so a caret drawn that way *inside* a selection would
|
|
627
|
-
* simply vanish. A background colour and an inverse caret compose; two
|
|
628
|
-
* inverses do not.
|
|
629
|
-
*
|
|
630
|
-
* With no palette (the first-run picker, or NO_COLOR) there is no background
|
|
631
|
-
* to use, so the band falls back to `inverse` and the caret is dropped for
|
|
632
|
-
* the duration — the band itself then shows where the selection is.
|
|
633
|
-
*/
|
|
634
|
-
const span = (() => {
|
|
635
|
-
const anchor = anchorRef.current;
|
|
636
|
-
if (anchor === null)
|
|
637
|
-
return null;
|
|
638
|
-
const from = Math.min(anchor, at);
|
|
639
|
-
const to = Math.max(anchor, at);
|
|
640
|
-
return from === to ? null : { from, to };
|
|
641
|
-
})();
|
|
642
|
-
const selectionColour = colourProp(palette.textSelectionBg);
|
|
643
|
-
const line = span ? (_jsxs(Text, { children: [_jsx(Text, { color: colourProp(palette.fg), children: cells.slice(0, span.from).join('') }), _jsx(Text, { color: colourProp(palette.fg), ...(selectionColour ? { backgroundColor: selectionColour } : { inverse: true }), children: cells.slice(span.from, span.to).join('') }), _jsx(Text, { color: colourProp(palette.fg), children: cells.slice(span.to).join('') })] })) : value ? (_jsxs(Text, { children: [_jsx(Text, { color: colourProp(palette.fg), children: before }), isActive ? caretGlyph(under) : _jsx(Text, { color: colourProp(palette.fg), children: under }), _jsx(Text, { color: colourProp(palette.fg), children: after })] })) : (_jsxs(Text, { children: [isActive ? caretGlyph(' ') : null, _jsx(Text, { color: colourProp(palette.dim), children: placeholder })] }));
|
|
644
|
-
/**
|
|
645
|
-
* A filled drop area, drawn without a border: the fill *is* the boundary,
|
|
646
|
-
* and a stroke around it only competed with the panel it was outlining.
|
|
647
|
-
* Three rows because this is the target you drag a file onto, and a
|
|
648
|
-
* one-line box is a small target.
|
|
649
|
-
*
|
|
650
|
-
* Every row is padded to exactly the same width — an earlier version
|
|
651
|
-
* budgeted the text row differently from the blank ones, which is what left
|
|
652
|
-
* the ragged notch on the right.
|
|
653
|
-
*
|
|
654
|
-
* Measured: Ink trims trailing whitespace from a rendered line, but only
|
|
655
|
-
* when it really is whitespace — with a background set the run ends in the
|
|
656
|
-
* reset sequence and survives intact. So the fill exists exactly when
|
|
657
|
-
* colour does, and under NO_COLOR it collapses to the prompt line alone,
|
|
658
|
-
* which is the right outcome either way.
|
|
659
|
-
*/
|
|
660
|
-
const bg = palette.selectionBg === '' ? undefined : palette.selectionBg;
|
|
661
|
-
if (!bg || variant === 'plain') {
|
|
662
|
-
// No colour: there is no fill to draw, so the prompt is just its line.
|
|
663
|
-
return (_jsx(Box, { flexDirection: "column", children: _jsx(Box, { ref: lineRef, width: width, children: _jsxs(Text, { wrap: "wrap", children: [_jsx(Text, { color: colourProp(palette.accent), children: ' › ' }), line] }) }) }));
|
|
664
|
-
}
|
|
665
|
-
return (_jsx(Box, { flexDirection: "column", width: width, backgroundColor: colourProp(bg), paddingX: 1, paddingY: 1, marginTop: variant === 'field' ? 2 : 1, marginBottom: variant === 'field' ? 2 : 1, children: _jsx(Box, { ref: lineRef, children: _jsxs(Text, { wrap: "wrap", children: [_jsx(Text, { color: colourProp(palette.accent), children: '› ' }), line] }) }) }));
|
|
666
|
-
}
|
|
667
|
-
//# sourceMappingURL=Prompt.js.map
|