ui

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ui handles terminal input and output: prompting for variables, confirming dangerous steps, and printing progress.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTruthy

func IsTruthy(s string) bool

IsTruthy is the shared string-to-bool reading, used for bool variables and for `when` expressions so the two never disagree.

Types

type Auto

type Auto struct {
	// Assume is the answer given to every Confirm.
	Assume bool
}

Auto answers from defaults without prompting, for CI and --yes runs.

func (*Auto) Ask

func (a *Auto) Ask(f Field) (string, error)

Ask returns the default, or fails loudly. Silently substituting an empty string for a missing answer would produce a subtly broken project.

func (*Auto) Confirm

func (a *Auto) Confirm(string, bool) (bool, error)

Confirm returns the assumed answer.

type Field

type Field struct {
	Label    string
	Help     string
	Default  string
	Options  []string // non-empty means a choice
	Bool     bool
	Validate func(string) error
}

Field describes one question. It is deliberately not the blueprint's Variable type — the prompter should not need to know what a blueprint is.

type Printer

type Printer struct {

	// Quiet suppresses everything except warnings and errors.
	Quiet bool
	// contains filtered or unexported fields
}

Printer writes progress output. It is separate from Prompter so that a non-interactive run can still produce readable logs.

func NewPrinter

func NewPrinter(out io.Writer) *Printer

NewPrinter builds a printer over a stream.

func (*Printer) Bold

func (p *Printer) Bold(s string) string

Bold emphasises inline text.

func (*Printer) Detail

func (p *Printer) Detail(format string, args ...any)

Detail is a line nested under the current step.

func (*Printer) Dim

func (p *Printer) Dim(s string) string

Dim de-emphasises inline text.

func (*Printer) Info

func (p *Printer) Info(format string, args ...any)

Info is an ordinary unindented line.

func (*Printer) Step

func (p *Printer) Step(format string, args ...any)

Step announces a stage of the run.

func (*Printer) Success

func (p *Printer) Success(format string, args ...any)

Success closes out a successful run.

func (*Printer) Warn

func (p *Printer) Warn(format string, args ...any)

Warn is shown even when quiet.

type Prompter

type Prompter interface {
	Ask(f Field) (string, error)
	Confirm(prompt string, def bool) (bool, error)
}

Prompter collects answers. Two implementations exist: a terminal prompter, and one that answers from defaults for non-interactive runs.

Whether a human is present is deliberately not part of this interface. That is a fact about the process, not about how questions get asked, and the two were conflated in an earlier version — which made piped answers silently resolve to defaults.

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

Terminal prompts on a real terminal.

func NewTerminal

func NewTerminal(in io.Reader, out io.Writer) *Terminal

NewTerminal builds a prompter over the given streams.

func (*Terminal) Ask

func (t *Terminal) Ask(f Field) (string, error)

Ask presents one field and returns the answer as a string. Choices are numbered rather than driven by arrow keys, so this works over a pipe, in a container, and in every terminal emulator without raw mode.

func (*Terminal) Confirm

func (t *Terminal) Confirm(prompt string, def bool) (bool, error)

Confirm asks a yes/no question. Used before running hooks, which is the one place rig executes code it did not write.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL