Documentation ¶
Overview ¶
Package edit implements a full-righteature line editor.
Index ¶
- Constants
- Variables
- func CleanupTerminal(file *os.File, savedTermios *tty.Termios) error
- func ForceWcWidth(s string, width int) string
- func Highlight(name, input string, ev *eval.Evaluator) chan parse.Item
- func SetupTerminal(file *os.File) (*tty.Termios, error)
- func TrimWcWidth(s string, wmax int) string
- func WcWidth(r rune) int
- func WcWidths(s string) (w int)
- type BadEscSeq
- type Editor
- type Highlighter
- type Key
- type LineRead
- type Mod
- type OneRead
- type Reader
- Bugs
Constants ¶
const ( ItemValidCommand parse.ItemType = -iota - 1 ItemInvalidCommand ItemValidVariable ItemInvalidVariable )
Pseudo-ItemType's used by the Highlighter. They are given negative values to avoid conflict with genuine ItemType's. They can be regarded as some "sub-ItemType" of ItemBare, since only barewords are inspected and marked with these pseudo-ItemType's.
const ( Invalid rune = -iota F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Up Down Right Left Home Insert Delete End PageUp PageDown DefaultBindingRune // Used in key of keyBinding for default binding Tab = '\t' Enter = '\n' Backspace = 0x7f )
const ( EscTimeout time.Duration = 10 * time.Millisecond CPRTimeout = 10 * time.Millisecond )
const (
CPRWaitTimeout = 10 * time.Millisecond
)
const (
ReaderOutChanSize int = 16
)
const (
RuneTimeout rune = -1
)
Variables ¶
var ( ErrTimeout = errors.New("timed out") BadCPR = errors.New("bad CPR") )
var DefaultBinding = Key{DefaultBindingRune, 0}
var FunctionKeyNames = [...]string{
"(Invalid)",
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
"Up", "Down", "Right", "Left",
"Home", "Insert", "Delete", "End", "PageUp", "PageDown",
}
var InvalidPos = pos{-1, -1}
var LackEOL = "\033[7m\u23ce\033[m\n"
var ZeroKey = Key{}
Functions ¶
func ForceWcWidth ¶
func TrimWcWidth ¶
Types ¶
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor keeps the status of the line editor.
type Highlighter ¶
type Highlighter struct {
// contains filtered or unexported fields
}
Highlighter is an enhanced Lexer with the knowledge of the validity of command names and variable names.
Generally speaking, this is not possible without properly parsing and evaluating the source, performing its side effects. However in the case of single bareword terms, some heuristics can be applied. Be noted though, the heuristics can be quite fragile in case of syntax changes, so it's important to keep the syntax either simple (so that the heuristics is easy to implement) or stable (so that the heuristics doesn't have to be modified), or both.
type LineRead ¶
LineRead is the result of ReadLine. Exactly one member is non-zero, making it effectively a tagged union.
Notes ¶
Bugs ¶
When completing, CommandContext is not supported
When completing, ArgContext is treated like RedirFilenameContext
When completing, only the case of ctx.ThisFactor.Typ == StringFactor is supported
When completing, completion.typ is always ItemBare
startReadline assumes that column number starts from 0
Error in Editor.finishReadLine may override earlier error
buffer.write drops unprintable runes silently