terminal

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxWidth  int  = 120
	MinHeight int  = 15
	MinWidth  int  = 80
	Piped     bool = false
)

Default terminal settings.

View Source
var (
	ErrNotTTY              = errors.New("not a terminal")
	ErrGetTermSize         = errors.New("getting terminal size")
	ErrTermWidthTooSmall   = errors.New("terminal width too small")
	ErrTermHeightTooSmall  = errors.New("terminal height too small")
	ErrUnsupportedPlatform = errors.New("unsupported platform")
	ErrNoStateToRestore    = errors.New("no term state to restore")
	ErrNotInteractive      = errors.New("not an interactive terminal")
)
View Source
var ErrActionAborted = errors.New("action aborted")

Functions

func Choose added in v0.1.5

func Choose(q string, opts []string, def string) string

Choose prompts the user to enter one of the given options.

func Clear

func Clear()

Clear clears the terminal.

func ClearChars added in v0.1.1

func ClearChars(n int)

ClearChars deletes n characters in the console.

func ClearLine

func ClearLine(n int)

ClearLine deletes n lines in the console.

func Confirm

func Confirm(q, def string) bool

Confirm prompts the user with a question and options.

func IsPiped

func IsPiped() bool

IsPiped returns true if the input is piped.

func LoadMaxWidth

func LoadMaxWidth()

LoadMaxWidth updates `MaxWidth` to the current width if it is smaller than the existing `MaxWidth`.

func NoColor

func NoColor(b *bool)

NoColor disables color output if the NO_COLOR environment variable is set.

func ReadPipedInput

func ReadPipedInput(args *[]string)

ReadPipedInput reads the input from a pipe.

func ReplaceLine

func ReplaceLine(n int, s string)

ReplaceLine replaces a line in the console.

func WaitForEnter

func WaitForEnter()

WaitForEnter displays a prompt and waits for the user to press ENTER.

Types

type Options added in v0.1.5

type Options struct {
	PromptStr   string
	InterruptFn func(error)
	// contains filtered or unexported fields
}

Options represents the options for the terminal.

type PromptSuggester

type PromptSuggester = func(in prompt.Document) []prompt.Suggest

PromptSuggester is a function that generates suggestions for a given prompt.

type Term added in v0.1.5

type Term struct {
	Options
	// contains filtered or unexported fields
}

Term is a struct that represents a terminal.

func New added in v0.1.5

func New(opts ...TermOptFn) *Term

New returns a new terminal.

func (*Term) CancelInterruptHandler added in v0.1.5

func (t *Term) CancelInterruptHandler()

CancelInterruptHandler cancels the interrupt handler.

func (*Term) Choose added in v0.1.5

func (t *Term) Choose(q string, opts []string, def string) string

Choose prompts the user to enter one of the given options.

func (*Term) ChooseTags added in v0.1.5

func (t *Term) ChooseTags(p string, items map[string]int) string

ChooseTags prompts the user for input with suggestions based on the provided tags.

func (*Term) Clear added in v0.1.5

func (t *Term) Clear()

Clear clears the terminal.

func (*Term) ClearChars added in v0.1.5

func (t *Term) ClearChars(n int)

ClearChars deletes n characters in the console.

func (*Term) ClearLine added in v0.1.5

func (t *Term) ClearLine(n int)

ClearLine deletes n lines in the console.

func (*Term) Confirm added in v0.1.5

func (t *Term) Confirm(q, def string) bool

Confirm prompts the user with a question and options.

func (*Term) Input added in v0.1.5

func (t *Term) Input(p string) string

Input get the Input data from the user and return it.

func (*Term) IsPiped added in v0.1.5

func (t *Term) IsPiped() bool

IsPiped returns true if the terminal input is piped.

func (*Term) PipedInput added in v0.1.7

func (t *Term) PipedInput(input *[]string)

func (*Term) Prompt added in v0.1.5

func (t *Term) Prompt(p string) string

Prompt get the input data from the user and return it.

func (*Term) PromptWithFuzzySuggestions added in v0.1.5

func (t *Term) PromptWithFuzzySuggestions(p string, items []string) string

PromptWithFuzzySuggestions prompts the user for input with fuzzy suggestions.

func (*Term) PromptWithSuggestions added in v0.1.5

func (t *Term) PromptWithSuggestions(p string, items []string) string

PromptWithSuggestions prompts the user for input with suggestions based on the provided items.

func (*Term) ReplaceLine added in v0.1.5

func (t *Term) ReplaceLine(n int, s string)

ReplaceLine deletes n lines in the console and prints the given string.

func (*Term) SetInterruptFn added in v0.1.5

func (t *Term) SetInterruptFn(fn func(error))

SetInterruptFn sets the interrupt function for the terminal.

func (*Term) SetReader added in v0.1.5

func (t *Term) SetReader(r io.Reader)

SetReader sets the reader for the terminal.

type TermOptFn added in v0.1.5

type TermOptFn func(*Options)

TermOptFn is an option function for the terminal.

func WithInterruptFn added in v0.1.5

func WithInterruptFn(fn func(error)) TermOptFn

WithInterruptFn sets the interrupt function for the terminal.

func WithReader added in v0.1.5

func WithReader(r io.Reader) TermOptFn

WithReader sets the reader for the terminal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