-
Notifications
You must be signed in to change notification settings - Fork 232
Add option to skip TTY initialization for fully-hidden forms #718
Copy link
Copy link
Open
Description
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)..
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels