readline

package
v0.0.0-...-e65ccaf Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 13 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 (
	CursorUp    = CursorUpN(1)
	CursorDown  = CursorDownN(1)
	CursorRight = CursorRightN(1)
	CursorLeft  = CursorLeftN(1)
)
View Source
var ErrInterrupt = errors.New("Interrupt")

Functions

func CursorDownN

func CursorDownN(n int) string

func CursorLeftN

func CursorLeftN(n int) string

func CursorRightN

func CursorRightN(n int) string

func CursorUpN

func CursorUpN(n int) string

func IsTerminal

func IsTerminal(fd uintptr) bool

IsTerminal returns true if the given file descriptor is a terminal.

func UnsetRawMode

func UnsetRawMode(fd uintptr, termios any) error

Types

type Buffer

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

func NewBuffer

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

func (*Buffer) Add

func (b *Buffer) Add(r rune)

func (*Buffer) AddChar

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

func (*Buffer) ClearScreen

func (b *Buffer) ClearScreen()

func (*Buffer) Delete

func (b *Buffer) Delete()

func (*Buffer) DeleteBefore

func (b *Buffer) DeleteBefore()

func (*Buffer) DeleteRemaining

func (b *Buffer) DeleteRemaining()

func (*Buffer) DeleteWord

func (b *Buffer) DeleteWord()

func (*Buffer) DisplaySize

func (b *Buffer) DisplaySize() int

func (*Buffer) GetLineSpacing

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

func (*Buffer) IsEmpty

func (b *Buffer) IsEmpty() bool

func (*Buffer) MoveLeft

func (b *Buffer) MoveLeft()

func (*Buffer) MoveLeftWord

func (b *Buffer) MoveLeftWord()

func (*Buffer) MoveRight

func (b *Buffer) MoveRight()

func (*Buffer) MoveRightWord

func (b *Buffer) MoveRightWord()

func (*Buffer) MoveToEnd

func (b *Buffer) MoveToEnd()

func (*Buffer) MoveToStart

func (b *Buffer) MoveToStart()

func (*Buffer) Remove

func (b *Buffer) Remove()

func (*Buffer) Replace

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

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) StringN

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

func (*Buffer) StringNM

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

type History

type History struct {
	Buf      *arraylist.List[string]
	Autosave bool
	Pos      int
	Limit    int
	Filename string
	Enabled  bool
}

func NewHistory

func NewHistory() (*History, error)

func (*History) Add

func (h *History) Add(s string)

func (*History) Clear

func (h *History) Clear()

func (*History) Compact

func (h *History) Compact()

func (*History) Init

func (h *History) Init() error

func (*History) Next

func (h *History) Next() (line string)

func (*History) Prev

func (h *History) Prev() (line string)

func (*History) Save

func (h *History) Save() error

func (*History) Size

func (h *History) Size() int

type Instance

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

func New

func New(prompt Prompt) (*Instance, error)

func (*Instance) HistoryDisable

func (i *Instance) HistoryDisable()

func (*Instance) HistoryEnable

func (i *Instance) HistoryEnable()

func (*Instance) Readline

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

type InterruptError

type InterruptError struct {
	Line []rune
}

func (*InterruptError) Error

func (*InterruptError) Error() string

type Prompt

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

type Terminal

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

func NewTerminal

func NewTerminal() (*Terminal, error)

func (*Terminal) Read

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

type Termios

type Termios syscall.Termios

func SetRawMode

func SetRawMode(fd uintptr) (*Termios, error)

Jump to

Keyboard shortcuts

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