@tooee/ask 0.1.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 +5 -0
- package/dist/Ask.d.ts +8 -0
- package/dist/Ask.d.ts.map +1 -0
- package/dist/Ask.js +38 -0
- package/dist/Ask.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/launch.d.ts +7 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +7 -0
- package/dist/launch.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
- package/src/Ask.tsx +72 -0
- package/src/index.ts +4 -0
- package/src/launch.tsx +19 -0
- package/src/types.ts +5 -0
package/README.md
ADDED
package/dist/Ask.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ActionDefinition } from "@tooee/commands";
|
|
2
|
+
import type { AskOptions } from "./types.js";
|
|
3
|
+
interface AskProps extends AskOptions {
|
|
4
|
+
actions?: ActionDefinition[];
|
|
5
|
+
}
|
|
6
|
+
export declare function Ask({ prompt, placeholder, defaultValue, actions }: AskProps): import("react").ReactNode;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=Ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ask.d.ts","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,UAAU,QAAS,SAAQ,UAAU;IACnC,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC7B;AAED,wBAAgB,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,QAAQ,6BA2D3E"}
|
package/dist/Ask.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { useRenderer } from "@opentui/react";
|
|
4
|
+
import { useCommand, useActions, useProvideCommandContext, useCommandContext } from "@tooee/commands";
|
|
5
|
+
import { useTheme, ThemePicker } from "@tooee/themes";
|
|
6
|
+
import { useThemeCommands } from "@tooee/shell";
|
|
7
|
+
export function Ask({ prompt, placeholder, defaultValue, actions }) {
|
|
8
|
+
const renderer = useRenderer();
|
|
9
|
+
const [value, setValue] = useState(defaultValue ?? "");
|
|
10
|
+
const { invoke } = useCommandContext();
|
|
11
|
+
const { theme } = useTheme();
|
|
12
|
+
const { name: themeName, picker: themePicker } = useThemeCommands();
|
|
13
|
+
useProvideCommandContext(() => ({
|
|
14
|
+
ask: { value },
|
|
15
|
+
exit: () => renderer.destroy(),
|
|
16
|
+
}));
|
|
17
|
+
useCommand({
|
|
18
|
+
id: "cancel",
|
|
19
|
+
title: "Cancel",
|
|
20
|
+
hotkey: "escape",
|
|
21
|
+
handler: (ctx) => {
|
|
22
|
+
ctx.exit();
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
useActions(actions);
|
|
26
|
+
const handleSubmit = () => {
|
|
27
|
+
// If there's a "submit" action registered, invoke it via the command system
|
|
28
|
+
if (actions?.some((a) => a.id === "submit")) {
|
|
29
|
+
invoke("submit");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// Default: write to stdout and exit
|
|
33
|
+
process.stdout.write(value + "\n");
|
|
34
|
+
renderer.destroy();
|
|
35
|
+
};
|
|
36
|
+
return (_jsxs("box", { flexDirection: "column", width: "100%", height: "100%", children: [prompt && _jsx("text", { content: prompt, fg: theme.primary, style: { marginBottom: 1 } }), _jsx("input", { value: value, onChange: setValue, onSubmit: handleSubmit, placeholder: placeholder, textColor: theme.text, focused: true }), _jsx("text", { content: `Theme: ${themeName}`, fg: theme.textMuted, style: { marginTop: 1 } }), themePicker.isOpen && (_jsx(ThemePicker, { entries: themePicker.entries, currentTheme: themeName, onSelect: themePicker.confirm, onClose: themePicker.close, onNavigate: themePicker.preview }))] }));
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Ask.js.map
|
package/dist/Ask.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ask.js","sourceRoot":"","sources":["../src/Ask.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAErG,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAO/C,MAAM,UAAU,GAAG,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAY;IAC1E,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAA;IAC9B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,CAAA;IACtD,MAAM,EAAE,MAAM,EAAE,GAAG,iBAAiB,EAAE,CAAA;IAEtC,MAAM,EAAE,KAAK,EAAE,GAAG,QAAQ,EAAE,CAAA;IAC5B,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,gBAAgB,EAAE,CAAA;IAEnE,wBAAwB,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9B,GAAG,EAAE,EAAE,KAAK,EAAE;QACd,IAAI,EAAE,GAAG,EAAE,CAAC,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AAW,CAAC,OAAO,EAC5B,YAAY,EAAE,SAAS,EACvB,QAAQ,EAAE,WAAW,CAAC,OAAO,EAC7B,OAAO,EAAE,WAAW,CAAC,KAAK,EAC1B,UAAU,EAAE,WAAW,CAAC,OAAO,GAC/B,CACH,IACG,CACP,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/launch.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActionDefinition } from "@tooee/commands";
|
|
2
|
+
import type { AskOptions } from "./types.js";
|
|
3
|
+
export interface AskLaunchOptions extends AskOptions {
|
|
4
|
+
actions?: ActionDefinition[];
|
|
5
|
+
}
|
|
6
|
+
export declare function launch(options: AskLaunchOptions): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=launch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../src/launch.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC7B;AAED,wBAAsB,MAAM,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASrE"}
|
package/dist/launch.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "@opentui/react/jsx-runtime";
|
|
2
|
+
import { launchCli } from "@tooee/shell";
|
|
3
|
+
import { Ask } from "./Ask.jsx";
|
|
4
|
+
export async function launch(options) {
|
|
5
|
+
await launchCli(_jsx(Ask, { prompt: options.prompt, placeholder: options.placeholder, defaultValue: options.defaultValue, actions: options.actions }));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=launch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch.js","sourceRoot":"","sources":["../src/launch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAO/B,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAyB;IACpD,MAAM,SAAS,CACb,KAAC,GAAG,IACF,MAAM,EAAE,OAAO,CAAC,MAAM,EACtB,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,YAAY,EAAE,OAAO,CAAC,YAAY,EAClC,OAAO,EAAE,OAAO,CAAC,OAAO,GACxB,CACH,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tooee/ask",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Terminal text input gathering",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Gareth Andrew",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/gingerhendrix/tooee.git",
|
|
10
|
+
"directory": "packages/ask"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/gingerhendrix/tooee",
|
|
13
|
+
"bugs": "https://github.com/gingerhendrix/tooee/issues",
|
|
14
|
+
"keywords": ["tui", "terminal", "cli", "opentui", "input", "prompt"],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"@tooee/source": "./src/index.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": ["dist", "src"],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"typecheck": "tsc --noEmit"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@tooee/commands": "0.0.0",
|
|
30
|
+
"@tooee/themes": "0.0.0",
|
|
31
|
+
"@tooee/shell": "0.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@opentui/core": "^0.1.67",
|
|
35
|
+
"@opentui/react": "^0.1.67",
|
|
36
|
+
"@types/bun": "^1.3.5",
|
|
37
|
+
"@types/react": "^19.1.10",
|
|
38
|
+
"typescript": "^5.8.3"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@opentui/core": "^0.1.67",
|
|
42
|
+
"@opentui/react": "^0.1.67",
|
|
43
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/Ask.tsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useState } from "react"
|
|
2
|
+
import { useRenderer } from "@opentui/react"
|
|
3
|
+
import { useCommand, useActions, useProvideCommandContext, useCommandContext } from "@tooee/commands"
|
|
4
|
+
import type { ActionDefinition } from "@tooee/commands"
|
|
5
|
+
import { useTheme, ThemePicker } from "@tooee/themes"
|
|
6
|
+
import { useThemeCommands } from "@tooee/shell"
|
|
7
|
+
import type { AskOptions } from "./types.js"
|
|
8
|
+
|
|
9
|
+
interface AskProps extends AskOptions {
|
|
10
|
+
actions?: ActionDefinition[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function Ask({ prompt, placeholder, defaultValue, actions }: AskProps) {
|
|
14
|
+
const renderer = useRenderer()
|
|
15
|
+
const [value, setValue] = useState(defaultValue ?? "")
|
|
16
|
+
const { invoke } = useCommandContext()
|
|
17
|
+
|
|
18
|
+
const { theme } = useTheme()
|
|
19
|
+
const { name: themeName, picker: themePicker } = useThemeCommands()
|
|
20
|
+
|
|
21
|
+
useProvideCommandContext(() => ({
|
|
22
|
+
ask: { value },
|
|
23
|
+
exit: () => renderer.destroy(),
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
useCommand({
|
|
27
|
+
id: "cancel",
|
|
28
|
+
title: "Cancel",
|
|
29
|
+
hotkey: "escape",
|
|
30
|
+
handler: (ctx) => {
|
|
31
|
+
ctx.exit()
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
useActions(actions)
|
|
36
|
+
|
|
37
|
+
const handleSubmit = () => {
|
|
38
|
+
// If there's a "submit" action registered, invoke it via the command system
|
|
39
|
+
if (actions?.some((a) => a.id === "submit")) {
|
|
40
|
+
invoke("submit")
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Default: write to stdout and exit
|
|
45
|
+
process.stdout.write(value + "\n")
|
|
46
|
+
renderer.destroy()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<box flexDirection="column" width="100%" height="100%">
|
|
51
|
+
{prompt && <text content={prompt} fg={theme.primary} style={{ marginBottom: 1 }} />}
|
|
52
|
+
<input
|
|
53
|
+
value={value}
|
|
54
|
+
onChange={setValue}
|
|
55
|
+
onSubmit={handleSubmit}
|
|
56
|
+
placeholder={placeholder}
|
|
57
|
+
textColor={theme.text}
|
|
58
|
+
focused
|
|
59
|
+
/>
|
|
60
|
+
<text content={`Theme: ${themeName}`} fg={theme.textMuted} style={{ marginTop: 1 }} />
|
|
61
|
+
{themePicker.isOpen && (
|
|
62
|
+
<ThemePicker
|
|
63
|
+
entries={themePicker.entries}
|
|
64
|
+
currentTheme={themeName}
|
|
65
|
+
onSelect={themePicker.confirm}
|
|
66
|
+
onClose={themePicker.close}
|
|
67
|
+
onNavigate={themePicker.preview}
|
|
68
|
+
/>
|
|
69
|
+
)}
|
|
70
|
+
</box>
|
|
71
|
+
)
|
|
72
|
+
}
|
package/src/index.ts
ADDED
package/src/launch.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { launchCli } from "@tooee/shell"
|
|
2
|
+
import type { ActionDefinition } from "@tooee/commands"
|
|
3
|
+
import { Ask } from "./Ask.jsx"
|
|
4
|
+
import type { AskOptions } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export interface AskLaunchOptions extends AskOptions {
|
|
7
|
+
actions?: ActionDefinition[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function launch(options: AskLaunchOptions): Promise<void> {
|
|
11
|
+
await launchCli(
|
|
12
|
+
<Ask
|
|
13
|
+
prompt={options.prompt}
|
|
14
|
+
placeholder={options.placeholder}
|
|
15
|
+
defaultValue={options.defaultValue}
|
|
16
|
+
actions={options.actions}
|
|
17
|
+
/>,
|
|
18
|
+
)
|
|
19
|
+
}
|