prompt

package
v0.1.111 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prompt asks a person at a terminal for a line of text, one choice from a list, or yes or no.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("cancelled")

ErrCancelled reports that the person pressed Ctrl-C or closed the input instead of answering.

Functions

This section is empty.

Types

type Option

type Option struct {
	// Label is the choice as the person reads it.
	Label string
	// Hint is a short note shown dimmed after the label, or empty.
	Hint string
}

Option is one choice a Select offers.

type Terminal

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

Terminal asks its questions on a terminal that understands ANSI cursor codes. Each question holds the terminal in raw mode until it is answered, so Ctrl-C reaches the question as a key and cancels it.

func NewTerminal

func NewTerminal(in *os.File, out io.Writer, color bool) *Terminal

NewTerminal returns a Terminal that reads answers from in and shows its questions on out, in color when color is true.

func (*Terminal) Confirm

func (t *Terminal) Confirm(label string, fallback bool) (bool, error)

Confirm asks a yes or no question and returns the answer, or fallback when the person presses Enter.

func (*Terminal) Select

func (t *Terminal) Select(label string, options []Option, selected int) (int, error)

Select asks for one of options, starting on the one at selected, and returns the chosen option's index. The arrow keys, j and k move, a digit jumps to that option, and Enter chooses.

func (*Terminal) Text

func (t *Terminal) Text(label, fallback string, check func(string) error) (string, error)

Text asks for a line of text and returns it trimmed, or fallback when the person presses Enter on an empty line. While check returns an error for the answer, Text shows the error and asks again.

Jump to

Keyboard shortcuts

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