line

package module
v0.0.0-...-03b4e7d Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: BSD-2-Clause Imports: 14 Imported by: 1

README

(Lib)Line

A full reimplementation of SerenityOS's LibLine in Go.

LibLine is a full-featured terminal line editor with support for:

  • Flexible autocompletion
  • Live prompt and buffer update/stylisation
  • Multiline editing
  • and more.

The API is a complete clone of SerenityOS's LibLine, an example can be found in example/.

This implementation is currently incomplete, and has missing or otherwise buggy features:

  • LibLine's history file format is not implemented yet
  • Editor config is not implemented yet (~/.config/lib/line.ini)
  • Some editor internal functions are left unimplemented
  • And probably many more bugs not yet encountered.

Documentation

Index

Constants

View Source
const (
	ModifierShift = 1
	ModifierAlt   = 2
	ModifierCtrl  = 4
)

Variables

View Source
var StyleReset = Style{
	ForegroundColor: Color{
		Xterm8:   XtermColorDefault,
		IsXterm:  true,
		HasValue: true,
	},
	BackgroundColor: Color{
		Xterm8:   XtermColorDefault,
		IsXterm:  true,
		HasValue: true,
	},
	Hyperlink: "",
}

Functions

This section is empty.

Types

type AllowPanics

type AllowPanics int
const (
	PanicsEnabled AllowPanics = iota
	PanicsDisabled
)

type BracketedPaste

type BracketedPaste int
const (
	BracketedPasteEnabled BracketedPaste = iota
	BracketedPasteDisabled
)

type Color

type Color struct {
	R uint8
	G uint8
	B uint8

	Xterm8  XtermColor
	IsXterm bool

	HasValue bool
}

func MakeXtermColor

func MakeXtermColor(color XtermColor) Color

type Completion

type Completion struct {
	Text                      string
	TrailingTrivia            string
	DisplayTrivia             string
	Style                     Style
	StartIndex                uint32
	InputOffset               uint32
	StaticOffset              uint32
	InvariantOffset           uint32
	AllowCommitWithoutListing bool
	// contains filtered or unexported fields
}

type Config

type Config struct {
	RefreshBehavior RefreshBehavior
	SignalHandler   SignalHandler
	AllowPanics     AllowPanics
	BracketedPaste  BracketedPaste
}

type Editor

type Editor interface {
	Initialize()
	GetLine(prompt string) (string, error)

	AddToHistory(line string)
	LoadHistory(path string) error
	SaveHistory(path string) error

	RegisterKeybinding(keys []key, binding KeybindingCallback)
	ActualRenderedStringMetrics(line string) StringMetrics

	SetTabCompletionHandler(handler TabCompletionHandler)
	SetPasteHandler(handler PasteHandler)
	SetInterruptHandler(handler func())
	SetRefreshHandler(handler func(editor Editor))

	SetLine(string)
	Line() string
	LineUpTo(n uint32) string

	SetPrompt(prompt string)

	NumLines() uint32

	InsertString(str string)
	InsertChar(ch rune)

	Stylize(span Span, style Style)
	StripStyles()

	TransformSuggestionOffsets(invariant uint32, static uint32, mode SpanMode) (uint32, uint32)

	TerminalSize() Winsize

	Finish()
	Reset()
	IsEditing() bool
}

func NewEditor

func NewEditor() Editor

func NewEditorWithConfig

func NewEditorWithConfig(config *Config) Editor
type Hyperlink string

type KeyBinding

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

type KeybindingCallback

type KeybindingCallback func([]key, Editor) bool

type LineMetrics

type LineMetrics struct {
	MaskedChars []MaskedChar
	Length      uint32
}

func (*LineMetrics) TotalLength

func (m *LineMetrics) TotalLength() uint32

type Mask

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

func NewMask

func NewMask(replacement string, mode MaskMode) *Mask

type MaskMode

type MaskMode int
const (
	MaskModeReplaceEntireSelection MaskMode = iota
	MaskModeReplaceEachCodePointInSelection
)

type MaskedChar

type MaskedChar struct {
	Position       uint32
	OriginalLength uint32
	MaskedLength   uint32
}

type PasteHandler

type PasteHandler func(pastedData string, editor Editor)

type RefreshBehavior

type RefreshBehavior int
const (
	RefreshBehaviorLazy RefreshBehavior = iota
	RefreshBehaviorEager
)

type SignalHandler

type SignalHandler int
const (
	SignalHandlerEnabled SignalHandler = iota
	SignalHandlerDisabled
)

type Span

type Span struct {
	Start uint32
	End   uint32
	Mode  SpanMode
}

type SpanMode

type SpanMode int
const (
	SpanModeByte SpanMode = iota
	SpanModeRune
)

type StringMetrics

type StringMetrics struct {
	LineMetrics   []LineMetrics
	TotalLength   uint32
	MaxLineLength uint32
}

func (*StringMetrics) LinesWithAddition

func (m *StringMetrics) LinesWithAddition(offset *StringMetrics, columnWidth uint32) uint32

func (*StringMetrics) OffsetWithAddition

func (m *StringMetrics) OffsetWithAddition(offset *StringMetrics, columnWidth uint32) uint32

func (*StringMetrics) Reset

func (m *StringMetrics) Reset()

type Style

type Style struct {
	ForegroundColor Color
	BackgroundColor Color
	Bold            bool
	Italic          bool
	Underline       bool
	Hyperlink       Hyperlink
	Mask            *Mask
}

func (*Style) IsEmpty

func (s *Style) IsEmpty() bool

func (*Style) UnifyWith

func (s *Style) UnifyWith(other Style)

type TabCompletionHandler

type TabCompletionHandler func(editor Editor) []Completion

type VTState

type VTState int
const (
	VTStateFree VTState = iota
	VTStateEscape
	VTStateBracket
	VTStateBracketArgsSemi
	VTStateTitle
)

type Winsize

type Winsize struct {
	Row uint16
	Col uint16
}

type XtermColor

type XtermColor int
const (
	XtermColorBlack XtermColor = iota
	XtermColorRed
	XtermColorGreen
	XtermColorYellow
	XtermColorBlue
	XtermColorMagenta
	XtermColorCyan
	XtermColorWhite
	XtermColorUnchanged
	XtermColorDefault
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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