term

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharNull      = 0
	CharLineStart = 1
	CharBackward  = 2
	CharInterrupt = 3
	CharDelete    = 4
	CharLineEnd   = 5
	CharForward   = 6
	CharBell      = 7
	CharCtrlH     = 8
	CharTab       = 9
	CharCtrlJ     = 10
	CharKill      = 11
	CharCtrlL     = 12
	CharEnter     = 13
	CharNext      = 14
	CharPrev      = 16
	CharBckSearch = 18
	CharFwdSearch = 19
	CharTranspose = 20
	CharCtrlU     = 21
	CharCtrlW     = 23
	CharCtrlY     = 25
	CharCtrlZ     = 26
	CharEsc       = 27
	CharSpace     = 32
	CharEscapeEx  = 91
	CharBackspace = 127
)
View Source
const (
	KeyDel    = 51
	KeyUp     = 65
	KeyDown   = 66
	KeyRight  = 67
	KeyLeft   = 68
	MetaEnd   = 70
	MetaStart = 72
)
View Source
const (
	Esc = "\x1b"

	CursorSave    = Esc + "[s"
	CursorRestore = Esc + "[u"

	CursorEOL  = Esc + "[E"
	CursorBOL  = Esc + "[1G"
	CursorHide = Esc + "[?25l"
	CursorShow = Esc + "[?25h"

	ClearToEOL  = Esc + "[K"
	ClearLine   = Esc + "[2K"
	ClearScreen = Esc + "[2J"
	CursorReset = Esc + "[0;0f"

	ColorGrey    = Esc + "[38;5;245m"
	ColorDefault = Esc + "[0m"

	StartBracketedPaste = Esc + "[?2004h"
	EndBracketedPaste   = Esc + "[?2004l"
)
View Source
const (
	CharBracketedPaste      = 50
	CharBracketedPasteStart = "00~"
	CharBracketedPasteEnd   = "01~"
)

Variables

View Source
var (
	ErrInputInterrupted = errors.New("input interrupted")
	ErrInputKilled      = errors.New("input killed")
	ErrReadlineInit     = errors.New("error initializing readline")
)
View Source
var (
	CursorUp    = CursorUpN(1)
	CursorDown  = CursorDownN(1)
	CursorRight = CursorRightN(1)
	CursorLeft  = CursorLeftN(1)
)

Functions

func CursorDownN added in v0.2.2

func CursorDownN(n int) string

func CursorLeftN added in v0.2.2

func CursorLeftN(n int) string

func CursorRightN added in v0.2.2

func CursorRightN(n int) string

func CursorUpN added in v0.2.2

func CursorUpN(n int) string

func InitRenderer

func InitRenderer() (*glamour.TermRenderer, error)

func PromptForBool

func PromptForBool(label string, defaultVal bool) bool

func PromptForKey added in v0.2.0

func PromptForKey(label string) uint16

func PromptForString

func PromptForString(
	label string,
	defaultVal string,
	validate func(string) error,
) string

func PromptSelectString added in v0.2.0

func PromptSelectString(
	label string,
	items []string,
) string

func ReadInput

func ReadInput(
	inputCh chan<- string,
	inputErrCh chan<- error,
	readyCh <-chan struct{},
)

func ReadInputOnce added in v0.2.0

func ReadInputOnce(rl *Instance) (string, error)

Types

type Buffer added in v0.2.2

type Buffer struct {
	DisplayPos int
	Pos        int
	Buf        *arraylist.List
	// LineHasSpace is an arraylist of bools to keep track of whether a line has a space at the end
	LineHasSpace *arraylist.List
	Prompt       *Prompt
	LineWidth    int
	Width        int
	Height       int
}

func NewBuffer added in v0.2.2

func NewBuffer(prompt *Prompt) (*Buffer, error)

func (*Buffer) Add added in v0.2.2

func (b *Buffer) Add(r rune)

func (*Buffer) AddChar added in v0.2.2

func (b *Buffer) AddChar(r rune, insert bool)

func (*Buffer) ClearScreen added in v0.2.2

