edit

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 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 to represent default binding.

	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 = Key{DefaultBindingRune, 0}

Default is used in the key binding table to indicate default binding.

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 added in v0.3.0

func MustBeFn(v eval.Value) error

MustBeFn validates whether a Value is an Fn.

func TrimEachLineWcWidth added in v0.2.0

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 added in v0.3.0

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

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

func (BoolExposer) Get added in v0.3.0

func (be BoolExposer) Get() eval.Value

func (BoolExposer) Set added in v0.3.0

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

type BuiltinFn added in v0.4.0

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

BuiltinFn records an editor builtin.

func (*BuiltinFn) Call added in v0.4.0

func (bf *BuiltinFn) Call(ec *eval.EvalCtx, args []eval.Value, opts map[string]eval.Value)

func (*BuiltinFn) Kind added in v0.4.0

func (*BuiltinFn) Kind() string

func (*BuiltinFn) Repr added in v0.4.0

func (bf *BuiltinFn) 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) Active added in v0.4.0

func (ed *Editor) Active() bool

func (*Editor) ActiveMutex added in v0.4.0

func (ed *Editor) ActiveMutex() *sync.Mutex

func (*Editor) CallFn added in v0.3.0

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) Notify added in v0.4.0

func (ed *Editor) Notify(format string, args ...interface{})

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 FuncArgCompleter

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

func (FuncArgCompleter) Complete

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

type History added in v0.3.0

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

func (History) IndexOne added in v0.3.0

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

func (History) Iterate added in v0.3.0

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

func (History) Kind added in v0.3.0

func (hv History) Kind() string

func (History) Len added in v0.3.0

func (hv History) Len() int

func (History) Repr added in v0.3.0

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 ToKey added in v0.4.0

func ToKey(idx eval.Value) Key

ToKey converts an elvish String to a Key. If the passed Value is not a String, it throws an error.

func (Key) String

func (k Key) String() string

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 added in v0.2.0

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 added in v0.3.0

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

func (StringExposer) Get added in v0.3.0

func (se StringExposer) Get() eval.Value

func (StringExposer) Set added in v0.3.0

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

type Stylist added in v0.3.0

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

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.

func (TokenKind) String added in v0.3.0

func (i TokenKind) String() string

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