-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recommended way to use prompts? #24
Labels
Comments
I ran into the same issue and did this to get a working prompt: import type { TaskInnerAPI } from 'tasuku'
import { confirm } from '@inquirer/prompts'
import { Stream } from 'node:stream'
export function confirmTask(
message: string,
setOutput: TaskInnerAPI['setOutput'],
) {
return confirm(
{
message,
},
{
output: new Stream.Writable({
write(chunk, _encoding, next) {
setOutput(String(chunk))
next()
},
}),
},
)
} Use it like this: await task('Some task', async ({ setError, setOutput }) => {
const confirmed = await confirmTask('Delete file', setOutput)
if (!confirmed) {
// Cancel...
setError('Aborted')
} else {
// Delete file...
}
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem?
Not exactly - I currently have a CLI app that's using listr2, but tasuku looks nicer in that each task can have a return value, rather than listr2 which relies on mutating the context, which isn't as type safe.
listr2 has a specific prompt adapter. I'm not sure if tasuku would need an adapter, but it could be useful to have a docs suggestion of how you would recommend integrating
enquirer
or somethingDescribe the solution you'd like
What would be really great, is some sort of
cleye
xtaskuku
xenquirer
thing. Wherecleye
defines its arguments/flags, andtasuku
adds tasks to prompt the user for those arguments if they haven't been defined already. It could be built in userland, but wondered if there'd be interest in incorporating here.Describe alternatives you've considered
DIY - just install
enquirer
.Additional context
The text was updated successfully, but these errors were encountered: