prompter

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Confirm

func Confirm(prompt string) (bool, error)

Confirm prints prompt to stderr and returns true only when the user types "y" or "Y". Any other input, including empty, returns false. This replaces huh.Confirm for simple yes/no prompts.

func Select

func Select(prompt string, choices []string) (int, error)

Select displays a numbered list of choices on stderr and reads the user's selection from stdin. It does not use raw mode — the user sees their input. This replaces huh.Select for non-secret interactive menus.

path, err := prompter.Select("Multiple databases found", paths)

func WithConfirm

func WithConfirm() func(*Input)

WithConfirm adds a confirmation prompt.

func WithConfirmMsg

func WithConfirmMsg(msg string) func(*Input)

WithConfirmMsg sets a custom confirmation prompt message and enables confirmation.

func WithMinLength

func WithMinLength(n int, msg string) func(*Input)

WithMinLength sets a minimum byte length for the entered value.

func WithMismatchMsg

func WithMismatchMsg(msg string) func(*Input)

WithMismatchMsg sets the error message shown when confirmation does not match.

func WithRequired

func WithRequired(required bool, msg string) func(*Input)

WithRequired marks the input as required (non-empty).

Types

type Formatter

type Formatter func(prompt string) string

Formatter formats a prompt string for display.

type Input

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

Input represents a no-echo password/passphrase prompt.

func NewInput

func NewInput(prompt string, opts ...func(*Input)) *Input

NewInput creates a new no-echo input builder with optional functional options.

input := NewInput("Master passphrase", WithConfirm(), WithRequired(true, "required"))

func (*Input) Run

func (p *Input) Run() (*Result, error)

Run executes the no-echo prompt and returns a secure Result. Returns an error if stdin is not a terminal.

func (*Input) WithPromptFormatter

func (p *Input) WithPromptFormatter(formatter Formatter) *Input

WithPromptFormatter sets a custom prompt formatter.

type Result

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

Result holds the secure password bytes with a zeroing method

func NewResult

func NewResult(pass []byte) *Result

NewResult creates a new Result

func Quick

func Quick(prompt string) (*Result, error)

Quick prompts for a single password with minimal options.

func QuickWithConfirm

func QuickWithConfirm(prompt string) (*Result, error)

QuickWithConfirm prompts for a password with confirmation.

func ReadSecret

func ReadSecret(prompt string) (*Result, error)

SecretInput reads a single secret value from the terminal with no echo. It is intentionally simpler than Input — no confirmation, no min-length — because it is used for storing secret values, not for passphrase entry.

Use this in the REPL's "set" command instead of reading the value as a command-line argument, which would expose it in terminal scrollback and shell history.

result, err := prompter.ReadSecret("Value for " + key)
if err != nil { ... }
defer result.Zero()
cmds.Set(key, string(result.Bytes()), keepcmd.SetOptions{})

func (*Result) Bytes

func (p *Result) Bytes() []byte

Bytes returns the password bytes - call Zero() when done

func (*Result) Confirm

func (p *Result) Confirm(other *Result) bool

Confirm compares two password results and zeroes both

func (*Result) String

func (p *Result) String() string

String returns the password as a string (use sparingly, only when absolutely needed) This defeats the security purpose - prefer Bytes() and Zero()

func (*Result) Zero

func (p *Result) Zero()

Zero securely wipes the password from memory

Jump to

Keyboard shortcuts

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