Documentation
¶
Index ¶
- Variables
- func ClearCurrentLine()
- func GetInput() byte
- func GetTerminalHeight() int
- func Min(a, b int) int
- func RenderClearAndReposition(linesToErase int, icon, title, answer string)
- func RenderClearLines(numLines int)
- func RenderFinalAnswer(icon, title, answer string)
- func RenderFormattedOutput(question, result string) string
- type InputPrompt
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUserAborted is returned when the user cancels a prompt operation. ErrUserAborted = errors.New("user aborted") )
Functions ¶
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 RenderClearAndReposition ¶
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 ¶
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.