Skip to content
/ huh Public
forked from charmbracelet/huh

Build terminal forms and prompts 🤷🏻‍♀️

License

Notifications You must be signed in to change notification settings

kralicky/huh

Repository files navigation

Huh?

A simple and powerful library for building interactive forms in the terminal. Powered by Bubble Tea.

Tutorial

Huh? provides a straightforward interface to prompt users for input.

There are several Question types available to use:

package main

import (
  "log"

  "github.com/charmbracelet/huh"
)

func main() {
  form := huh.NewForm(
    // What's a taco without a shell?
    // We'll need to know what filling to put inside too.
    huh.NewGroup(
      huh.NewSelect("Hard", "Soft").
        Title("Shell?"),

      huh.NewSelect("Chicken", "Beef", "Fish", "Beans").
        Title("Base"),
    ),

    // Prompt for toppings and special instructions.
    // The customer can ask for up to 4 toppings.
    huh.NewGroup(
      huh.NewMultiSelect("Lettuce", "Tomatoes", "Corn", "Salsa", "Sour Cream", "Cheese").
        Title("Toppings").
        Limit(4),

      huh.NewText().
        Title("Special Instructions").
        CharLimit(400),
    ),

    // Gather final details for the order.
    huh.NewGroup(
      huh.NewInput().
        Title("What's your name?").
        Validate(validateName),

      huh.NewConfirm().
        Title("Would you like 15% off"),
    ),
  )

  err := form.Run()
  if err != nil {
    log.Fatal(err)
  }
}

Input

Inputs are single line text fields.

huh.NewInput().
  Title("What's for lunch?").
  Validate(validateLength).
  Prompt("?")

Text

Texts are multi-line text fields.

huh.NewText().
  Title("Tell me a story.").
  Validate(validateLength).
  Prompt(">").
  Editor(true) // open in $EDITOR

Select

Selects are multiple choice questions.

huh.NewSelect[Country]().
  Title("Pick a country.").
  Options(
    huh.NewOption("United States", "US"),
    huh.NewOption("Germany", "DE"),
    huh.NewOption("Brazil", "BR"),
    huh.NewOption("Canada", "CA"),
  ).
  Cursor("→")

Alternatively,

huh.NewSelect("United States", "Germany", "Brazil", "Canada").
  Title("Pick a country.").
  Cursor("→")

Multiple Select

MultiSelects are multiple choice questions but allow multiple selections.

huh.NewMultiSelect().
  Title("Toppings.").
  Limit(4)

Feedback

We'd love to hear your thoughts on this project. Feel free to drop us a note!

Acknowledgments

huh is inspired by the wonderful Survey library by Alec Aivazis.

License

MIT


Part of Charm.

The Charm logo

Charm热爱开源 • Charm loves open source • نحنُ نحب المصادر المفتوحة

About

Build terminal forms and prompts 🤷🏻‍♀️

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.9%
  • Makefile 0.1%