layerbase 0.2.0 → 0.3.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/dist/cli.js +1 -1
- package/dist/commands/interactive.js +92 -69
- package/dist/commands/interactive.js.map +1 -1
- package/dist/lib/commands.js +73 -0
- package/dist/lib/commands.js.map +1 -0
- package/dist/ui/prompt.js +59 -0
- package/dist/ui/prompt.js.map +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ const cli = meow(`
|
|
|
23
23
|
spindb [args...] Run the local spindb CLI (passes args through)
|
|
24
24
|
alias Set up the short lb command (only if it is free)
|
|
25
25
|
|
|
26
|
-
Run with no command for
|
|
26
|
+
Run with no command for the interactive prompt (type /commands). Also lbase.
|
|
27
27
|
|
|
28
28
|
Options
|
|
29
29
|
--print With connect: show connection info, do not exec
|
|
@@ -1,55 +1,43 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { render, Box, Text } from 'ink';
|
|
3
|
+
import { Prompt } from '../ui/prompt.js';
|
|
3
4
|
import { Menu } from '../ui/menu.js';
|
|
4
|
-
import { Header } from '../ui/brand.js';
|
|
5
5
|
import { Connecting } from '../ui/connecting.js';
|
|
6
|
-
import { PressEnter } from '../ui/press-enter.js';
|
|
7
6
|
import { loadCredentials } from '../lib/config.js';
|
|
8
7
|
import { decodeTokenClaims } from '../lib/token.js';
|
|
8
|
+
import { resolveInput, availableCommands } from '../lib/commands.js';
|
|
9
9
|
import { listDatabases } from '../lib/cloud-api.js';
|
|
10
10
|
import { runSpindb } from '../lib/run-spindb.js';
|
|
11
11
|
import { connectToDatabase } from '../commands/connect.js';
|
|
12
|
-
import { lbStatus } from '../lib/alias.js';
|
|
13
12
|
import { App } from '../ui/app.js';
|
|
13
|
+
const ACCENT_ANSI = '\x1b[38;2;124;156;255m';
|
|
14
|
+
const DIM = '\x1b[2m';
|
|
15
|
+
const RESET = '\x1b[0m';
|
|
14
16
|
const BACK = '__back__';
|
|
15
|
-
function
|
|
16
|
-
// Clear the visible screen and home the cursor (scrollback is preserved).
|
|
17
|
-
process.stdout.write('[2J[H');
|
|
18
|
-
}
|
|
19
|
-
function accountLine(creds) {
|
|
17
|
+
function accountText(creds) {
|
|
20
18
|
if (!creds)
|
|
21
|
-
return
|
|
19
|
+
return 'Not signed in';
|
|
22
20
|
const email = decodeTokenClaims(creds.token)?.email;
|
|
23
|
-
return
|
|
21
|
+
return email ? `Signed in as ${email}` : 'Signed in';
|
|
24
22
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
items.push({ label: 'Log in', value: 'login', hint: 'browser sign-in' });
|
|
33
|
-
}
|
|
34
|
-
items.push({ label: 'Run spindb', value: 'spindb', hint: 'local databases' });
|
|
35
|
-
if (loggedIn)
|
|
36
|
-
items.push({ label: 'Log out', value: 'logout' });
|
|
37
|
-
if (lbAvailable) {
|
|
38
|
-
items.push({ label: 'Enable the lb shortcut', value: 'alias' });
|
|
39
|
-
}
|
|
40
|
-
items.push({ label: 'Quit', value: 'quit' });
|
|
41
|
-
return items;
|
|
23
|
+
function printBanner(creds) {
|
|
24
|
+
process.stdout.write(`\n${ACCENT_ANSI}◆ Layerbase${RESET} ${DIM}cloud + local databases${RESET}\n` +
|
|
25
|
+
`${DIM}${accountText(creds)} · type /help to see commands${RESET}\n\n`);
|
|
26
|
+
}
|
|
27
|
+
function printCommands(loggedIn) {
|
|
28
|
+
const lines = availableCommands(loggedIn).map((c) => ` ${DIM}/${RESET}${c.name.padEnd(11)}${DIM}${c.summary}${RESET}`);
|
|
29
|
+
process.stdout.write(`Commands:\n${lines.join('\n')}\n\n`);
|
|
42
30
|
}
|
|
43
|
-
function
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
function promptOnce(creds) {
|
|
32
|
+
const commands = availableCommands(Boolean(creds)).map((c) => ({
|
|
33
|
+
name: c.name,
|
|
34
|
+
summary: c.summary,
|
|
35
|
+
}));
|
|
48
36
|
return new Promise((resolve) => {
|
|
49
|
-
const app = render(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
37
|
+
const app = render(_jsx(Prompt, { commands: commands, onSubmit: (raw) => {
|
|
38
|
+
app.unmount();
|
|
39
|
+
resolve(raw);
|
|
40
|
+
} }));
|
|
53
41
|
});
|
|
54
42
|
}
|
|
55
43
|
function pickDatabase(databases) {
|
|
@@ -60,15 +48,17 @@ function pickDatabase(databases) {
|
|
|
60
48
|
}));
|
|
61
49
|
items.push({ label: 'Back', value: BACK });
|
|
62
50
|
return new Promise((resolve) => {
|
|
63
|
-
const app = render(_jsxs(Box, { flexDirection: "column",
|
|
51
|
+
const app = render(_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [_jsx(Text, { bold: true, children: "Pick a database to connect to" }), _jsx(Box, { marginTop: 1, children: _jsx(Menu, { items: items, onSelect: (v) => {
|
|
64
52
|
app.unmount();
|
|
65
|
-
resolve(
|
|
53
|
+
resolve(v === BACK ? null : v);
|
|
66
54
|
} }) })] }));
|
|
67
55
|
});
|
|
68
56
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
async function runConnectFlow(dbRef) {
|
|
58
|
+
if (dbRef) {
|
|
59
|
+
await connectToDatabase({ dbRef, command: 'connect' });
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
72
62
|
const spinner = render(_jsx(Connecting, { label: "Loading your databases..." }));
|
|
73
63
|
let databases;
|
|
74
64
|
try {
|
|
@@ -84,42 +74,75 @@ async function runConnectFlow() {
|
|
|
84
74
|
process.stdout.write('No databases yet. Create one at https://layerbase.com.\n');
|
|
85
75
|
return;
|
|
86
76
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
const picked = await pickDatabase(databases);
|
|
78
|
+
if (picked)
|
|
79
|
+
await connectToDatabase({ dbRef: picked, command: 'connect' });
|
|
80
|
+
}
|
|
81
|
+
async function runMenu(creds, flags) {
|
|
82
|
+
// The selectable view: action commands only (menu/help/quit are not actions
|
|
83
|
+
// here - q in the list returns to the prompt).
|
|
84
|
+
const items = availableCommands(Boolean(creds))
|
|
85
|
+
.filter((c) => !['menu', 'help', 'quit'].includes(c.name))
|
|
86
|
+
.map((c) => ({ label: `/${c.name}`, value: c.name, hint: c.summary }));
|
|
87
|
+
const choice = await new Promise((resolve) => {
|
|
88
|
+
const app = render(_jsxs(Box, { flexDirection: "column", paddingY: 1, children: [_jsx(Text, { dimColor: true, children: "Select a command (q to go back to the prompt)" }), _jsx(Box, { marginTop: 1, children: _jsx(Menu, { items: items, onSelect: (v) => {
|
|
89
|
+
app.unmount();
|
|
90
|
+
resolve(v);
|
|
91
|
+
} }) })] }));
|
|
92
|
+
});
|
|
93
|
+
if (choice === 'quit')
|
|
94
|
+
return 'continue'; // q in the menu = back to the prompt
|
|
95
|
+
return dispatch(choice, [], creds, flags);
|
|
91
96
|
}
|
|
92
|
-
async function
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
async function dispatch(name, args, creds, flags) {
|
|
98
|
+
switch (name) {
|
|
99
|
+
case 'quit':
|
|
100
|
+
return 'quit';
|
|
101
|
+
case 'help':
|
|
102
|
+
printCommands(Boolean(creds));
|
|
103
|
+
return 'continue';
|
|
104
|
+
case 'menu':
|
|
105
|
+
return runMenu(creds, flags);
|
|
106
|
+
case 'spindb':
|
|
107
|
+
await runSpindb(args);
|
|
108
|
+
return 'continue';
|
|
109
|
+
case 'connect':
|
|
110
|
+
await runConnectFlow(args[0]);
|
|
111
|
+
return 'continue';
|
|
112
|
+
default: {
|
|
113
|
+
const instance = render(_jsx(App, { command: name, args: args, flags: flags }));
|
|
114
|
+
await instance.waitUntilExit();
|
|
115
|
+
process.stdout.write('\n');
|
|
116
|
+
return 'continue';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
95
119
|
}
|
|
96
|
-
// The
|
|
97
|
-
//
|
|
98
|
-
//
|
|
120
|
+
// The interactive harness: a Claude-Code-style prompt loop. Type /commands (or
|
|
121
|
+
// browse the palette), /menu for the selectable view, /spindb to hand off to
|
|
122
|
+
// local spindb. Bare text is the future AI-chat path (stubbed for now). The
|
|
123
|
+
// command set lives in @/lib/commands.
|
|
99
124
|
export async function runInteractive(flags) {
|
|
125
|
+
printBanner(await loadCredentials());
|
|
100
126
|
for (;;) {
|
|
101
|
-
clearScreen();
|
|
102
127
|
const creds = await loadCredentials();
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (choice === 'spindb') {
|
|
111
|
-
await runSpindb([]);
|
|
128
|
+
const raw = await promptOnce(creds);
|
|
129
|
+
const res = resolveInput(raw, { loggedIn: Boolean(creds) });
|
|
130
|
+
if (res.type === 'empty')
|
|
131
|
+
continue;
|
|
132
|
+
if (res.type === 'unknown') {
|
|
133
|
+
process.stdout.write(`Unknown command: /${res.token}. Type /help to see the commands.\n\n`);
|
|
134
|
+
continue;
|
|
112
135
|
}
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
if (res.type === 'ai') {
|
|
137
|
+
process.stdout.write('We do not yet support AI chat, please check back soon.\n\n');
|
|
138
|
+
printCommands(Boolean(creds));
|
|
139
|
+
continue;
|
|
115
140
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await instance.waitUntilExit();
|
|
141
|
+
const result = await dispatch(res.name, res.args, creds, flags);
|
|
142
|
+
if (result === 'quit') {
|
|
143
|
+
process.stdout.write('Bye.\n');
|
|
144
|
+
return;
|
|
121
145
|
}
|
|
122
|
-
await waitForEnter();
|
|
123
146
|
}
|
|
124
147
|
}
|
|
125
148
|
//# sourceMappingURL=interactive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/commands/interactive.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interactive.js","sourceRoot":"","sources":["../../src/commands/interactive.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,MAAM,WAAW,GAAG,wBAAwB,CAAA;AAC5C,MAAM,GAAG,GAAG,SAAS,CAAA;AACrB,MAAM,KAAK,GAAG,SAAS,CAAA;AACvB,MAAM,IAAI,GAAG,UAAU,CAAA;AAEvB,SAAS,WAAW,CAAC,KAA+B;IAClD,IAAI,CAAC,KAAK;QAAE,OAAO,eAAe,CAAA;IAClC,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,KAAK,CAAA;IACnD,OAAO,KAAK,CAAC,CAAC,CAAC,gBAAgB,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAA;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,CAAC;AAED,+EAA+E;AAC/E,6EAA6E;AAC7E,4EAA4E;AAC5E,uCAAuC;AACvC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,KAAmB;IACtD,WAAW,CAAC,MAAM,eAAe,EAAE,CAAC,CAAA;IAEpC,SAAS,CAAC;QACR,MAAM,KAAK,GAAG,MAAM,eAAe,EAAE,CAAA;QACrC,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,KAAK,CAAC,CAAA;QACnC,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE3D,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;YAAE,SAAQ;QAClC,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qBAAqB,GAAG,CAAC,KAAK,uCAAuC,CACtE,CAAA;YACD,SAAQ;QACV,CAAC;QACD,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,4DAA4D,CAC7D,CAAA;YACD,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YAC7B,SAAQ;QACV,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAC/D,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;YACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;YAC9B,OAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The command registry: the single source of truth for the interactive harness.
|
|
2
|
+
// Adding a command here makes it show up in the prompt palette, the /menu, and
|
|
3
|
+
// /help automatically. This is the seam future AI chat plugs into (a default
|
|
4
|
+
// handler for non-command input).
|
|
5
|
+
// When true (the pre-AI state), a bare single word that matches a command runs
|
|
6
|
+
// it, so `login` behaves like `/login`. Once AI chat is wired in, flip this to
|
|
7
|
+
// false so bare text is sent to the model instead of being treated as a command.
|
|
8
|
+
// Deliberately an in-code constant, not an env var: it encodes a code-evolution
|
|
9
|
+
// stage, not a runtime/operator decision.
|
|
10
|
+
export const ALLOW_FORWARD_SLASH_OMISSION = true;
|
|
11
|
+
export const COMMANDS = [
|
|
12
|
+
{ name: 'login', summary: 'Sign in via your browser', hideWhenAuthed: true },
|
|
13
|
+
{
|
|
14
|
+
name: 'logout',
|
|
15
|
+
summary: 'Sign out and remove the stored token',
|
|
16
|
+
requiresAuth: true,
|
|
17
|
+
},
|
|
18
|
+
{ name: 'whoami', summary: 'Show the signed-in account', requiresAuth: true },
|
|
19
|
+
{ name: 'ls', summary: 'List your cloud databases', requiresAuth: true },
|
|
20
|
+
{
|
|
21
|
+
name: 'connect',
|
|
22
|
+
summary: 'Connect to a cloud database',
|
|
23
|
+
requiresAuth: true,
|
|
24
|
+
},
|
|
25
|
+
{ name: 'spindb', summary: 'Run the local spindb CLI' },
|
|
26
|
+
{ name: 'menu', summary: 'Open the selectable menu' },
|
|
27
|
+
{ name: 'help', summary: 'List the available commands' },
|
|
28
|
+
{ name: 'quit', summary: 'Exit', aliases: ['exit'] },
|
|
29
|
+
];
|
|
30
|
+
export function findCommand(token) {
|
|
31
|
+
const t = token.toLowerCase();
|
|
32
|
+
return COMMANDS.find((c) => c.name === t || c.aliases?.includes(t));
|
|
33
|
+
}
|
|
34
|
+
export function availableCommands(loggedIn) {
|
|
35
|
+
return COMMANDS.filter((c) => {
|
|
36
|
+
if (c.requiresAuth && !loggedIn)
|
|
37
|
+
return false;
|
|
38
|
+
if (c.hideWhenAuthed && loggedIn)
|
|
39
|
+
return false;
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Parse a line of prompt input into an action. Slash commands always resolve as
|
|
44
|
+
// commands; bare input resolves to a command only when it is a single word that
|
|
45
|
+
// matches AND ALLOW_FORWARD_SLASH_OMISSION is on; everything else is 'ai' (the
|
|
46
|
+
// future AI-chat path, stubbed for now).
|
|
47
|
+
export function resolveInput(raw, options) {
|
|
48
|
+
void options;
|
|
49
|
+
const input = raw.trim();
|
|
50
|
+
if (!input)
|
|
51
|
+
return { type: 'empty' };
|
|
52
|
+
if (input.startsWith('/')) {
|
|
53
|
+
const parts = input.slice(1).trim().split(/\s+/);
|
|
54
|
+
const token = parts[0];
|
|
55
|
+
if (!token)
|
|
56
|
+
return { type: 'empty' };
|
|
57
|
+
const cmd = findCommand(token);
|
|
58
|
+
return cmd
|
|
59
|
+
? { type: 'command', name: cmd.name, args: parts.slice(1) }
|
|
60
|
+
: { type: 'unknown', token };
|
|
61
|
+
}
|
|
62
|
+
if (ALLOW_FORWARD_SLASH_OMISSION) {
|
|
63
|
+
const words = input.split(/\s+/);
|
|
64
|
+
const only = words[0];
|
|
65
|
+
if (words.length === 1 && only) {
|
|
66
|
+
const cmd = findCommand(only);
|
|
67
|
+
if (cmd)
|
|
68
|
+
return { type: 'command', name: cmd.name, args: [] };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return { type: 'ai', input };
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/lib/commands.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,+EAA+E;AAC/E,6EAA6E;AAC7E,kCAAkC;AAElC,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAA;AAahD,MAAM,CAAC,MAAM,QAAQ,GAAkB;IACrC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,0BAA0B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AAE,IAAI,EAAE,EAAE,EAAE,CAAA;QAC/D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AAC9B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Box, Text, useInput } from 'ink';
|
|
4
|
+
import { ACCENT } from '../ui/brand.js';
|
|
5
|
+
// A Claude-Code-style input line: type a /command (with a live palette you can
|
|
6
|
+
// arrow through and Tab-complete), or type free text. Enter submits. The palette
|
|
7
|
+
// shows only while typing a bare slash token (it hides once you add arguments).
|
|
8
|
+
export function Prompt({ commands, onSubmit, }) {
|
|
9
|
+
const [value, setValue] = useState('');
|
|
10
|
+
const [index, setIndex] = useState(0);
|
|
11
|
+
const showPalette = /^\/[a-z-]*$/i.test(value);
|
|
12
|
+
const query = showPalette ? value.slice(1).toLowerCase() : '';
|
|
13
|
+
const matches = showPalette
|
|
14
|
+
? commands.filter((c) => c.name.startsWith(query))
|
|
15
|
+
: [];
|
|
16
|
+
const active = matches.length ? Math.min(index, matches.length - 1) : 0;
|
|
17
|
+
useInput((input, key) => {
|
|
18
|
+
if (key.return) {
|
|
19
|
+
const chosen = matches[active];
|
|
20
|
+
if (showPalette && chosen)
|
|
21
|
+
onSubmit(`/${chosen.name}`);
|
|
22
|
+
else
|
|
23
|
+
onSubmit(value);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (key.upArrow) {
|
|
27
|
+
if (matches.length)
|
|
28
|
+
setIndex((i) => (i <= 0 ? matches.length - 1 : i - 1));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (key.downArrow) {
|
|
32
|
+
if (matches.length)
|
|
33
|
+
setIndex((i) => (i >= matches.length - 1 ? 0 : i + 1));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (key.tab) {
|
|
37
|
+
const chosen = matches[active];
|
|
38
|
+
if (chosen) {
|
|
39
|
+
setValue(`/${chosen.name}`);
|
|
40
|
+
setIndex(0);
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (key.backspace || key.delete) {
|
|
45
|
+
setValue((v) => v.slice(0, -1));
|
|
46
|
+
setIndex(0);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (input && !key.ctrl && !key.meta) {
|
|
50
|
+
setValue((v) => v + input);
|
|
51
|
+
setIndex(0);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT, children: '❯ ' }), _jsx(Text, { children: value }), _jsx(Text, { inverse: true, children: " " })] }), showPalette ? (_jsx(Box, { flexDirection: "column", marginTop: 1, children: matches.length === 0 ? (_jsx(Text, { dimColor: true, children: " no matching command" })) : (matches.map((c, i) => {
|
|
55
|
+
const on = i === active;
|
|
56
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { color: on ? ACCENT : undefined, bold: on, children: [on ? '❯ ' : ' ', `/${c.name}`.padEnd(12)] }), _jsx(Text, { dimColor: true, children: c.summary })] }, c.name));
|
|
57
|
+
})) })) : (_jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Type a /command (or / to browse) ", '·', " Enter to run ", '·', " Ctrl+C to quit"] }) }))] }));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/ui/prompt.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAInC,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