edit

package
v0.0.0-...-5da5f19 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2016 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package edit implements a command line editor.

Index

Constants

View Source
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.

View Source
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

View Source
var (
	ErrCompleterIndexMustBeString = errors.New("index of completer table must be string")
	ErrCompleterValueMustBeFunc   = errors.New("value of completer table must be function")
)
View Source
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.

View Source
var (
	// Default is used in the key binding table to indicate default binding.
	Default = Key{DefaultBindingRune, 0}
)

Predefined special Key values.

View Source
var DefaultArgCompleter = ""
View Source
var ErrMustBeFn = errors.New("must be function")
View Source
var ErrStoreOffline = errors.New("store offline")
View Source
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
)
View Source
var Logger = util.GetLogger("[edit] ")

Functions

func ForceWcWidth

func ForceWcWidth(s string, width int) string

ForceWcWidth forces the string s to the given display width by trimming and padding.

func MustBeFn

func MustBeFn(v eval.Value) error

MustBeFn validates whether a Value is an Fn.

func TrimEachLineWcWidth

func TrimEachLineWcWidth(s string, width int) string

func TrimWcWidth

func TrimWcWidth(s string, wmax int) string

TrimWcWidth trims the string s so that it has a width of at most wmax.

func WcWidth

func WcWidth(r rune) int

WcWidth returns the width of a rune when displayed on the terminal.

func WcWidths

func WcWidths(s string) (w int)

WcWidths returns the width of a string when displayed on the terminal, assuming no soft line breaks.

Types

type ArgCompleter

type ArgCompleter interface {
	Complete([]string, *Editor) ([]*candidate, error)
}

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) Quit

func (ar *AsyncReader) Quit()

Quit terminates the loop of Run.

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) IndexOne

func (bt BindingTable) IndexOne(idx eval.Value) eval.Value

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 BoolExposer

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

BoolExposer implements eval.Variable and exposes a bool to elvishscript.

func (BoolExposer) Get

func (be BoolExposer) Get() eval.Value

func (BoolExposer) Set

func (be BoolExposer) Set(v eval.Value)

type BoundFunc

type BoundFunc interface {
	eval.Reprer
	Call(ed *Editor)
}

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.

func (Builtin) Call

func (b Builtin) Call(ed *Editor)

func (Builtin) Repr

func (b Builtin) Repr(int) string

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 CompleterTable

type CompleterTable map[string]ArgCompleter

CompleterTable provides $le:completer. It implements eval.IndexSetter.

func (CompleterTable) IndexOne

func (ct CompleterTable) IndexOne(idx eval.Value) eval.Value

func (CompleterTable) IndexSet

func (ct CompleterTable) IndexSet(idx eval.Value, v eval.Value)

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.

func NewEditor

func NewEditor(file *os.File, sigs chan os.Signal, ev *eval.Evaler, st *store.Store) *Editor

NewEditor creates an Editor.

func (*Editor) CallFn

func (ed *Editor) CallFn(fn eval.FnValue, args ...eval.Value)

CallFn calls an Fn, displaying its outputs and possible errors as editor notifications. It is the preferred way to call a Fn while the editor is active.

func (*Editor) ReadLine

func (ed *Editor) ReadLine() (line string, err error)

ReadLine reads a line interactively.

type FnAsArgCompleter

type FnAsArgCompleter struct {
	Fn eval.FnValue
}

func (FnAsArgCompleter) Complete

func (fac FnAsArgCompleter) Complete(words []string, ed *Editor) ([]*candidate, error)

type FnAsBoundFunc

type FnAsBoundFunc struct {
	Fn eval.FnValue
}

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 FuncArgCompleter

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

func (FuncArgCompleter) Complete

func (fac FuncArgCompleter) Complete(words []string, ed *Editor) ([]*candidate, error)

type History

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

func (History) IndexOne

func (hv History) IndexOne(idx eval.Value) eval.Value

func (History) Iterate

func (hv History) Iterate(f func(eval.Value) bool)

func (History) Kind

func (hv History) Kind() string

func (History) Len

func (hv History) Len() int

func (History) Repr

func (hv History) Repr(int) string

type Key

type Key struct {
	Rune rune
	Mod  Mod
}

Key represents a single keyboard input, typically assembled from a escape sequence.

func (Key) String

func (k Key) String() (s string)

type LineExposer

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

func (LineExposer) Get

func (l LineExposer) Get() eval.Value

func (LineExposer) Set

func (l LineExposer) Set(v eval.Value)

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 ModeType

type ModeType int

type Placeholderer

type Placeholderer interface {
	Placeholder() string
}

type Reader

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

Reader converts a stream of events on separate channels.

func NewReader

func NewReader(f *os.File) *Reader

NewReader creates a new Reader on the given terminal file.

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

func (rd *Reader) ErrorChan() <-chan error

ErrorChan returns the channel onto which the Reader writes errors it came across during the reading process.

func (*Reader) KeyChan

func (rd *Reader) KeyChan() <-chan Key

KeyChan returns the channel onto which the Reader writes Keys it has read.

func (*Reader) MouseChan

func (rd *Reader) MouseChan() <-chan mouseEvent

MouseChan returns the channel onto which the Reader writes mouse events it has read.

func (*Reader) PasteChan

func (rd *Reader) PasteChan() <-chan bool

func (*Reader) Quit

func (rd *Reader) Quit()

Quit terminates the loop of Run.

func (*Reader) Run

func (rd *Reader) Run()

Run runs the Reader. It blocks until Quit is called and should be called in a separate goroutine.

type StringExposer

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

func (StringExposer) Get

func (se StringExposer) Get() eval.Value

func (StringExposer) Set

func (se StringExposer) Set(v eval.Value)

type Token

type Token struct {
	Type      TokenKind
	Text      string
	Node      parse.Node
	MoreStyle string
}

Token is a leaf of the parse tree.

type TokenKind

type TokenKind int

TokenKind classifies Token's.

const (
	ParserError TokenKind = iota
	Bareword
	SingleQuoted
	DoubleQuoted
	Variable
	Wildcard
	Tilde
	Sep
)

Values for TokenKind.

Notes

Bugs

  • AsyncReader relies on the undocumented fact that (*os.File).Read returns an *os.File.PathError

  • buffer.write drops unprintable runes silently

Jump to

Keyboard shortcuts

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