Scripts2026年5月17日·1 分钟阅读

Huh — Build Terminal Forms and Prompts in Go

A Go library for building interactive terminal forms with inputs, selects, confirms, and file pickers, powered by the Bubble Tea TUI framework.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 96/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Prompt
安装
Single
信任
信任等级:Established
入口
Huh Overview
通用 CLI 安装命令
npx tokrepo install c11aa6f6-51a7-11f1-9bc6-00163e2b0d79

Introduction

Huh is a Go library by Charm for building rich interactive forms in the terminal. It provides pre-built components like text inputs, selects, multi-selects, confirms, and file pickers that render beautifully using the Bubble Tea framework underneath.

What Huh Does

  • Renders multi-step terminal forms with keyboard navigation
  • Provides input, select, multi-select, confirm, and text area fields
  • Supports theming via Lip Gloss styles for consistent branding
  • Validates user input with custom or built-in validators
  • Works in accessible mode for screen readers and simple terminals

Architecture Overview

Huh builds on Charm's Bubble Tea TUI framework. Each form field is a Bubble Tea model with its own Update/View cycle. A Form groups fields into ordered steps, managing focus transitions and collecting results into bound Go variables via pointer references.

Self-Hosting & Configuration

  • Add to your module: go get github.com/charmbracelet/huh
  • No external runtime or daemon required
  • Customize appearance with huh.NewTheme() and Lip Gloss styles
  • Set accessible mode with huh.NewForm().WithAccessible(true) for CI environments
  • Compose fields into groups and groups into multi-page forms

Key Features

  • Declarative API: define forms with a builder pattern in a few lines
  • Keyboard-driven UX with Vim-style and arrow key navigation
  • Built-in spinner component for async operations during form flow
  • Supports piped input and non-interactive environments gracefully
  • Lightweight with no CGo dependencies

Comparison with Similar Tools

  • Bubble Tea — lower-level TUI framework; Huh is a form abstraction on top of it
  • Survey (Go) — similar form library but less visually polished
  • promptui — simpler prompts, fewer field types, less active maintenance
  • Inquirer.js — Node.js equivalent; Huh brings the same UX to Go
  • tview — full TUI widget toolkit; heavier than what forms need

FAQ

Q: Can Huh forms run in CI without a TTY? A: Yes. Enable accessible mode or pipe values via stdin for non-interactive runs.

Q: Does Huh support custom validation? A: Yes. Each field accepts a Validate(func(string) error) callback.

Q: Can I theme the form to match my CLI brand? A: Yes. Huh exposes a full theming API using Lip Gloss styles for colors, borders, and spacing.

Q: Is Huh compatible with Windows terminals? A: Yes. It works on Windows Terminal, PowerShell, and cmd via Bubble Tea's cross-platform rendering.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产