input

package
v0.0.0-...-9799baa Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const NO_RESULT = -1

Variables

This section is empty.

Functions

func Code

func Code(lexerName, styleName string, lineLimit, tabSize int) string

Creates a small code editor with syntax highlighting and line numbers. Does not work with screen scrolling, thus is best for small snippits of code.

func Confirm

func Confirm(question string) (confirmed bool)

Prompts the user to enter a boolean.

func CookedMode

func CookedMode()

Enter cooked terminal mode, meaning key presses are only received after pressing enter. Does nothing if it's already in cooked mode.

func Integer

func Integer(question string) (answer int, err error)

Prompts the user to enter an integer.

func Password

func Password() (passHash string, err error)

Prompts the user to enter a password. The password is not display password in terminal. The password is hashed before being returned.

func RawKeys

func RawKeys() (keys iter.Seq[Key])

Enters raw terminal mode and then gets key press as an iterator. Whenever pulling from the iterator the program will pause until the next key press. The returned iterator must be stopped to exit raw mode. Will immediately terminate the program with code 0 if the user enters ctrl+c.

func RawMode

func RawMode() (err error)

Enter raw terminal mode, meaning each key press are received one by one. Does nothing if it's already in raw mode.

func SetOnEntered

func SetOnEntered(listener func())

func SetOnSelected

func SetOnSelected(listener func())

func String

func String(question string) (answer string, err error)

Prompts the user to enter a string.

func UnsetOnEntered

func UnsetOnEntered()

func UnsetOnSelected

func UnsetOnSelected()

Types

type Choice

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

func NewChoice

func NewChoice(options ...string) *Choice

Creates a new choice with options.

func (*Choice) Add

func (choice *Choice) Add(option string) *Choice

Appends a single new option to a choice.

func (*Choice) AddSlice

func (choice *Choice) AddSlice(options []string) *Choice

Appends a slice of new options to a choice.

func (*Choice) Ask

func (choice *Choice) Ask() *Choice

Ask the user, replacing any older selection. May fail to select anything, leaving the result as NO_RESULT.

func (*Choice) Forget

func (choice *Choice) Forget() *Choice

Forgets any option already selected.

func (*Choice) ResultIndex

func (choice *Choice) ResultIndex() int

Gets the index of the selected option, asking the user if needed. Returns NO_RESULT if failed to select anything.

func (*Choice) ResultString

func (choice *Choice) ResultString() string

Get the string of the selected option, asking the user if needed. Returns an empty string if failed to select anything.

type Key

type Key uint64
const (
	KEY_UNKNOWN     Key = 0
	KEY_END_OF_TEXT Key = 3
	KEY_TAB         Key = 9
	KEY_ENTER       Key = 13
	KEY_ESCAPE      Key = 27
)
const (
	KEY_SPACE Key = iota + 32
	KEY_EXCLAMATION
	KEY_QUOTATION_MARK
	KEY_HASH
	KEY_DOLLAR
	KEY_PERCENT
	KEY_AMPERSAND
	KEY_APOSTROPHE
	KEY_LEFT_PARENTHESIS
	KEY_RIGHT_PARENTHESIS
	KEY_ASTERISK
	KEY_PLUS_SIGN
	KEY_COMMA
	KEY_HYPHEN
	KEY_PERIOD
	KEY_SLASH

	KEY_ZERO
	KEY_ONE
	KEY_TWO
	KEY_THREE
	KEY_FOUR
	KEY_FIVE
	KEY_SIX
	KEY_SEVEN
	KEY_EIGHT
	KEY_NINE

	KEY_COLON
	KEY_SEMICOLON
	KEY_LESS_THAN
	KEY_EQUAL
	KEY_GREATER_THAN
	KEY_QUESTION_MARK
	KEY_AT_SIGN

	KEY_SHIFT_A
	KEY_SHIFT_B
	KEY_SHIFT_C
	KEY_SHIFT_D
	KEY_SHIFT_E
	KEY_SHIFT_F
	KEY_SHIFT_G
	KEY_SHIFT_H
	KEY_SHIFT_I
	KEY_SHIFT_J
	KEY_SHIFT_K
	KEY_SHIFT_L
	KEY_SHIFT_M
	KEY_SHIFT_N
	KEY_SHIFT_O
	KEY_SHIFT_P
	KEY_SHIFT_Q
	KEY_SHIFT_R
	KEY_SHIFT_S
	KEY_SHIFT_T
	KEY_SHIFT_U
	KEY_SHIFT_V
	KEY_SHIFT_W
	KEY_SHIFT_X
	KEY_SHIFT_Y
	KEY_SHIFT_Z

	KEY_LEFT_SQUARE_BRACKET
	KEY_BACK_SLASH
	KEY_RIGHT_SQUARE_BRACKET
	KEY_EXPONENT
	KEY_UNDERSCORE
	KEY_GRAVE

	KEY_A
	KEY_B
	KEY_C
	KEY_D
	KEY_E
	KEY_F
	KEY_G
	KEY_H
	KEY_I
	KEY_J
	KEY_K
	KEY_L
	KEY_M
	KEY_N
	KEY_O
	KEY_P
	KEY_Q
	KEY_R
	KEY_S
	KEY_T
	KEY_U
	KEY_V
	KEY_W
	KEY_X
	KEY_Y
	KEY_Z

	KEY_LEFT_CURLY_BRACE
	KEY_PIPE
	KEY_RIGHT_CURLY_BRASE
	KEY_TILDE
	KEY_BACKSPACE
)
const (
	KEY_ALT_A Key = iota*256 + 24859
	KEY_ALT_B
	KEY_ALT_C
	KEY_ALT_D
	KEY_ALT_E
	KEY_ALT_F
	KEY_ALT_G
	KEY_ALT_H
	KEY_ALT_I
	KEY_ALT_J
	KEY_ALT_K
	KEY_ALT_L
	KEY_ALT_M
	KEY_ALT_N
	KEY_ALT_O
	KEY_ALT_P
	KEY_ALT_Q
	KEY_ALT_R
	KEY_ALT_S
	KEY_ALT_T
	KEY_ALT_U
	KEY_ALT_V
	KEY_ALT_W
	KEY_ALT_X
	KEY_ALT_Y
	KEY_ALT_Z
)
const (
	KEY_UP        Key = 4283163
	KEY_DOWN      Key = 4348699
	KEY_RIGHT     Key = 4414235
	KEY_LEFT      Key = 4479771
	KEY_END       Key = 4610843
	KEY_HOME      Key = 4741915
	KEY_INSERT    Key = 2117229339
	KEY_DELETE    Key = 2117294875
	KEY_PAGE_UP   Key = 2117425947
	KEY_PAGE_DOWN Key = 2117491483
)

func KeyBind

func KeyBind() (key Key)

func RawKey

func RawKey() Key

func (Key) Name

func (key Key) Name() string

Jump to

Keyboard shortcuts

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