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 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 ¶
BuffersHeight computes the combined height of a number of buffers.
func CellsWidth ¶
CellsWidth returns the total width of a Cell slice.
func CompareCells ¶
CompareCells returns whether two Cell slices are equal, and when they are not, the first index at which they differ.
func TranslateStyle ¶
Types ¶
type Buffer ¶
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 (*Buffer) Extend ¶
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 ¶
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 ¶
func (*Buffer) TrimToLines ¶
TrimToLines trims a buffer to the lines [low, high).
func (*Buffer) Write ¶
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 ¶
WriteSpaces writes w spaces.
func (*Buffer) WriteString ¶
WriteString writes a string to a buffer, with one style.
func (*Buffer) WriteStyleds ¶
WriteStyleds writes a slice of styled structs.
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 ¶
type Renderer interface { // Render renders onto a Buffer. Render(b *Buffer) }
Renderer wraps the Render method.
func NewModeLineRenderer ¶
NewModeLineRenderer returns a Renderer for a mode line.
Notes ¶
Bugs ¶
after calling ExtendRight, the widths of some lines can exceed b.width.