Skip to content

Form Timeouts #166

Closed
Closed

Description

@korpa

Is your feature request related to a problem? Please describe.
I want a Confirm field automatically go on with the preselection after 5 seconds without user interaction.

Describe the solution you'd like
Add a timeout config to the Run func

Some pseudo code:

form := huh.NewForm(...)
form.Run(cfg{timeout: time.Duration})
huh.NewInput().
...
Run(cfg{timeout: time.Duration})

If a timeout is set, a countdown starts when Run is called. When it finishes, Run does not block anymore and adds preselections to Values.
As soon as a key is hit while countdown has not finished, count down stops and works as w/o timeout

Describe alternatives you've considered

Additional context

Activity

  1. maaslalani commented on May 25, 2024

    @maaslalani
    Contributor

    Hey! Thanks for creating this issue. We do actually need something like this as we recently removed timeout functionality for gum and would love to add it back due to the huh? transition.

  2. changed the title [-]Go on with preselection after timeout/countdown without user interaction[/-] [+]Form Timeouts[/+] on May 25, 2024
  3. Delta456 commented on Jun 6, 2024

    @Delta456
    Contributor

    Hi, I am working on this and I would like a complete test case/example of this.

  4. maaslalani commented on Jun 7, 2024

    @maaslalani
    Contributor

    Hi @Delta456,

    We would need to implement something like the following on the form, similar to the other options.

    func (f Form) WithTimeout(d time.Duration) Form

    Then, when we Run() the form, we should pass a context to the tea.Program and cancel that context (use context.WithTimeout)

  5. Delta456 commented on Jun 8, 2024

    @Delta456
    Contributor

    This needs to be closed as it is implemented now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions