Open-Source Wikis

/

Bubble Tea

/

Reference

/

Program options

charmbracelet/bubbletea

Program options

Every ProgramOption accepted by tea.NewProgram(model, opts...). All defined in options.go.

Option Effect
WithContext(ctx context.Context) Set the parent context. Cancelling it returns from Run with ErrProgramKilled.
WithOutput(w io.Writer) Override the default os.Stdout.
WithInput(r io.Reader) Override the default os.Stdin. Pass nil to disable input entirely.
WithEnvironment(env []string) Override the program's view of environment variables. Useful for SSH-hosted programs that want the client's TERM.
WithoutSignalHandler() Skip installing the SIGINT/SIGTERM handler. The host must shut down the program manually.
WithoutCatchPanics() Disable the deferred panic recovery. After a panic the terminal will be in raw mode until something else restores it.
WithoutSignals() Treat all signals as if they should be ignored (atomic.StoreUint32(&p.ignoreSignals, 1)). Mainly used in tests.
WithoutRenderer() Use nilRenderer instead of cursedRenderer. Stdout is plain text. Pairs well with WithInput(nil) for daemon mode.
WithFilter(func(Model, Msg) Msg) Intercept every Msg before it reaches Update. Returning nil drops the message. Used for things like preventing quit when there are unsaved changes.
WithFPS(fps int) Cap renderer frames per second. < 1 falls back to 60. > 120 is clamped to 120.
WithColorProfile(p colorprofile.Profile) Force a specific color profile (e.g. for tests). Otherwise auto-detected.
WithWindowSize(w, h int) Force an initial size. Otherwise queried from the TTY. Useful for tests and headless renders.

Removed-since-v1 options (do nothing now): WithAltScreen, WithMouseCellMotion, WithMouseAllMotion, WithReportFocus, WithoutBracketedPaste, WithInputTTY, WithANSICompressor. See UPGRADE_GUIDE_V2.md.

Pairing options

Common combinations:

  • Daemon mode: WithoutRenderer() plus WithInput(nil) plus WithoutSignalHandler() for a Bubble Tea app that runs without a TTY (see examples/tui-daemon-combo).
  • Test mode: WithInput(strings.NewReader("")), WithOutput(&bytes.Buffer{}), WithoutSignals(), WithoutCatchPanics(), WithColorProfile(colorprofile.TrueColor), WithWindowSize(80, 24).
  • SSH server: WithEnvironment(sess.Environ()), WithInput(sess), WithOutput(sess).

Setting up Run

These options affect Run. Once Run returns, the option values are consumed; calling NewProgram a second time gives you a fresh Program with default settings unless you pass the options again.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Program options – Bubble Tea wiki | Factory