@bastani/atomic-tui 0.9.90-alpha.1 → 0.10.0-alpha.1
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/dist/builtin-command-names.d.ts +1 -1
- package/dist/builtin-command-names.d.ts.map +1 -1
- package/dist/builtin-command-names.js +0 -2
- package/dist/builtin-command-names.js.map +1 -1
- package/dist/clickable-hints.d.ts.map +1 -1
- package/dist/clickable-hints.js +75 -19
- package/dist/clickable-hints.js.map +1 -1
- package/dist/components/editor.d.ts +39 -0
- package/dist/components/editor.d.ts.map +1 -1
- package/dist/components/editor.js +110 -0
- package/dist/components/editor.js.map +1 -1
- package/dist/components/scroll-view.d.ts +17 -0
- package/dist/components/scroll-view.d.ts.map +1 -1
- package/dist/components/scroll-view.js +40 -0
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/windowed-container.d.ts +87 -0
- package/dist/components/windowed-container.d.ts.map +1 -1
- package/dist/components/windowed-container.js +212 -3
- package/dist/components/windowed-container.js.map +1 -1
- package/dist/editor-component.d.ts +9 -0
- package/dist/editor-component.d.ts.map +1 -1
- package/dist/editor-component.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kill-ring.d.ts +2 -0
- package/dist/kill-ring.d.ts.map +1 -1
- package/dist/kill-ring.js +6 -0
- package/dist/kill-ring.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +6 -1
- package/dist/layout.js.map +1 -1
- package/dist/tui-alt-screen.d.ts +45 -1
- package/dist/tui-alt-screen.d.ts.map +1 -1
- package/dist/tui-alt-screen.js +550 -48
- package/dist/tui-alt-screen.js.map +1 -1
- package/dist/tui-main-screen.d.ts +27 -1
- package/dist/tui-main-screen.d.ts.map +1 -1
- package/dist/tui-main-screen.js +216 -15
- package/dist/tui-main-screen.js.map +1 -1
- package/dist/tui.d.ts +56 -4
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +58 -7
- package/dist/tui.js.map +1 -1
- package/dist/undo-stack.d.ts +2 -0
- package/dist/undo-stack.d.ts.map +1 -1
- package/dist/undo-stack.js +6 -0
- package/dist/undo-stack.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Ordered command IDs shared by the application command registry and the terminal hint grammar. */
|
|
2
2
|
export declare const CORE_COMMAND_NAMES: readonly ["settings", "model", "tree", "thinking", "scoped-models", "export", "import", "share", "copy", "name", "session", "tools", "tasks", "changelog", "hotkeys", "fork", "clone", "trust", "login", "logout", "new", "compact", "resume", "reload", "exit", "quit"];
|
|
3
|
-
export declare const BUNDLED_COMMAND_NAMES: readonly ["agents", "
|
|
3
|
+
export declare const BUNDLED_COMMAND_NAMES: readonly ["agents", "mcp", "mcp-auth", "curator", "google-account", "search", "websearch", "intercom"];
|
|
4
4
|
//# sourceMappingURL=builtin-command-names.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin-command-names.d.ts","sourceRoot":"","sources":["../src/builtin-command-names.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,eAAO,MAAM,kBAAkB,YAC9B,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,MAAM,EACN,MAAM,EACN,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,CACG,CAAC;AAEX,eAAO,MAAM,qBAAqB,YACjC,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"builtin-command-names.d.ts","sourceRoot":"","sources":["../src/builtin-command-names.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,eAAO,MAAM,kBAAkB,YAC9B,UAAU,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,MAAM,EACN,MAAM,EACN,SAAS,EACT,OAAO,EACP,OAAO,EACP,WAAW,EACX,SAAS,EACT,MAAM,EACN,OAAO,EACP,OAAO,EACP,OAAO,EACP,QAAQ,EACR,KAAK,EACL,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,CACG,CAAC;AAEX,eAAO,MAAM,qBAAqB,YACjC,QAAQ,EACR,KAAK,EACL,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,QAAQ,EACR,WAAW,EACX,UAAU,CACD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builtin-command-names.js","sourceRoot":"","sources":["../src/builtin-command-names.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,UAAU;IACV,OAAO;IACP,MAAM;IACN,UAAU;IACV,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACP,WAAW;IACX,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;CACG,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,QAAQ;IACR,
|
|
1
|
+
{"version":3,"file":"builtin-command-names.js","sourceRoot":"","sources":["../src/builtin-command-names.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,CAAC,MAAM,kBAAkB,GAAG;IACjC,UAAU;IACV,OAAO;IACP,MAAM;IACN,UAAU;IACV,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IACN,MAAM;IACN,SAAS;IACT,OAAO;IACP,OAAO;IACP,WAAW;IACX,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;CACG,CAAC;AAEX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,QAAQ;IACR,KAAK;IACL,UAAU;IACV,SAAS;IACT,gBAAgB;IAChB,QAAQ;IACR,WAAW;IACX,UAAU;CACD,CAAC","sourcesContent":["/** Ordered command IDs shared by the application command registry and the terminal hint grammar. */\nexport const CORE_COMMAND_NAMES = [\n\t\"settings\",\n\t\"model\",\n\t\"tree\",\n\t\"thinking\",\n\t\"scoped-models\",\n\t\"export\",\n\t\"import\",\n\t\"share\",\n\t\"copy\",\n\t\"name\",\n\t\"session\",\n\t\"tools\",\n\t\"tasks\",\n\t\"changelog\",\n\t\"hotkeys\",\n\t\"fork\",\n\t\"clone\",\n\t\"trust\",\n\t\"login\",\n\t\"logout\",\n\t\"new\",\n\t\"compact\",\n\t\"resume\",\n\t\"reload\",\n\t\"exit\",\n\t\"quit\",\n] as const;\n\nexport const BUNDLED_COMMAND_NAMES = [\n\t\"agents\",\n\t\"mcp\",\n\t\"mcp-auth\",\n\t\"curator\",\n\t\"google-account\",\n\t\"search\",\n\t\"websearch\",\n\t\"intercom\",\n] as const;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clickable-hints.d.ts","sourceRoot":"","sources":["../src/clickable-hints.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,KAAK,KAAK,EAAgB,MAAM,WAAW,CAAC;AAGrD,8GAA8G;AAC9G,MAAM,MAAM,UAAU,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;CAAE,GAC7C;IAAE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88
88
|
return parseHintKeys(text).parts;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function hintSpace(char, wholeLine) {
|
|
91
|
+
return (char === " " || (wholeLine && (char === "\t" || (char !== undefined && char >= "\u00a0" && /\p{Zs}/u.test(char)))));
|
|
92
|
+
}
|
|
93
|
+
function hintTokenAt(text, start, wholeLine) {
|
|
91
94
|
if (ARROW_GLYPHS.has(text[start]))
|
|
92
95
|
return text[start];
|
|
93
|
-
let
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
let end = start;
|
|
97
|
+
// No recognized key exceeds `control+option+shift+super+backspace`. One more character proves this
|
|
98
|
+
// speculative token is label text. Explicit key parts, on the other hand, must retain unknown tokens whole.
|
|
99
|
+
const limit = wholeLine ? Math.min(text.length, start + 37) : text.length;
|
|
100
|
+
for (; end < limit; end++) {
|
|
101
|
+
const char = text[end];
|
|
102
|
+
const expectsKey = end - start > 1 && text[end - 1] === "+" && text[end - 2] !== "+";
|
|
103
|
+
if (hintSpace(char, wholeLine) || (ARROW_GLYPHS.has(char) && !expectsKey))
|
|
98
104
|
break;
|
|
99
|
-
if (char === "/" &&
|
|
105
|
+
if (char === "/" && end !== start && !expectsKey)
|
|
100
106
|
break;
|
|
101
|
-
token += char;
|
|
102
107
|
}
|
|
103
|
-
return
|
|
108
|
+
return text.slice(start, end);
|
|
104
109
|
}
|
|
105
110
|
const DIGIT_RANGE = /^[1-9]-[1-9]$/;
|
|
106
|
-
function parseHintKeys(text, bindings) {
|
|
111
|
+
function parseHintKeys(text, bindings, numericList = false) {
|
|
107
112
|
const parts = [];
|
|
113
|
+
const wholeLine = bindings !== undefined;
|
|
108
114
|
// Whole-line parsing is speculative: an invalid member invalidates its entire compact shortcut, not just its tail.
|
|
109
115
|
let groupStart = 0;
|
|
110
116
|
let groupPart = 0;
|
|
111
117
|
let afterSlash = false;
|
|
118
|
+
let crossedHorizontalSpace = false;
|
|
112
119
|
let index = 0;
|
|
113
120
|
while (index < text.length) {
|
|
114
121
|
const start = index;
|
|
115
|
-
if (!afterSlash && text[start - 1]
|
|
122
|
+
if (!afterSlash && hintSpace(text[start - 1], wholeLine)) {
|
|
116
123
|
groupStart = start;
|
|
117
124
|
groupPart = parts.length;
|
|
118
125
|
}
|
|
119
|
-
let token = hintTokenAt(text, index);
|
|
126
|
+
let token = hintTokenAt(text, index, wholeLine);
|
|
120
127
|
index += token.length;
|
|
121
128
|
const end = index;
|
|
122
|
-
while (text[index]
|
|
129
|
+
while (hintSpace(text[index], wholeLine))
|
|
123
130
|
index++;
|
|
124
131
|
if (token !== "" && text[index] === "/") {
|
|
125
132
|
let next = index + 1;
|
|
126
|
-
while (text[next]
|
|
133
|
+
while (hintSpace(text[next], wholeLine))
|
|
127
134
|
next++;
|
|
128
135
|
// In `esc / enter` this slash separates keys; in `esc /` the final slash is a key itself.
|
|
129
|
-
const following = index === end ? undefined : hintTokenAt(text, next);
|
|
136
|
+
const following = index === end ? undefined : hintTokenAt(text, next, wholeLine);
|
|
130
137
|
if (following === undefined || DIGIT_RANGE.test(following) || hintKeyId(following) !== undefined)
|
|
131
138
|
index = next;
|
|
132
139
|
}
|
|
133
140
|
const separator = text.slice(end, index);
|
|
141
|
+
// A named key needs no binding lookup. Don't start looking up bare letters in previously inert prose
|
|
142
|
+
// merely because a tab or Unicode space was recognized (e.g. `a destination` or `esc a destination`).
|
|
143
|
+
const inferBare = numericList || (!crossedHorizontalSpace && (text[end] === " " || !hintSpace(text[end], wholeLine)));
|
|
144
|
+
if (wholeLine && /[^ /]/.test(separator))
|
|
145
|
+
crossedHorizontalSpace = true;
|
|
134
146
|
if (token === "") {
|
|
135
147
|
if (parts.length > 0) {
|
|
136
148
|
const last = parts[parts.length - 1];
|
|
@@ -142,12 +154,26 @@ function parseHintKeys(text, bindings) {
|
|
|
142
154
|
continue;
|
|
143
155
|
}
|
|
144
156
|
// In a numbered picker, `1-4` shows two keys: the dash belongs to the first, the label to the last.
|
|
145
|
-
if (DIGIT_RANGE.test(token) && (!bindings || bindings.includes(token[0]))) {
|
|
157
|
+
if (DIGIT_RANGE.test(token) && (!bindings || (inferBare && bindings.includes(token[0])))) {
|
|
146
158
|
parts.push({ text: token.slice(0, 2), key: token[0] });
|
|
147
159
|
token = token[2];
|
|
148
160
|
}
|
|
149
161
|
const key = hintKeyId(token);
|
|
150
|
-
if (bindings &&
|
|
162
|
+
if (bindings &&
|
|
163
|
+
!(key && (key.length > 1 || (inferBare && bindings.includes(key)) || (key === "/" && parts.length > 0)))) {
|
|
164
|
+
// `esc / a destination`: we now know that `a` starts the label rather than naming a key. The
|
|
165
|
+
// provisional separator between the two spaces is itself the last key. Don't read the binding twice.
|
|
166
|
+
if (numericList && /^\d$/.test(token))
|
|
167
|
+
return { parts: [], label: text };
|
|
168
|
+
if (afterSlash && key?.length === 1) {
|
|
169
|
+
const last = parts[parts.length - 1];
|
|
170
|
+
const slash = last.text.lastIndexOf("/");
|
|
171
|
+
if (hintSpace(last.text[slash - 1], true) && hintSpace(last.text[slash + 1], true)) {
|
|
172
|
+
parts[parts.length - 1] = { ...last, text: last.text.slice(0, slash) };
|
|
173
|
+
parts.push({ text: last.text.slice(slash), key: "/" });
|
|
174
|
+
return { parts, label: text.slice(start) };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
151
177
|
return { parts: parts.slice(0, groupPart), label: text.slice(groupStart) };
|
|
152
178
|
}
|
|
153
179
|
afterSlash = separator.includes("/");
|
|
@@ -157,6 +183,33 @@ function parseHintKeys(text, bindings) {
|
|
|
157
183
|
? { parts: parts.slice(0, groupPart), label: text.slice(groupStart) }
|
|
158
184
|
: { parts, label: "" };
|
|
159
185
|
}
|
|
186
|
+
/** Does the slash after a numeric prefix continue a complete list containing a named key? No binding reads here:
|
|
187
|
+
* a ratio followed by ordinary text (even `esc/not-a-key`) must stay inert without consulting caller code. */
|
|
188
|
+
function hasMixedKeySuffix(text, start) {
|
|
189
|
+
let named = false;
|
|
190
|
+
let index = start;
|
|
191
|
+
while (index < text.length) {
|
|
192
|
+
while (hintSpace(text[index], true))
|
|
193
|
+
index++;
|
|
194
|
+
const token = hintTokenAt(text, index, true);
|
|
195
|
+
const key = hintKeyId(token);
|
|
196
|
+
if (key === undefined && !DIGIT_RANGE.test(token))
|
|
197
|
+
return false;
|
|
198
|
+
if (key && key.length > 1)
|
|
199
|
+
named = true;
|
|
200
|
+
index += token.length;
|
|
201
|
+
const end = index;
|
|
202
|
+
while (hintSpace(text[index], true))
|
|
203
|
+
index++;
|
|
204
|
+
if (text[index] === "/")
|
|
205
|
+
index++;
|
|
206
|
+
else if (index === text.length || index !== end)
|
|
207
|
+
return named;
|
|
208
|
+
else if (!ARROW_GLYPHS.has(text[index]))
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return false; // a trailing separator is not another named key
|
|
212
|
+
}
|
|
160
213
|
/** A hint for `keyText`, such as `pgup/pgdn`, and `label`, each key running when its text is clicked. */
|
|
161
214
|
export function clickableKeyTextHint(keyText, label) {
|
|
162
215
|
return clickableKeysHint(hintKeyParts(keyText), label);
|
|
@@ -173,9 +226,12 @@ export function clickableHintText(text, bindings) {
|
|
|
173
226
|
if (command && (CORE_COMMANDS.has(command) || bundledCommandLookups.get(getKeybindings())?.(command))) {
|
|
174
227
|
return lead + slashCommandHint(body);
|
|
175
228
|
}
|
|
176
|
-
|
|
229
|
+
const ratio = /^(\d+(?:\s*\/\s*\d+)+)(?:([\t\p{Zs}]+\/)|(?=\s|$))/u.exec(body);
|
|
230
|
+
if (ratio &&
|
|
231
|
+
(!ratio[2] || /\d\d|[^\d/\t\p{Zs}]/u.test(ratio[1]) || !hasMixedKeySuffix(body, ratio[0].length))) {
|
|
177
232
|
return segment;
|
|
178
|
-
|
|
233
|
+
}
|
|
234
|
+
const { parts, label } = parseHintKeys(body, configured, ratio !== null);
|
|
179
235
|
return lead + clickableKeysHint(parts, label);
|
|
180
236
|
})
|
|
181
237
|
.join(" · ");
|
|
@@ -1 +1 @@
|
|
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,YAAY,CAAC,KAAsC,EAAE,MAAc;IAClF,OAAO,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;AACjF,CAAC;AAED,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC/B,OAAO,mBAAmB,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,mBAAmB,CAAI,MAAe;IACrD,mBAAmB,EAAE,CAAC;IACtB,IAAI,CAAC;QACJ,OAAO,MAAM,EAAE,CAAC;IACjB,CAAC;YAAS,CAAC;QACV,mBAAmB,EAAE,CAAC;IACvB,CAAC;AACF,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Clickable key hints. A hint such as `esc cancel` is drawn with zero-width markers around it that name what a click on\n * it runs: a key, which the renderer feeds to the input path as if it were pressed, or a slash command. The fullscreen\n * renderer strips the markers before writing a frame and remembers where each hint was painted.\n */\n\nimport { CORE_COMMAND_NAMES } from \"./builtin-command-names.ts\";\nimport { getKeybindings, type KeybindingsManager } from \"./keybindings.ts\";\nimport { type KeyId, keyInputData } from \"./keys.ts\";\nimport { extractAnsiCode, HINT_CLOSE, HINT_OPEN, visibleWidth } from \"./utils.ts\";\n\n/** What a click on a hint runs: a key, exactly as if it were pressed, or a slash command such as `/tasks`. */\nexport type HintAction =\n\t| { readonly kind: \"key\"; readonly key: KeyId }\n\t| { readonly kind: \"command\"; readonly command: string };\n\n/** Where a hint was painted on a row, in columns `[start, end)`, and what a click on it runs. */\nexport interface HintSpan {\n\treadonly start: number;\n\treadonly end: number;\n\treadonly action: HintAction;\n}\n\n/** One key a hint names, and the text that names it, such as `pgup/` for the first key of `pgup/pgdn`. */\nexport interface HintKeyPart {\n\treadonly text: string;\n\treadonly key?: KeyId;\n}\n\nconst CONTROL_CHARACTERS = /[\\u0000-\\u001f\\u007f-\\u009f]/g;\n\nexport function keyHintAction(key: KeyId): HintAction {\n\treturn { kind: \"key\", key };\n}\n\nexport function commandHintAction(command: string): HintAction {\n\treturn { kind: \"command\", command };\n}\n\nfunction encodeAction(action: HintAction): string {\n\tconst payload = action.kind === \"key\" ? `k:${action.key}` : `c:${action.command}`;\n\treturn payload.replace(CONTROL_CHARACTERS, \"\");\n}\n\nfunction decodeAction(payload: string): HintAction | undefined {\n\tconst value = payload.slice(2);\n\tif (value === \"\") return undefined;\n\tif (payload.startsWith(\"k:\")) return { kind: \"key\", key: value as KeyId };\n\tif (payload.startsWith(\"c:\")) return { kind: \"command\", command: value };\n\treturn undefined;\n}\n\n/**\n * `text` marked as a hint that a click runs `action`. The markers take no columns, so widths, truncation and wrapping\n * are unchanged; text with no action is returned as it is.\n */\nexport function clickableHint(text: string, action: HintAction | undefined): string {\n\tif (action === undefined || text === \"\") return text;\n\treturn `${HINT_OPEN}${encodeAction(action)}\\x07${text}${HINT_CLOSE}`;\n}\n\n/**\n * A hint naming one or more keys, such as `pgup/pgdn scroll`: the text of each key runs that key, and `label` runs the\n * last one, so a hint that names two keys acts by the half clicked. A part with no key is drawn without an action.\n */\nexport function clickableKeysHint(parts: readonly HintKeyPart[], label = \"\"): string {\n\tif (parts.length === 0) return label;\n\treturn parts\n\t\t.map((part, index) =>\n\t\t\tclickableHint(\n\t\t\t\tindex === parts.length - 1 ? part.text + label : part.text,\n\t\t\t\tpart.key === undefined ? undefined : keyHintAction(part.key),\n\t\t\t),\n\t\t)\n\t\t.join(\"\");\n}\n\nconst ARROW_GLYPHS = new Set([\"↑\", \"↓\", \"←\", \"→\"]);\nconst CORE_COMMANDS = new Set<string>(CORE_COMMAND_NAMES);\nconst bundledCommandLookups = new WeakMap<KeybindingsManager, (name: string) => boolean>();\n\n/** Resolve bundled command hints against the live registrations of the session that owns these bindings. */\nexport function bindBundledHintCommands(bindings: KeybindingsManager, isRegistered: (name: string) => boolean): void {\n\tbundledCommandLookups.set(bindings, isRegistered);\n}\n\n/** Key names a hint shows, by the key id they stand for. */\nconst HINT_KEY_IDS: Record<string, string> = {\n\t\"↑\": \"up\",\n\t\"↓\": \"down\",\n\t\"←\": \"left\",\n\t\"→\": \"right\",\n\tesc: \"escape\",\n\t\"↵\": \"enter\",\n\treturn: \"enter\",\n\tpgup: \"pageUp\",\n\tpgdn: \"pageDown\",\n\tpageup: \"pageUp\",\n\tpagedown: \"pageDown\",\n\tdel: \"delete\",\n\tcontrol: \"ctrl\",\n\toption: \"alt\",\n};\n\n/** The key id a hint's name for a key stands for, such as `pageUp` for `pgup`; undefined when no key is named. */\nexport function hintKeyId(name: string): KeyId | undefined {\n\tconst id = name\n\t\t.split(\"+\")\n\t\t.map((part) => HINT_KEY_IDS[part.toLowerCase()] ?? (part.length === 1 ? part : part.toLowerCase()))\n\t\t.join(\"+\");\n\treturn keyInputData(id as KeyId) === undefined ? undefined : (id as KeyId);\n}\n\n/**\n * A hint's key text, such as `pgup/pgdn`, `↑↓` or `esc/←`, split by key: each part keeps its text and the separator\n * after it, so the parts read as the text did, and names the key a click on it presses.\n */\nexport function hintKeyParts(text: string): HintKeyPart[] {\n\treturn parseHintKeys(text).parts;\n}\n\nfunction hintTokenAt(text: string, start: number): string {\n\tif (ARROW_GLYPHS.has(text[start]!)) return text[start]!;\n\tlet token = \"\";\n\tfor (let index = start; index < text.length; index++) {\n\t\tconst char = text[index]!;\n\t\tconst expectsKey = token.length > 1 && token.endsWith(\"+\") && !token.endsWith(\"++\");\n\t\tif (char === \" \" || (ARROW_GLYPHS.has(char) && !expectsKey)) break;\n\t\tif (char === \"/\" && token !== \"\" && !expectsKey) break;\n\t\ttoken += char;\n\t}\n\treturn token;\n}\n\nconst DIGIT_RANGE = /^[1-9]-[1-9]$/;\n\nfunction parseHintKeys(text: string, bindings?: readonly KeyId[]): { parts: HintKeyPart[]; label: string } {\n\tconst parts: HintKeyPart[] = [];\n\t// Whole-line parsing is speculative: an invalid member invalidates its entire compact shortcut, not just its tail.\n\tlet groupStart = 0;\n\tlet groupPart = 0;\n\tlet afterSlash = false;\n\tlet index = 0;\n\twhile (index < text.length) {\n\t\tconst start = index;\n\t\tif (!afterSlash && text[start - 1] === \" \") {\n\t\t\tgroupStart = start;\n\t\t\tgroupPart = parts.length;\n\t\t}\n\t\tlet token = hintTokenAt(text, index);\n\t\tindex += token.length;\n\t\tconst end = index;\n\t\twhile (text[index] === \" \") index++;\n\t\tif (token !== \"\" && text[index] === \"/\") {\n\t\t\tlet next = index + 1;\n\t\t\twhile (text[next] === \" \") next++;\n\t\t\t// In `esc / enter` this slash separates keys; in `esc /` the final slash is a key itself.\n\t\t\tconst following = index === end ? undefined : hintTokenAt(text, next);\n\t\t\tif (following === undefined || DIGIT_RANGE.test(following) || hintKeyId(following) !== undefined) index = next;\n\t\t}\n\t\tconst separator = text.slice(end, index);\n\t\tif (token === \"\") {\n\t\t\tif (parts.length > 0) {\n\t\t\t\tconst last = parts[parts.length - 1]!;\n\t\t\t\tparts[parts.length - 1] = { ...last, text: last.text + separator };\n\t\t\t} else {\n\t\t\t\tparts.push({ text: separator });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\t// In a numbered picker, `1-4` shows two keys: the dash belongs to the first, the label to the last.\n\t\tif (DIGIT_RANGE.test(token) && (!bindings || bindings.includes(token[0] as KeyId))) {\n\t\t\tparts.push({ text: token.slice(0, 2), key: token[0] as KeyId });\n\t\t\ttoken = token[2]!;\n\t\t}\n\t\tconst key = hintKeyId(token);\n\t\tif (bindings && !(key && (key.length > 1 || bindings.includes(key) || (key === \"/\" && parts.length > 0)))) {\n\t\t\treturn { parts: parts.slice(0, groupPart), label: text.slice(groupStart) };\n\t\t}\n\t\tafterSlash = separator.includes(\"/\");\n\t\tparts.push(key === undefined ? { text: token + separator } : { text: token + separator, key });\n\t}\n\treturn bindings && afterSlash\n\t\t? { parts: parts.slice(0, groupPart), label: text.slice(groupStart) }\n\t\t: { parts, label: \"\" };\n}\n\n/** A hint for `keyText`, such as `pgup/pgdn`, and `label`, each key running when its text is clicked. */\nexport function clickableKeyTextHint(keyText: string, label: string): string {\n\treturn clickableKeysHint(hintKeyParts(keyText), label);\n}\n\n/**\n * A hint line written as text, such as `↑↓ select · ↵ open · esc close`: each ` · `-separated segment that starts with\n * a complete named key (or a modified key) runs it. Bare letters, digits and punctuation must be listed in `bindings`,\n * except a literal slash following a recognized key. Every member of a compact shortcut must be recognized. Numeric\n * ratios stay plain even with digit bindings. Use {@link clickableKeyTextHint} when the key text is known separately.\n * Built-in slash commands such as `/tasks to manage` run the command. Use {@link slashCommandHint} for custom commands.\n */\nexport function clickableHintText(text: string): string;\nexport function clickableHintText(text: string, bindings: readonly KeyId[]): string;\nexport function clickableHintText(text: string, bindings?: readonly KeyId[]): string {\n\t// Passing the one-argument builder to Array.map supplies a numeric index, not a binding list.\n\tconst configured = Array.isArray(bindings) ? bindings : [];\n\treturn text\n\t\t.split(\" · \")\n\t\t.map((segment) => {\n\t\t\tconst lead = /^\\s*/.exec(segment)?.[0] ?? \"\";\n\t\t\tconst body = segment.slice(lead.length);\n\t\t\tconst command = /^\\/([\\w:-]+)(?:\\s|$)/.exec(body)?.[1];\n\t\t\tif (command && (CORE_COMMANDS.has(command) || bundledCommandLookups.get(getKeybindings())?.(command))) {\n\t\t\t\treturn lead + slashCommandHint(body);\n\t\t\t}\n\t\t\tif (/^\\d+(?:\\s*\\/\\s*\\d+)+(?:\\s|$)/.test(body)) return segment;\n\t\t\tconst { parts, label } = parseHintKeys(body, configured);\n\t\t\treturn lead + clickableKeysHint(parts, label);\n\t\t})\n\t\t.join(\" · \");\n}\n\n/** A hint naming a slash command, such as `/tasks to manage`, that runs the command when clicked. */\nexport function slashCommandHint(text: string): string {\n\tconst command = /^\\/[\\w:-]+/.exec(text)?.[0];\n\treturn command === undefined ? text : clickableHint(text, commandHintAction(command));\n}\n\n/** Whether `line` has hint markers. */\nexport function hasHintMarkers(line: string): boolean {\n\treturn line.includes(HINT_OPEN) || line.includes(HINT_CLOSE);\n}\n\n/** `line` without its hint markers. */\nexport function stripHintMarkers(line: string): string {\n\treturn hasHintMarkers(line) ? readHintSpans(line).line : line;\n}\n\n/**\n * `line` without its hint markers, and the columns each marked hint covers. A hint whose closing marker was cut off,\n * by truncation for example, ends at the end of the line; a closing marker whose opening one was cut off is dropped.\n */\nexport function readHintSpans(line: string): { readonly line: string; readonly spans: readonly HintSpan[] } {\n\tif (!hasHintMarkers(line)) return { line, spans: [] };\n\tconst spans: HintSpan[] = [];\n\tlet text = \"\";\n\tlet column = 0;\n\tlet open: { start: number; action: HintAction | undefined } | undefined;\n\tconst close = () => {\n\t\tif (open?.action !== undefined && column > open.start)\n\t\t\tspans.push({ start: open.start, end: column, action: open.action });\n\t\topen = undefined;\n\t};\n\tlet index = 0;\n\twhile (index < line.length) {\n\t\tconst ansi = line.charCodeAt(index) === 0x1b ? extractAnsiCode(line, index) : null;\n\t\tif (ansi) {\n\t\t\tindex += ansi.length;\n\t\t\tif (ansi.code.startsWith(HINT_OPEN)) {\n\t\t\t\tclose();\n\t\t\t\tconst payload = ansi.code.slice(HINT_OPEN.length).replace(/(?:\\x07|\\x1b\\\\)$/, \"\");\n\t\t\t\topen = { start: column, action: decodeAction(payload) };\n\t\t\t} else if (ansi.code === HINT_CLOSE) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\ttext += ansi.code;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tlet next = line.indexOf(\"\\x1b\", index + 1);\n\t\tif (next === -1) next = line.length;\n\t\tconst chunk = line.slice(index, next);\n\t\ttext += chunk;\n\t\tcolumn += visibleWidth(chunk);\n\t\tindex = next;\n\t}\n\tclose();\n\treturn { line: text, spans };\n}\n\n/** The action of the hint painted at `column`, among a row's `spans`. */\nexport function hintActionAt(spans: readonly HintSpan[] | undefined, column: number): HintAction | undefined {\n\treturn spans?.find((span) => column >= span.start && column < span.end)?.action;\n}\n\nlet hintActivationDepth = 0;\n\n/**\n * Whether the input being handled was sent by a click on a key hint. A key that acts only on an empty prompt, such as\n * `?` for the keys of a screen, acts for a click whatever the prompt holds: a click cannot be typing.\n */\nexport function isHintActivation(): boolean {\n\treturn hintActivationDepth > 0;\n}\n\n/** Run `handle` as the input of a click on a key hint; see {@link isHintActivation}. */\nexport function runAsHintActivation<T>(handle: () => T): T {\n\thintActivationDepth++;\n\ttry {\n\t\treturn handle();\n\t} finally {\n\t\thintActivationDepth--;\n\t}\n}\n\n/** The terminal input a click on a key hint sends for `action`, or undefined for a command or an unknown key. */\nexport function hintKeyInput(action: HintAction): string | undefined {\n\treturn action.kind === \"key\" ? keyInputData(action.key) : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"clickable-hints.js","sourceRoot":"","sources":["../src/clickable-hints.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,cAAc,EAA2B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAc,YAAY,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAoBlF,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAE3D,MAAM,UAAU,aAAa,CAAC,GAAU;IACvC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAe;IAChD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;AACrC,CAAC;AAED,SAAS,YAAY,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KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACtC,IAAI,IAAI,KAAK,CAAC;QACd,MAAM,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,GAAG,IAAI,CAAC;IACd,CAAC;IACD,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC9B,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,YAAY,CAAC,KAAsC,EAAE,MAAc;IAClF,OAAO,KAAK,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;AACjF,CAAC;AAED,IAAI,mBAAmB,GAAG,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC/B,OAAO,mBAAmB,GAAG,CAAC,CAAC;AAChC,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,mBAAmB,CAAI,MAAe;IACrD,mBAAmB,EAAE,CAAC;IACtB,IAAI,CAAC;QACJ,OAAO,MAAM,EAAE,CAAC;IACjB,CAAC;YAAS,CAAC;QACV,mBAAmB,EAAE,CAAC;IACvB,CAAC;AACF,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC","sourcesContent":["/**\n * Clickable key hints. A hint such as `esc cancel` is drawn with zero-width markers around it that name what a click on\n * it runs: a key, which the renderer feeds to the input path as if it were pressed, or a slash command. The fullscreen\n * renderer strips the markers before writing a frame and remembers where each hint was painted.\n */\n\nimport { CORE_COMMAND_NAMES } from \"./builtin-command-names.ts\";\nimport { getKeybindings, type KeybindingsManager } from \"./keybindings.ts\";\nimport { type KeyId, keyInputData } from \"./keys.ts\";\nimport { extractAnsiCode, HINT_CLOSE, HINT_OPEN, visibleWidth } from \"./utils.ts\";\n\n/** What a click on a hint runs: a key, exactly as if it were pressed, or a slash command such as `/tasks`. */\nexport type HintAction =\n\t| { readonly kind: \"key\"; readonly key: KeyId }\n\t| { readonly kind: \"command\"; readonly command: string };\n\n/** Where a hint was painted on a row, in columns `[start, end)`, and what a click on it runs. */\nexport interface HintSpan {\n\treadonly start: number;\n\treadonly end: number;\n\treadonly action: HintAction;\n}\n\n/** One key a hint names, and the text that names it, such as `pgup/` for the first key of `pgup/pgdn`. */\nexport interface HintKeyPart {\n\treadonly text: string;\n\treadonly key?: KeyId;\n}\n\nconst CONTROL_CHARACTERS = /[\\u0000-\\u001f\\u007f-\\u009f]/g;\n\nexport function keyHintAction(key: KeyId): HintAction {\n\treturn { kind: \"key\", key };\n}\n\nexport function commandHintAction(command: string): HintAction {\n\treturn { kind: \"command\", command };\n}\n\nfunction encodeAction(action: HintAction): string {\n\tconst payload = action.kind === \"key\" ? `k:${action.key}` : `c:${action.command}`;\n\treturn payload.replace(CONTROL_CHARACTERS, \"\");\n}\n\nfunction decodeAction(payload: string): HintAction | undefined {\n\tconst value = payload.slice(2);\n\tif (value === \"\") return undefined;\n\tif (payload.startsWith(\"k:\")) return { kind: \"key\", key: value as KeyId };\n\tif (payload.startsWith(\"c:\")) return { kind: \"command\", command: value };\n\treturn undefined;\n}\n\n/**\n * `text` marked as a hint that a click runs `action`. The markers take no columns, so widths, truncation and wrapping\n * are unchanged; text with no action is returned as it is.\n */\nexport function clickableHint(text: string, action: HintAction | undefined): string {\n\tif (action === undefined || text === \"\") return text;\n\treturn `${HINT_OPEN}${encodeAction(action)}\\x07${text}${HINT_CLOSE}`;\n}\n\n/**\n * A hint naming one or more keys, such as `pgup/pgdn scroll`: the text of each key runs that key, and `label` runs the\n * last one, so a hint that names two keys acts by the half clicked. A part with no key is drawn without an action.\n */\nexport function clickableKeysHint(parts: readonly HintKeyPart[], label = \"\"): string {\n\tif (parts.length === 0) return label;\n\treturn parts\n\t\t.map((part, index) =>\n\t\t\tclickableHint(\n\t\t\t\tindex === parts.length - 1 ? part.text + label : part.text,\n\t\t\t\tpart.key === undefined ? undefined : keyHintAction(part.key),\n\t\t\t),\n\t\t)\n\t\t.join(\"\");\n}\n\nconst ARROW_GLYPHS = new Set([\"↑\", \"↓\", \"←\", \"→\"]);\nconst CORE_COMMANDS = new Set<string>(CORE_COMMAND_NAMES);\nconst bundledCommandLookups = new WeakMap<KeybindingsManager, (name: string) => boolean>();\n\n/** Resolve bundled command hints against the live registrations of the session that owns these bindings. */\nexport function bindBundledHintCommands(bindings: KeybindingsManager, isRegistered: (name: string) => boolean): void {\n\tbundledCommandLookups.set(bindings, isRegistered);\n}\n\n/** Key names a hint shows, by the key id they stand for. */\nconst HINT_KEY_IDS: Record<string, string> = {\n\t\"↑\": \"up\",\n\t\"↓\": \"down\",\n\t\"←\": \"left\",\n\t\"→\": \"right\",\n\tesc: \"escape\",\n\t\"↵\": \"enter\",\n\treturn: \"enter\",\n\tpgup: \"pageUp\",\n\tpgdn: \"pageDown\",\n\tpageup: \"pageUp\",\n\tpagedown: \"pageDown\",\n\tdel: \"delete\",\n\tcontrol: \"ctrl\",\n\toption: \"alt\",\n};\n\n/** The key id a hint's name for a key stands for, such as `pageUp` for `pgup`; undefined when no key is named. */\nexport function hintKeyId(name: string): KeyId | undefined {\n\tconst id = name\n\t\t.split(\"+\")\n\t\t.map((part) => HINT_KEY_IDS[part.toLowerCase()] ?? (part.length === 1 ? part : part.toLowerCase()))\n\t\t.join(\"+\");\n\treturn keyInputData(id as KeyId) === undefined ? undefined : (id as KeyId);\n}\n\n/**\n * A hint's key text, such as `pgup/pgdn`, `↑↓` or `esc/←`, split by key: each part keeps its text and the separator\n * after it, so the parts read as the text did, and names the key a click on it presses.\n */\nexport function hintKeyParts(text: string): HintKeyPart[] {\n\treturn parseHintKeys(text).parts;\n}\n\nfunction hintSpace(char: string | undefined, wholeLine: boolean): boolean {\n\treturn (\n\t\tchar === \" \" || (wholeLine && (char === \"\\t\" || (char !== undefined && char >= \"\\u00a0\" && /\\p{Zs}/u.test(char))))\n\t);\n}\n\nfunction hintTokenAt(text: string, start: number, wholeLine: boolean): string {\n\tif (ARROW_GLYPHS.has(text[start]!)) return text[start]!;\n\tlet end = start;\n\t// No recognized key exceeds `control+option+shift+super+backspace`. One more character proves this\n\t// speculative token is label text. Explicit key parts, on the other hand, must retain unknown tokens whole.\n\tconst limit = wholeLine ? Math.min(text.length, start + 37) : text.length;\n\tfor (; end < limit; end++) {\n\t\tconst char = text[end]!;\n\t\tconst expectsKey = end - start > 1 && text[end - 1] === \"+\" && text[end - 2] !== \"+\";\n\t\tif (hintSpace(char, wholeLine) || (ARROW_GLYPHS.has(char) && !expectsKey)) break;\n\t\tif (char === \"/\" && end !== start && !expectsKey) break;\n\t}\n\treturn text.slice(start, end);\n}\n\nconst DIGIT_RANGE = /^[1-9]-[1-9]$/;\n\nfunction parseHintKeys(\n\ttext: string,\n\tbindings?: readonly KeyId[],\n\tnumericList = false,\n): { parts: HintKeyPart[]; label: string } {\n\tconst parts: HintKeyPart[] = [];\n\tconst wholeLine = bindings !== undefined;\n\t// Whole-line parsing is speculative: an invalid member invalidates its entire compact shortcut, not just its tail.\n\tlet groupStart = 0;\n\tlet groupPart = 0;\n\tlet afterSlash = false;\n\tlet crossedHorizontalSpace = false;\n\tlet index = 0;\n\twhile (index < text.length) {\n\t\tconst start = index;\n\t\tif (!afterSlash && hintSpace(text[start - 1], wholeLine)) {\n\t\t\tgroupStart = start;\n\t\t\tgroupPart = parts.length;\n\t\t}\n\t\tlet token = hintTokenAt(text, index, wholeLine);\n\t\tindex += token.length;\n\t\tconst end = index;\n\t\twhile (hintSpace(text[index], wholeLine)) index++;\n\t\tif (token !== \"\" && text[index] === \"/\") {\n\t\t\tlet next = index + 1;\n\t\t\twhile (hintSpace(text[next], wholeLine)) next++;\n\t\t\t// In `esc / enter` this slash separates keys; in `esc /` the final slash is a key itself.\n\t\t\tconst following = index === end ? undefined : hintTokenAt(text, next, wholeLine);\n\t\t\tif (following === undefined || DIGIT_RANGE.test(following) || hintKeyId(following) !== undefined) index = next;\n\t\t}\n\t\tconst separator = text.slice(end, index);\n\t\t// A named key needs no binding lookup. Don't start looking up bare letters in previously inert prose\n\t\t// merely because a tab or Unicode space was recognized (e.g. `a destination` or `esc a destination`).\n\t\tconst inferBare =\n\t\t\tnumericList || (!crossedHorizontalSpace && (text[end] === \" \" || !hintSpace(text[end], wholeLine)));\n\t\tif (wholeLine && /[^ /]/.test(separator)) crossedHorizontalSpace = true;\n\t\tif (token === \"\") {\n\t\t\tif (parts.length > 0) {\n\t\t\t\tconst last = parts[parts.length - 1]!;\n\t\t\t\tparts[parts.length - 1] = { ...last, text: last.text + separator };\n\t\t\t} else {\n\t\t\t\tparts.push({ text: separator });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\t// In a numbered picker, `1-4` shows two keys: the dash belongs to the first, the label to the last.\n\t\tif (DIGIT_RANGE.test(token) && (!bindings || (inferBare && bindings.includes(token[0] as KeyId)))) {\n\t\t\tparts.push({ text: token.slice(0, 2), key: token[0] as KeyId });\n\t\t\ttoken = token[2]!;\n\t\t}\n\t\tconst key = hintKeyId(token);\n\t\tif (\n\t\t\tbindings &&\n\t\t\t!(key && (key.length > 1 || (inferBare && bindings.includes(key)) || (key === \"/\" && parts.length > 0)))\n\t\t) {\n\t\t\t// `esc / a destination`: we now know that `a` starts the label rather than naming a key. The\n\t\t\t// provisional separator between the two spaces is itself the last key. Don't read the binding twice.\n\t\t\tif (numericList && /^\\d$/.test(token)) return { parts: [], label: text };\n\t\t\tif (afterSlash && key?.length === 1) {\n\t\t\t\tconst last = parts[parts.length - 1]!;\n\t\t\t\tconst slash = last.text.lastIndexOf(\"/\");\n\t\t\t\tif (hintSpace(last.text[slash - 1], true) && hintSpace(last.text[slash + 1], true)) {\n\t\t\t\t\tparts[parts.length - 1] = { ...last, text: last.text.slice(0, slash) };\n\t\t\t\t\tparts.push({ text: last.text.slice(slash), key: \"/\" });\n\t\t\t\t\treturn { parts, label: text.slice(start) };\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { parts: parts.slice(0, groupPart), label: text.slice(groupStart) };\n\t\t}\n\t\tafterSlash = separator.includes(\"/\");\n\t\tparts.push(key === undefined ? { text: token + separator } : { text: token + separator, key });\n\t}\n\treturn bindings && afterSlash\n\t\t? { parts: parts.slice(0, groupPart), label: text.slice(groupStart) }\n\t\t: { parts, label: \"\" };\n}\n\n/** Does the slash after a numeric prefix continue a complete list containing a named key? No binding reads here:\n * a ratio followed by ordinary text (even `esc/not-a-key`) must stay inert without consulting caller code. */\nfunction hasMixedKeySuffix(text: string, start: number): boolean {\n\tlet named = false;\n\tlet index = start;\n\twhile (index < text.length) {\n\t\twhile (hintSpace(text[index], true)) index++;\n\t\tconst token = hintTokenAt(text, index, true);\n\t\tconst key = hintKeyId(token);\n\t\tif (key === undefined && !DIGIT_RANGE.test(token)) return false;\n\t\tif (key && key.length > 1) named = true;\n\t\tindex += token.length;\n\t\tconst end = index;\n\t\twhile (hintSpace(text[index], true)) index++;\n\t\tif (text[index] === \"/\") index++;\n\t\telse if (index === text.length || index !== end) return named;\n\t\telse if (!ARROW_GLYPHS.has(text[index]!)) return false;\n\t}\n\treturn false; // a trailing separator is not another named key\n}\n\n/** A hint for `keyText`, such as `pgup/pgdn`, and `label`, each key running when its text is clicked. */\nexport function clickableKeyTextHint(keyText: string, label: string): string {\n\treturn clickableKeysHint(hintKeyParts(keyText), label);\n}\n\n/**\n * A hint line written as text, such as `↑↓ select · ↵ open · esc close`: each ` · `-separated segment that starts with\n * a complete named key (or a modified key) runs it. Bare letters, digits and punctuation must be listed in `bindings`,\n * except a literal slash following a recognized key. Every member of a compact shortcut must be recognized. Numeric\n * ratios stay plain even with digit bindings. Use {@link clickableKeyTextHint} when the key text is known separately.\n * Built-in slash commands such as `/tasks to manage` run the command. Use {@link slashCommandHint} for custom commands.\n */\nexport function clickableHintText(text: string): string;\nexport function clickableHintText(text: string, bindings: readonly KeyId[]): string;\nexport function clickableHintText(text: string, bindings?: readonly KeyId[]): string {\n\t// Passing the one-argument builder to Array.map supplies a numeric index, not a binding list.\n\tconst configured = Array.isArray(bindings) ? bindings : [];\n\treturn text\n\t\t.split(\" · \")\n\t\t.map((segment) => {\n\t\t\tconst lead = /^\\s*/.exec(segment)?.[0] ?? \"\";\n\t\t\tconst body = segment.slice(lead.length);\n\t\t\tconst command = /^\\/([\\w:-]+)(?:\\s|$)/.exec(body)?.[1];\n\t\t\tif (command && (CORE_COMMANDS.has(command) || bundledCommandLookups.get(getKeybindings())?.(command))) {\n\t\t\t\treturn lead + slashCommandHint(body);\n\t\t\t}\n\t\t\tconst ratio = /^(\\d+(?:\\s*\\/\\s*\\d+)+)(?:([\\t\\p{Zs}]+\\/)|(?=\\s|$))/u.exec(body);\n\t\t\tif (\n\t\t\t\tratio &&\n\t\t\t\t(!ratio[2] || /\\d\\d|[^\\d/\\t\\p{Zs}]/u.test(ratio[1]!) || !hasMixedKeySuffix(body, ratio[0].length))\n\t\t\t) {\n\t\t\t\treturn segment;\n\t\t\t}\n\t\t\tconst { parts, label } = parseHintKeys(body, configured, ratio !== null);\n\t\t\treturn lead + clickableKeysHint(parts, label);\n\t\t})\n\t\t.join(\" · \");\n}\n\n/** A hint naming a slash command, such as `/tasks to manage`, that runs the command when clicked. */\nexport function slashCommandHint(text: string): string {\n\tconst command = /^\\/[\\w:-]+/.exec(text)?.[0];\n\treturn command === undefined ? text : clickableHint(text, commandHintAction(command));\n}\n\n/** Whether `line` has hint markers. */\nexport function hasHintMarkers(line: string): boolean {\n\treturn line.includes(HINT_OPEN) || line.includes(HINT_CLOSE);\n}\n\n/** `line` without its hint markers. */\nexport function stripHintMarkers(line: string): string {\n\treturn hasHintMarkers(line) ? readHintSpans(line).line : line;\n}\n\n/**\n * `line` without its hint markers, and the columns each marked hint covers. A hint whose closing marker was cut off,\n * by truncation for example, ends at the end of the line; a closing marker whose opening one was cut off is dropped.\n */\nexport function readHintSpans(line: string): { readonly line: string; readonly spans: readonly HintSpan[] } {\n\tif (!hasHintMarkers(line)) return { line, spans: [] };\n\tconst spans: HintSpan[] = [];\n\tlet text = \"\";\n\tlet column = 0;\n\tlet open: { start: number; action: HintAction | undefined } | undefined;\n\tconst close = () => {\n\t\tif (open?.action !== undefined && column > open.start)\n\t\t\tspans.push({ start: open.start, end: column, action: open.action });\n\t\topen = undefined;\n\t};\n\tlet index = 0;\n\twhile (index < line.length) {\n\t\tconst ansi = line.charCodeAt(index) === 0x1b ? extractAnsiCode(line, index) : null;\n\t\tif (ansi) {\n\t\t\tindex += ansi.length;\n\t\t\tif (ansi.code.startsWith(HINT_OPEN)) {\n\t\t\t\tclose();\n\t\t\t\tconst payload = ansi.code.slice(HINT_OPEN.length).replace(/(?:\\x07|\\x1b\\\\)$/, \"\");\n\t\t\t\topen = { start: column, action: decodeAction(payload) };\n\t\t\t} else if (ansi.code === HINT_CLOSE) {\n\t\t\t\tclose();\n\t\t\t} else {\n\t\t\t\ttext += ansi.code;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tlet next = line.indexOf(\"\\x1b\", index + 1);\n\t\tif (next === -1) next = line.length;\n\t\tconst chunk = line.slice(index, next);\n\t\ttext += chunk;\n\t\tcolumn += visibleWidth(chunk);\n\t\tindex = next;\n\t}\n\tclose();\n\treturn { line: text, spans };\n}\n\n/** The action of the hint painted at `column`, among a row's `spans`. */\nexport function hintActionAt(spans: readonly HintSpan[] | undefined, column: number): HintAction | undefined {\n\treturn spans?.find((span) => column >= span.start && column < span.end)?.action;\n}\n\nlet hintActivationDepth = 0;\n\n/**\n * Whether the input being handled was sent by a click on a key hint. A key that acts only on an empty prompt, such as\n * `?` for the keys of a screen, acts for a click whatever the prompt holds: a click cannot be typing.\n */\nexport function isHintActivation(): boolean {\n\treturn hintActivationDepth > 0;\n}\n\n/** Run `handle` as the input of a click on a key hint; see {@link isHintActivation}. */\nexport function runAsHintActivation<T>(handle: () => T): T {\n\thintActivationDepth++;\n\ttry {\n\t\treturn handle();\n\t} finally {\n\t\thintActivationDepth--;\n\t}\n}\n\n/** The terminal input a click on a key hint sends for `action`, or undefined for a command or an unknown key. */\nexport function hintKeyInput(action: HintAction): string | undefined {\n\treturn action.kind === \"key\" ? keyInputData(action.key) : undefined;\n}\n"]}
|
|
@@ -25,6 +25,22 @@ export interface TextChunk {
|
|
|
25
25
|
* @returns Array of chunks with text and position information
|
|
26
26
|
*/
|
|
27
27
|
export declare function wordWrapLine(line: string, maxWidth: number, preSegmented?: Intl.SegmentData[]): TextChunk[];
|
|
28
|
+
declare const editorDraftBrand: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* A prompt's whole state, as {@link Editor.snapshotDraft} took it: its text, cursor and scroll, its paste registry, its
|
|
31
|
+
* undo history and kill ring, and where Up-history browsing stands with the draft it parked. Only
|
|
32
|
+
* {@link Editor.restoreDraft} reads it; restoring it more than once gives the same prompt each time.
|
|
33
|
+
*/
|
|
34
|
+
export interface EditorDraft {
|
|
35
|
+
readonly [editorDraftBrand]: true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The text the reader typed into the prompt `draft` holds, with pastes expanded: while it was browsing Up history,
|
|
39
|
+
* the draft Up parked, not the history entry shown.
|
|
40
|
+
*/
|
|
41
|
+
export declare function editorDraftText(draft: EditorDraft): string;
|
|
42
|
+
/** The state of a prompt nothing was typed into yet: empty, with no undo history, kill ring or Up browsing. */
|
|
43
|
+
export declare function emptyEditorDraft(): EditorDraft;
|
|
28
44
|
/** One key the open @ or / menu offers: the keybindings that trigger it and what it does. */
|
|
29
45
|
export interface EditorAutocompleteHintEntry {
|
|
30
46
|
readonly actions: readonly Keybinding[];
|
|
@@ -116,6 +132,28 @@ export declare class Editor implements Component, Focusable {
|
|
|
116
132
|
* Called after successful submission.
|
|
117
133
|
*/
|
|
118
134
|
addToHistory(text: string): void;
|
|
135
|
+
/**
|
|
136
|
+
* The prompt's whole state, detached: editing on afterwards leaves it as it was. The prompt itself is not changed.
|
|
137
|
+
* Up history is not part of it.
|
|
138
|
+
*/
|
|
139
|
+
snapshotDraft(): EditorDraft;
|
|
140
|
+
/**
|
|
141
|
+
* Put back a prompt {@link snapshotDraft} took, from this editor or another: its text, cursor, paste registry, undo
|
|
142
|
+
* history, kill ring and Up-history browsing. An open completion menu closes. A prompt that was browsing an entry the
|
|
143
|
+
* current Up history no longer has comes back as the draft Up parked. Reports the text to `onChange`, as `setText`
|
|
144
|
+
* does.
|
|
145
|
+
*/
|
|
146
|
+
restoreDraft(draft: EditorDraft): void;
|
|
147
|
+
/**
|
|
148
|
+
* Replace the history up/down walk, newest first as {@link getHistory} returns it, kept as {@link addToHistory}
|
|
149
|
+
* keeps entries. The text and cursor stay as they are; browsing ends, so the shown entry becomes the draft.
|
|
150
|
+
*/
|
|
151
|
+
setHistory(newestFirst: readonly string[]): void;
|
|
152
|
+
/**
|
|
153
|
+
* Add entries older than every one in the history behind it, newest first, kept as {@link addToHistory} keeps
|
|
154
|
+
* entries. Browsing goes on: the entry shown and the draft Down returns to stay where they are.
|
|
155
|
+
*/
|
|
156
|
+
appendOlderHistory(newestFirst: readonly string[]): void;
|
|
119
157
|
private isEditorEmpty;
|
|
120
158
|
private isOnFirstVisualLine;
|
|
121
159
|
private isOnLastVisualLine;
|
|
@@ -293,4 +331,5 @@ export declare class Editor implements Component, Focusable {
|
|
|
293
331
|
isShowingAutocomplete(): boolean;
|
|
294
332
|
private updateAutocomplete;
|
|
295
333
|
}
|
|
334
|
+
export {};
|
|
296
335
|
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../src/components/editor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAA2B,MA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zC;IAED,OAAO,CAAC,yBAAyB;IAYjC,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,kBAAkB;IAKnB,qBAAqB,IAAI,OAAO,CAEtC;IAED,OAAO,CAAC,kBAAkB;CAI1B"}
|
|
@@ -184,6 +184,41 @@ export function wordWrapLine(line, maxWidth, preSegmented) {
|
|
|
184
184
|
}
|
|
185
185
|
return chunks;
|
|
186
186
|
}
|
|
187
|
+
const editorDrafts = new WeakMap();
|
|
188
|
+
/**
|
|
189
|
+
* The text the reader typed into the prompt `draft` holds, with pastes expanded: while it was browsing Up history,
|
|
190
|
+
* the draft Up parked, not the history entry shown.
|
|
191
|
+
*/
|
|
192
|
+
export function editorDraftText(draft) {
|
|
193
|
+
const saved = editorDrafts.get(draft);
|
|
194
|
+
if (saved === undefined)
|
|
195
|
+
return "";
|
|
196
|
+
const state = saved.historyIndex >= 0 && saved.historyDraft !== null ? saved.historyDraft : saved.state;
|
|
197
|
+
let text = state.lines.join("\n");
|
|
198
|
+
for (const [pasteId, pasteContent] of saved.pastes) {
|
|
199
|
+
const markerRegex = new RegExp(`\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`, "g");
|
|
200
|
+
text = text.replace(markerRegex, () => pasteContent);
|
|
201
|
+
}
|
|
202
|
+
return text;
|
|
203
|
+
}
|
|
204
|
+
/** The state of a prompt nothing was typed into yet: empty, with no undo history, kill ring or Up browsing. */
|
|
205
|
+
export function emptyEditorDraft() {
|
|
206
|
+
const draft = Object.freeze({});
|
|
207
|
+
editorDrafts.set(draft, {
|
|
208
|
+
state: { lines: [""], cursorLine: 0, cursorCol: 0 },
|
|
209
|
+
pastes: new Map(),
|
|
210
|
+
pasteCounter: 0,
|
|
211
|
+
undoStack: new UndoStack(),
|
|
212
|
+
killRing: new KillRing(),
|
|
213
|
+
lastAction: null,
|
|
214
|
+
historyIndex: -1,
|
|
215
|
+
historyDraft: null,
|
|
216
|
+
scrollOffset: 0,
|
|
217
|
+
preferredVisualCol: null,
|
|
218
|
+
snappedFromCursorCol: null,
|
|
219
|
+
});
|
|
220
|
+
return draft;
|
|
221
|
+
}
|
|
187
222
|
const SLASH_COMMAND_SELECT_LIST_LAYOUT = {
|
|
188
223
|
minPrimaryColumnWidth: 12,
|
|
189
224
|
maxPrimaryColumnWidth: 32,
|
|
@@ -400,6 +435,81 @@ export class Editor {
|
|
|
400
435
|
this.history.pop();
|
|
401
436
|
}
|
|
402
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* The prompt's whole state, detached: editing on afterwards leaves it as it was. The prompt itself is not changed.
|
|
440
|
+
* Up history is not part of it.
|
|
441
|
+
*/
|
|
442
|
+
snapshotDraft() {
|
|
443
|
+
const draft = Object.freeze({});
|
|
444
|
+
editorDrafts.set(draft, {
|
|
445
|
+
state: structuredClone(this.state),
|
|
446
|
+
pastes: new Map(this.pastes),
|
|
447
|
+
pasteCounter: this.pasteCounter,
|
|
448
|
+
undoStack: this.undoStack.clone(),
|
|
449
|
+
killRing: this.killRing.clone(),
|
|
450
|
+
lastAction: this.lastAction,
|
|
451
|
+
historyIndex: this.historyIndex,
|
|
452
|
+
historyDraft: this.historyDraft === null ? null : structuredClone(this.historyDraft),
|
|
453
|
+
scrollOffset: this.scrollOffset,
|
|
454
|
+
preferredVisualCol: this.preferredVisualCol,
|
|
455
|
+
snappedFromCursorCol: this.snappedFromCursorCol,
|
|
456
|
+
});
|
|
457
|
+
return draft;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Put back a prompt {@link snapshotDraft} took, from this editor or another: its text, cursor, paste registry, undo
|
|
461
|
+
* history, kill ring and Up-history browsing. An open completion menu closes. A prompt that was browsing an entry the
|
|
462
|
+
* current Up history no longer has comes back as the draft Up parked. Reports the text to `onChange`, as `setText`
|
|
463
|
+
* does.
|
|
464
|
+
*/
|
|
465
|
+
restoreDraft(draft) {
|
|
466
|
+
const saved = editorDrafts.get(draft);
|
|
467
|
+
if (saved === undefined)
|
|
468
|
+
return;
|
|
469
|
+
this.cancelAutocomplete();
|
|
470
|
+
this.jumpMode = null;
|
|
471
|
+
const browsing = saved.historyIndex >= 0 && saved.historyIndex < this.history.length;
|
|
472
|
+
// A prompt that browsed a history no longer there comes back as the draft Up parked, not the entry it showed.
|
|
473
|
+
const parked = !browsing && saved.historyIndex >= 0 ? saved.historyDraft : null;
|
|
474
|
+
Object.assign(this.state, structuredClone(parked ?? saved.state));
|
|
475
|
+
this.pastes = new Map(saved.pastes);
|
|
476
|
+
this.pasteCounter = saved.pasteCounter;
|
|
477
|
+
this.undoStack = saved.undoStack.clone();
|
|
478
|
+
this.killRing = saved.killRing.clone();
|
|
479
|
+
this.lastAction = saved.lastAction;
|
|
480
|
+
this.historyIndex = browsing ? saved.historyIndex : -1;
|
|
481
|
+
this.historyDraft = browsing && saved.historyDraft !== null ? structuredClone(saved.historyDraft) : null;
|
|
482
|
+
this.scrollOffset = saved.scrollOffset;
|
|
483
|
+
this.preferredVisualCol = saved.preferredVisualCol;
|
|
484
|
+
this.snappedFromCursorCol = saved.snappedFromCursorCol;
|
|
485
|
+
if (this.onChange) {
|
|
486
|
+
this.onChange(this.getText());
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Replace the history up/down walk, newest first as {@link getHistory} returns it, kept as {@link addToHistory}
|
|
491
|
+
* keeps entries. The text and cursor stay as they are; browsing ends, so the shown entry becomes the draft.
|
|
492
|
+
*/
|
|
493
|
+
setHistory(newestFirst) {
|
|
494
|
+
this.history = [];
|
|
495
|
+
this.exitHistoryBrowsing();
|
|
496
|
+
for (let index = newestFirst.length - 1; index >= 0; index--)
|
|
497
|
+
this.addToHistory(newestFirst[index]);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Add entries older than every one in the history behind it, newest first, kept as {@link addToHistory} keeps
|
|
501
|
+
* entries. Browsing goes on: the entry shown and the draft Down returns to stay where they are.
|
|
502
|
+
*/
|
|
503
|
+
appendOlderHistory(newestFirst) {
|
|
504
|
+
for (const text of newestFirst) {
|
|
505
|
+
if (this.history.length >= 100)
|
|
506
|
+
return;
|
|
507
|
+
const trimmed = text.trim();
|
|
508
|
+
if (!trimmed || this.history.at(-1) === trimmed)
|
|
509
|
+
continue;
|
|
510
|
+
this.history.push(trimmed);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
403
513
|
isEditorEmpty() {
|
|
404
514
|
return this.state.lines.length === 1 && this.state.lines[0] === "";
|
|
405
515
|
}
|