edit

package
v0.0.0-...-8666326 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2014 License: BSD-2-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package edit implements a full-righteature line editor.

Index

Constants

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

View Source
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
)
View Source
const (
	EscTimeout time.Duration = 10 * time.Millisecond
	CPRTimeout               = 10 * time.Millisecond
)
View Source
const (
	CPRWaitTimeout = 10 * time.Millisecond
)
View Source
const (
	ReaderOutChanSize int = 16
)
View Source
const (
	RuneTimeout rune = -1
)

Variables

View Source
var (
	ErrTimeout = errors.New("timed out")
	BadCPR     = errors.New("bad CPR")
)
View Source
var DefaultBinding = Key{DefaultBindingRune, 0}
View Source
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",
}
View Source
var InvalidPos = pos{-1, -1}
View Source
var KeyNames = map[rune]string{
	Tab: "Tab", Enter: "Enter", Backspace: "Backspace",
}
View Source
var LackEOL = "\033[7m\u23ce\033[m\n"
View Source
var ZeroKey = Key{}

Functions

func CleanupTerminal

func CleanupTerminal(file *os.File, savedTermios *tty.Termios) error

func ForceWcWidth

func ForceWcWidth(s string, width int) string

func Highlight

func Highlight(name, input string, ev *eval.Evaluator) chan parse.Item

func SetupTerminal

func SetupTerminal(file *os.File) (*tty.Termios, error)

func TrimWcWidth

func TrimWcWidth(s string, wmax int) string

func WcWidth

func WcWidth(r rune) int

func WcWidths

func WcWidths(s string) (w int)

Types

type BadEscSeq

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

func (*BadEscSeq) Error

func (bes *BadEscSeq) Error() 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, ev *eval.Evaluator, sigs <-chan os.Signal) *Editor

NewEditor creates an Editor.

func (*Editor) ReadLine

func (ed *Editor) ReadLine(prompt, rprompt func() string) (lr LineRead)

ReadLine reads a line interactively. TODO(xiaq): ReadLine currently handles SIGINT and SIGWINCH and swallows all other signals.

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 Key

type Key struct {
	Rune rune
	Mod  Mod
}

func (Key) String

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

type LineRead

type LineRead struct {
	Line string
	EOF  bool
	Err  error
}

LineRead is the result of ReadLine. Exactly one member is non-zero, making it effectively a tagged union.

type Mod

type Mod byte
const (
	Shift Mod = 1 << iota
	Alt
	Ctrl
)

type OneRead

type OneRead struct {
	Key Key
	CPR pos
	Err error
}

type Reader

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

Reader converts a stream of runes into a stream of Keys

func NewReader

func NewReader(f *os.File) *Reader

func (*Reader) Chan

func (rd *Reader) Chan() <-chan OneRead

func (*Reader) Continue

func (rd *Reader) Continue()

func (*Reader) Quit

func (rd *Reader) Quit()

func (*Reader) Stop

func (rd *Reader) Stop()

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

Directories

Path Synopsis
Package tty wraps tty ioctls.
Package tty wraps tty ioctls.

Jump to

Keyboard shortcuts

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