termx

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Error = color.New()
View Source
var Spinner = spinnerCore{
	// contains filtered or unexported fields
}

Functions

func IsInteractive

func IsInteractive() bool

func ReadKey

func ReadKey(prompt ...string) (rune, error)

ReadKey writes the prompt to the terminal and waits for a single key press. It returns the key pressed as a rune, handling multi-byte characters, and echoes it.

func ReadKeyOf

func ReadKeyOf(prompt string, keys ...rune) (rune, error)

ReadKeyOf writes the prompt and waits for a key press that matches one of the provided runes. It keeps prompting until a valid key is pressed, echoes it, and returns that rune.

func ReadKeyOfSilent

func ReadKeyOfSilent(prompt string, keys ...rune) (rune, error)

ReadKeyOfSilent writes the prompt and waits for a key press that matches one of the provided runes silently. It keeps prompting until a valid key is pressed and returns that rune.

func ReadKeyOrDefaultOf

func ReadKeyOrDefaultOf(prompt string, def rune, others ...rune) (rune, error)

ReadKeyOrDefaultOf writes the prompt and waits for a key press that matches one of the provided runes. If the Enter key (rune '\r') is pressed, it echoes and returns the default rune.

func ReadKeyOrDefaultOfSilent

func ReadKeyOrDefaultOfSilent(prompt string, def rune, others ...rune) (rune, error)

ReadKeyOrDefaultOfSilent writes the prompt and waits for a key press that matches one of the provided runes silently. If the Enter key (rune '\r') is pressed, it returns the default rune.

func ReadKeySilent

func ReadKeySilent(prompt ...string) (rune, error)

ReadKeySilent writes the prompt to the terminal and waits for a single key press silently. It returns the key pressed as a rune, handling multi-byte characters.

func ReadLine

func ReadLine(prompt string) (string, error)

ReadLine reads a line from the terminal based on a prompt

func ReadPrompt added in v0.0.2

func ReadPrompt(ctx context.Context, contr Controller) (string, error)

Types

type Controller added in v0.0.2

type Controller interface {
	GetPrompt(ctx context.Context) string
	GetHint(ctx context.Context) string
}

type ControllerMode added in v0.0.2

type ControllerMode interface {
	CycleMode(ctx context.Context)
}

type Printer added in v0.0.2

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

func NewPrinter added in v0.0.2

func NewPrinter() *Printer

func (*Printer) Print added in v0.0.2

func (p *Printer) Print(s string)

func (*Printer) Printf added in v0.0.2

func (p *Printer) Printf(format string, a ...any)

func (*Printer) Println added in v0.0.2

func (p *Printer) Println(a ...any)

type Static added in v0.0.2

type Static struct{ Prompt, Hint string }

func (*Static) GetHint added in v0.0.2

func (c *Static) GetHint(ctx context.Context) string

func (*Static) GetPrompt added in v0.0.2

func (c *Static) GetPrompt(ctx context.Context) string

Jump to

Keyboard shortcuts

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