prompt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package prompt implements the small set of interactive TTY prompts SSLKnife needs: confirmations, passwords, free text and choices.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInteractive = errors.New("input required but no terminal is attached")

ErrNotInteractive is returned when a prompt is needed but no terminal is attached. Callers should tell the user which flag or env var to use.

Functions

This section is empty.

Types

type Prompter

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

Prompter reads answers from in and writes questions to out.

func New

func New(in io.Reader, out io.Writer) *Prompter

New creates a prompter. Prompts are only allowed when in is a terminal.

func NewScripted

func NewScripted(in io.Reader, out io.Writer) *Prompter

NewScripted creates a prompter that reads answers from in regardless of whether it is a terminal. Used by tests.

func (*Prompter) Choose

func (p *Prompter) Choose(question string, options []string, def int) (int, error)

Choose presents numbered options and returns the selected index.

func (*Prompter) Confirm

func (p *Prompter) Confirm(question string, def bool) (bool, error)

Confirm asks a yes/no question. An empty answer returns def.

func (*Prompter) Interactive

func (p *Prompter) Interactive() bool

Interactive reports whether prompting is possible.

func (*Prompter) Line

func (p *Prompter) Line(question, def string) (string, error)

Line asks for a line of text. An empty answer returns def.

func (*Prompter) Lines

func (p *Prompter) Lines(question string) ([]string, error)

Lines reads values until an empty line.

func (*Prompter) NewPassword

func (p *Prompter) NewPassword(question string, minLen int) ([]byte, error)

NewPassword asks for a password twice and checks that both match.

func (*Prompter) Password

func (p *Prompter) Password(question string) ([]byte, error)

Password reads a secret without echo. The caller should zero the result.

Jump to

Keyboard shortcuts

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