func (b *Buffer) ClearScreen()

func (*Buffer) Delete added in v0.2.2

func (b *Buffer) Delete()

func (*Buffer) DeleteBefore added in v0.2.2

func (b *Buffer) DeleteBefore()

func (*Buffer) DeleteRemaining added in v0.2.2

func (b *Buffer) DeleteRemaining()

func (*Buffer) DeleteWord added in v0.2.2

func (b *Buffer) DeleteWord()

func (*Buffer) DisplaySize added in v0.2.2

func (b *Buffer) DisplaySize() int

func (*Buffer) GetLineSpacing added in v0.2.2

func (b *Buffer) GetLineSpacing(line int) bool

func (*Buffer) IsEmpty added in v0.2.2

func (b *Buffer) IsEmpty() bool

func (*Buffer) MoveLeft added in v0.2.2

func (b *Buffer) MoveLeft()

func (*Buffer) MoveLeftWord added in v0.2.2

func (b *Buffer) MoveLeftWord()

func (*Buffer) MoveRight added in v0.2.2

func (b *Buffer) MoveRight()

func (*Buffer) MoveRightWord added in v0.2.2

func (b *Buffer) MoveRightWord()

func (*Buffer) MoveToEnd added in v0.2.2

func (b *Buffer) MoveToEnd()

func (*Buffer) MoveToStart added in v0.2.2

func (b *Buffer) MoveToStart()

func (*Buffer) Remove added in v0.2.2

func (b *Buffer) Remove()

func (*Buffer) Replace added in v0.2.2

func (b *Buffer) Replace(r []rune)

func (*Buffer) String added in v0.2.2

func (b *Buffer) String() string

func (*Buffer) StringN added in v0.2.2

func (b *Buffer) StringN(n int) string

func (*Buffer) StringNM added in v0.2.2

func (b *Buffer) StringNM(n, m int) string

type Instance added in v0.2.2

type Instance struct {
	Prompt   *Prompt
	Terminal *Terminal
	History  *readline.History
	Pasting  bool
}

func InitReadline

func InitReadline(defaultValue string) (*Instance, error)

func (*Instance) Close added in v0.2.2

func (i *Instance) Close()

func (*Instance) Closed added in v0.2.2

func (i *Instance) Closed() bool

func (*Instance) HistoryDisable added in v0.2.2

func (i *Instance) HistoryDisable()

func (*Instance) HistoryEnable added in v0.2.2

func (i *Instance) HistoryEnable()

func (*Instance) Readline added in v0.2.2

func (i *Instance) Readline() (string, error)

type MultilineState

type MultilineState int
const (
	MultilineNone MultilineState = iota
	MultilinePrompt
	MultilineSystem
	MultilineTemplate
)

type Prompt added in v0.2.2

type Prompt struct {
	Prompt         string
	AltPrompt      string
	Placeholder    string
	AltPlaceholder string
	UseAlt         bool
}

type Renderer

type Renderer = glamour.TermRenderer

type ScreenBuf

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

func NewScreenBuf

func NewScreenBuf(w io.Writer) *ScreenBuf

func (*ScreenBuf) Clear

func (sb *ScreenBuf) Clear()

func (*ScreenBuf) String

func (sb *ScreenBuf) String() string

func (*ScreenBuf) WriteLine

func (sb *ScreenBuf) WriteLine(s string)

type Spinner

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

func NewSpinner

func NewSpinner(initialDuration time.Duration, initialMessage string) *Spinner

func (*Spinner) Start

func (s *Spinner) Start()

func (*Spinner) Stop

func (s *Spinner) Stop()

type Terminal added in v0.2.2

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

func NewTerminal added in v0.2.2

func NewTerminal() (*Terminal, error)

func (*Terminal) Close added in v0.2.2

func (t *Terminal) Close() error

func (*Terminal) Closed added in v0.2.2

func (t *Terminal) Closed() bool

func (*Terminal) Read added in v0.2.2

func (t *Terminal) Read() (rune, error)

Jump to

Keyboard shortcuts

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