Skip to content

Add option to skip TTY initialization for fully-hidden forms #718

@tetienne

Description

@tetienne

Description

When building CLI tools with huh, it's common to use .WithHide() to conditionally skip prompts when values are provided via flags. However, Form.Run() still requires a TTY even when all groups evaluate to hidden.

name := "provided-via-flag"

  form := huh.NewForm(
      huh.NewGroup(
          huh.NewInput().Title("Name").Value(&name),
      ).WithHide(name != ""),
  )

  err := form.Run() // Fails: "could not open a new TTY: open /dev/tty: device not configured"

I faced this issue while telling Claude Code to use my CLI, but it can also occur within any CI pipeline.

I can update my code to guard all the Form.Run() calls, but it means duplicate all my .WithHide() conditions which is not really great. My suggestion would be before calling tea.NewProgram().Run(), to check if all groups are hidden. If so, return nil immediately without initializing Bubble Tea (which opens /dev/tty here)..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions