Documentation
¶
Overview ¶
Package ui contains types that may be used by different editor frontends.
Index ¶
- Constants
- Variables
- func BuffersHeight(bufs ...*Buffer) (l int)
- func CellsWidth(cs []Cell) int
- func CompareCells(r1, r2 []Cell) (bool, int)
- func KeyBuiltin(ec *eval.Frame, args []types.Value, opts map[string]types.Value)
- func TranslateStyle(s string) string
- type Buffer
- func (b *Buffer) Cursor() Pos
- func (b *Buffer) Extend(b2 *Buffer, moveDot bool)
- func (b *Buffer) ExtendRight(b2 *Buffer, w int)
- func (b *Buffer) Newline()
- func (b *Buffer) SetDot(dot Pos) *Buffer
- func (b *Buffer) SetEagerWrap(v bool) *Buffer
- func (b *Buffer) SetIndent(indent int) *Buffer
- func (b *Buffer) SetLines(lines ...[]Cell) *Buffer
- func (b *Buffer) TrimToLines(low, high int)
- func (b *Buffer) Write(r rune, style string)
- func (b *Buffer) WriteSpaces(w int, style string)
- func (b *Buffer) WriteString(text, style string)
- func (b *Buffer) WriteStyleds(ss []*Styled)
- type Cell
- type Key
- type Keys
- type Mod
- type Pos
- type Renderer
- type Styled
- type Styles
- Bugs
Constants ¶
const ( // DefaultBindingRune is a special value to represent default binding. DefaultBindingRune rune = iota - functionKeyOffset F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Up Down Right Left Home Insert Delete End PageUp PageDown Tab = '\t' Enter = '\n' Backspace = 0x7f )
Special negative runes to represent function keys, used in the Rune field of the Key struct.
Variables ¶
var Default = Key{DefaultBindingRune, 0}
Default is used in the key binding table to indicate default binding.
var ErrKeyMustBeString = errors.New("key must be key or string value")
Functions ¶
func BuffersHeight ¶ added in v0.11.0
BuffersHeight computes the combined height of a number of buffers.
func CellsWidth ¶ added in v0.11.0
CellsWidth returns the total width of a Cell slice.
func CompareCells ¶ added in v0.11.0
CompareCells returns whether two Cell slices are equal, and when they are not, the first index at which they differ.
func KeyBuiltin ¶ added in v0.10.0
KeyBuiltin implements the edit:key builtin.
func TranslateStyle ¶ added in v0.9.0
Types ¶
type Buffer ¶ added in v0.11.0
type Buffer struct {
Width, Col, Indent int
// EagerWrap controls whether to wrap line as soon as the cursor reaches the
// right edge of the terminal. This is not often desirable as it creates
// unneessary line breaks, but is is useful when echoing the user input.
// will otherwise
EagerWrap bool
// Lines the content of the buffer.
Lines [][]Cell
// Dot is what the user perceives as the cursor.
Dot Pos
}
Buffer reflects a continuous range of lines on the terminal.
The Unix terminal API provides only awkward ways of querying the terminal Buffer, so we keep an internal reflection and do one-way synchronizations (Buffer -> terminal, and not the other way around). This requires us to exactly match the terminal's idea of the width of characters (wcwidth) and where to insert soft carriage returns, so there could be bugs.
func Render ¶ added in v0.11.0
Render creates a new Buffer with the given width, and lets a Renderer render onto it.
func (*Buffer) Extend ¶ added in v0.11.0
Extend adds all lines from b2 to the bottom of this buffer. If moveDot is true, the dot is updated to match the dot of b2.
func (*Buffer) ExtendRight ¶ added in v0.11.0
ExtendRight extends b to the right. It pads each line in b to be at least of width w and appends the corresponding line in b2 to it, making new lines in b when b2 has more lines than b. BUG(xiaq): after calling ExtendRight, the widths of some lines can exceed b.width.
func (*Buffer) SetEagerWrap ¶ added in v0.11.0
func (*Buffer) TrimToLines ¶ added in v0.11.0
TrimToLines trims a buffer to the lines [low, high).
func (*Buffer) Write ¶ added in v0.11.0
Write writes a single rune to a buffer, wrapping the line when needed. If the rune is a control character, it will be written using the caret notation (like ^X) and gets the additional style of styleForControlChar.
func (*Buffer) WriteSpaces ¶ added in v0.11.0
WriteSpaces writes w spaces.
func (*Buffer) WriteString ¶ added in v0.11.0
WriteString writes a string to a buffer, with one style.
func (*Buffer) WriteStyleds ¶ added in v0.11.0
WriteStyleds writes a slice of styled structs.
type Cell ¶ added in v0.11.0
Cell is an indivisible unit on the screen. It is not necessarily 1 column wide.
type Key ¶
Key represents a single keyboard input, typically assembled from a escape sequence.
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 Renderer ¶ added in v0.11.0
type Renderer interface { // Render renders onto a Buffer. Render(b *Buffer) }
Renderer wraps the Render method.
type Styles ¶ added in v0.9.0
type Styles []string
func JoinStyles ¶ added in v0.9.0
func StylesFromString ¶ added in v0.9.0
Notes ¶
Bugs ¶
after calling ExtendRight, the widths of some lines can exceed b.width.