terkelg/prompts

Prompt time out

arivictor opened this issue · 0 comments

Describe the solution you'd like

I would like to have a prompt that has a TTL/timeout with a visual countdown, the user has N seconds/minutes to provide an input before the process exits.

I'd like to be able to do this, as I prompt a user Are you sure? before proceeding with a destructive change to a remote data store. However, consider the scenario where the user never provides an input and the prompt hangs (they go to get a coffee and forget). It's quite possible that the original information they were acting on is now wrong (i.e. the data store has since been updated). I want to narrow the window of how long the prompt can hang.

Describe alternatives you've considered

I've attempted to use the built in functionality of prompt combined with timeouts and intervals but I just can't seem to get a good UX. I can make the prompt timeout but I can't visualise that to the user with a countdown that dynamically updates:

? Are you sure? › (y/N)

App will exit in: 5 sec

Example

From charmbraclets bubbletea TUI package on Go

image

https://github.com/charmbracelet/bubbletea