tui

package
v0.0.0-...-f3dbc0f Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserAborted is returned when the user cancels a prompt operation.
	ErrUserAborted = errors.New("user aborted")
)

Functions

func ClearCurrentLine

func ClearCurrentLine()

ClearCurrentLine clears the current terminal line.

func GetInput

func GetInput() byte

GetInput reads raw keyboard input from the terminal. Handles buffered input, raw mode, and ANSI escape sequences.

func GetTerminalHeight

func GetTerminalHeight() int

GetTerminalHeight returns the terminal height, defaulting to 25.

func Min

func Min(a, b int) int

Min returns the smaller of two integers.

func RenderClearAndReposition

func RenderClearAndReposition(linesToErase int, icon, title, answer string)

RenderClearAndReposition clears lines and renders final answer. Minimizes screen flicker by batching terminal operations.

func RenderClearLines

func RenderClearLines(numLines int)

RenderClearLines clears multiple lines from the cursor position.

func RenderFinalAnswer

func RenderFinalAnswer(icon, title, answer string)

RenderFinalAnswer displays the final formatted prompt result.

func RenderFormattedOutput

func RenderFormattedOutput(question, result string) string

RenderFormattedOutput creates formatted output with ANSI clear sequences.

Types

type InputPrompt

type InputPrompt[T any] struct {
	// contains filtered or unexported fields
}

InputPrompt provides a generic framework for text-based input prompts.

func NewPasswordPrompt

func NewPasswordPrompt() *InputPrompt[[]byte]

NewPasswordPrompt creates an InputPrompt for secure password input with masking.

func NewStringPrompt

func NewStringPrompt() *InputPrompt[string]

NewStringPrompt creates an InputPrompt for plaintext string input.

func (*InputPrompt[T]) AnswerFunc

func (p *InputPrompt[T]) AnswerFunc(fn func(string) string) *InputPrompt[T]

AnswerFunc sets a function to transform the final answer before returning.

func (*InputPrompt[T]) Display

func (p *InputPrompt[T]) Display(prompt string, value *T) error

Display displays the input prompt and handles user input

func (*InputPrompt[T]) DisplayInput

func (p *InputPrompt[T]) DisplayInput(fn func(T) string) *InputPrompt[T]

DisplayInput sets a function to customize how input is displayed during typing.

func (*InputPrompt[T]) Validate

func (p *InputPrompt[T]) Validate(fn func(T) error) *InputPrompt[T]

Validate sets a validation function for the input prompt.

Jump to

Keyboard shortcuts

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