Documentation
¶
Overview ¶
Package edit implements a command line editor.
Index ¶
- Constants
- Variables
- func ForceWcWidth(s string, width int) string
- func TrimEachLineWcWidth(s string, width int) string
- func TrimWcWidth(s string, wmax int) string
- func WcWidth(r rune) int
- func WcWidths(s string) (w int)
- type ArgCompleter
- type AsyncReader
- type BindingTable
- type BoundFunc
- type Builtin
- type BuiltinAsFnValue
- type BuiltinPrompt
- type CompleterTable
- type Editor
- type FnAsArgCompleter
- type FnAsBoundFunc
- type FnAsPrompt
- type FuncArgCompleter
- type Key
- type Lister
- type Mod
- type Mode
- type ModeType
- type Placeholderer
- type Prompt
- type PromptVariable
- type Reader
- type Token
- type TokenKind
- Bugs
Constants ¶
const ( F1 rune = -iota - 1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Up Down Right Left Home Insert Delete End PageUp PageDown DefaultBindingRune // A special value used in DefaultBinding Tab = '\t' Enter = '\n' Backspace = 0x7f )
Special negative runes to represent function keys, used in the Rune field of the Key struct.
const ( S_IWOTH = 0x2 // Writable by other S_IXGRP = 0x8 // Executable by group S_IXOTH = 0x1 // Executable by other )
Weirdly, permission masks for group and other are missing on platforms other than linux, darwin and netbsd. So we replicate some of them here.
Variables ¶
var ( ErrCompleterIndexMustBeString = errors.New("index of completer table must be string") ErrCompleterValueMustBeFunc = errors.New("value of completer table must be function") )
var ( ErrTakeNoArg = errors.New("editor builtins take no arguments") ErrEditorInactive = errors.New("editor inactive") ErrKeyMustBeString = errors.New("key must be string") )
Errors thrown to Evaler.
var ( // Default is used in the key binding table to indicate default binding. Default = Key{DefaultBindingRune, 0} )
Predefined special Key values.
var DefaultArgCompleter = ""
var ErrPromptMustBeStringOrFunc = errors.New("prompt must be string or function")
var ErrStoreOffline = errors.New("store offline")
var ( // EscSequenceTimeout is the amount of time within which runes that make up // an escape sequence are supposed to follow each other. Modern terminal // emulators send escape sequences very fast, so 10ms is more than // sufficient. SSH connections on a slow link might be problematic though. EscSequenceTimeout = 10 * time.Millisecond )
var Logger = util.GetLogger("[edit] ")
Functions ¶
func ForceWcWidth ¶
ForceWcWidth forces the string s to the given display width by trimming and padding.
func TrimEachLineWcWidth ¶
func TrimWcWidth ¶
TrimWcWidth trims the string s so that it has a width of at most wmax.
Types ¶
type ArgCompleter ¶
ArgCompleter is an argument completer. Its Complete method is called with all words of the form. There are at least two words: the first one being the form head and the last word being the current argument to complete. It should return a list of candidates for the current argument and errors.
type AsyncReader ¶
type AsyncReader struct {
// contains filtered or unexported fields
}
AsyncReader delivers a Unix fd stream to a channel of runes.
func NewAsyncReader ¶
func NewAsyncReader(rd *os.File) *AsyncReader
NewAsyncReader creates a new AsyncReader from a file.
func (*AsyncReader) Chan ¶
func (ar *AsyncReader) Chan() <-chan rune
Chan returns a channel onto which the AsyncReader writes the runes it reads.
func (*AsyncReader) Close ¶
func (ar *AsyncReader) Close()
Close releases files and channels associated with the AsyncReader. It does not close the file used to create it.
func (*AsyncReader) ErrorChan ¶
func (ar *AsyncReader) ErrorChan() <-chan error
ErrorChan returns a channel onto which the AsyncReader writes the errors it encounters.
func (*AsyncReader) Run ¶
func (ar *AsyncReader) Run()
Run runs the AsyncReader. It blocks until Quit is called and should be called in a separate goroutine.
type BindingTable ¶
type BindingTable struct {
// contains filtered or unexported fields
}
BindingTable adapts a binding table to eval.IndexSetter, so that it can be manipulated in elvish script.
func (BindingTable) IndexSet ¶
func (bt BindingTable) IndexSet(idx, v eval.Value)
func (BindingTable) Kind ¶
func (BindingTable) Kind() string
func (BindingTable) Repr ¶
func (bt BindingTable) Repr(indent int) string
type BoundFunc ¶
BoundFunc is a function bound to a key. It is either a Builtin or an FnAsBoundFunc.
type Builtin ¶
type Builtin struct {
// contains filtered or unexported fields
}
Builtin records an editor builtin.
type BuiltinAsFnValue ¶
type BuiltinAsFnValue struct {
// contains filtered or unexported fields
}
BuiltinAsFnValue adapts a Builtin to satisfy eval.FnValue, so that it can be called from elvish script.
func (*BuiltinAsFnValue) Call ¶
func (eb *BuiltinAsFnValue) Call(ec *eval.EvalCtx, args []eval.Value)
func (*BuiltinAsFnValue) Kind ¶
func (*BuiltinAsFnValue) Kind() string
func (*BuiltinAsFnValue) Repr ¶
func (eb *BuiltinAsFnValue) Repr(int) string
type BuiltinPrompt ¶
BuiltinPrompt is a trivial implementation of Prompt.
func (BuiltinPrompt) Call ¶
func (bp BuiltinPrompt) Call(ed *Editor) string
type CompleterTable ¶
type CompleterTable map[string]ArgCompleter
CompleterTable provides $le:completer. It implements eval.IndexSetter.
func (CompleterTable) Kind ¶
func (CompleterTable) Kind() string
func (CompleterTable) Repr ¶
func (ct CompleterTable) Repr(indent int) string
type Editor ¶
type Editor struct {
// contains filtered or unexported fields
}
Editor keeps the status of the line editor.
type FnAsArgCompleter ¶
type FnAsBoundFunc ¶
FnAsBoundFunc adapts eval.Fn to BoundFunc, so that functions in elvish script can be bound to keys.
func (FnAsBoundFunc) Call ¶
func (c FnAsBoundFunc) Call(ed *Editor)
func (FnAsBoundFunc) Repr ¶
func (c FnAsBoundFunc) Repr(indent int) string
type FnAsPrompt ¶
FnAsPrompt adapts a eval.Fn to a Prompt.
func (FnAsPrompt) Call ¶
func (c FnAsPrompt) Call(ed *Editor) string
type FuncArgCompleter ¶
type FuncArgCompleter struct {
// contains filtered or unexported fields
}
type Lister ¶
type Lister interface { // List renders the listing under the given constraint of width and maximum // height. It returns a rendered buffer. List(width, maxHeight int) *buffer }
Lister is a mode with a listing.
type Mod ¶
type Mod byte
Mod represents a modifier key.
const ( // Shift is the shift modifier. It is only applied to special keys (e.g. // Shift-F1). For instance 'A' and '@' which are typically entered with the // shift key pressed, are not considered to be shift-modified. Shift Mod = 1 << iota // Alt is the alt modifier, traditionally known as the meta modifier. Alt Ctrl )
Values for Mod.
type Mode ¶
type Mode interface { Mode() ModeType // ModeLine renders a mode line under the given width constraint. It // returns a rendered buffer. ModeLine(width int) *buffer }
Mode is an editor mode.
type Placeholderer ¶
type Placeholderer interface {
Placeholder() string
}
type PromptVariable ¶
type PromptVariable struct {
Prompt *Prompt
}
PromptVariable is a prompt function variable. It may be set to a String, a Fn, or a BuiltinPrompt. It provides $le:prompt and $le:rprompt.
func (PromptVariable) Get ¶
func (pv PromptVariable) Get() eval.Value
func (PromptVariable) Set ¶
func (pv PromptVariable) Set(v eval.Value)
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader converts a stream of events on separate channels.
func (*Reader) CPRChan ¶
func (rd *Reader) CPRChan() <-chan pos
CPRChan returns the channel onto which the Reader writes CPRs it has read.
func (*Reader) Close ¶
func (rd *Reader) Close()
Close releases files associated with the Reader. It does not close the file used to create it.
func (*Reader) ErrorChan ¶
ErrorChan returns the channel onto which the Reader writes errors it came across during the reading process.
Notes ¶
Bugs ¶
AsyncReader relies on the undocumented fact that (*os.File).Read returns an *os.File.PathError
buffer.write drops unprintable runes silently
Source Files
¶
- arg_completer.go
- async_reader.go
- bang.go
- binding.go
- builtins.go
- completers.go
- completion.go
- editor.go
- histlist.go
- history.go
- insert.go
- key.go
- listing.go
- location.go
- ls_colors.go
- minmax.go
- mode.go
- module.go
- navigation.go
- nodeutil.go
- prompt.go
- reader.go
- style.go
- styled.go
- stylists.go
- token.go
- wcwidth.go
- writer.go