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
- type BufferBuilder
- func (bb *BufferBuilder) Buffer() *Buffer
- func (bb *BufferBuilder) Cursor() Pos
- func (bb *BufferBuilder) Extend(b2 *Buffer, moveDot bool) *BufferBuilder
- func (bb *BufferBuilder) ExtendRight(b2 *Buffer, w int) *BufferBuilder
- func (bb *BufferBuilder) Newline()
- func (bb *BufferBuilder) SetDot(dot Pos) *BufferBuilder
- func (bb *BufferBuilder) SetDotToCursor() *BufferBuilder
- func (bb *BufferBuilder) SetEagerWrap(v bool) *BufferBuilder
- func (bb *BufferBuilder) SetIndent(indent int) *BufferBuilder
- func (bb *BufferBuilder) SetLines(lines ...[]Cell) *BufferBuilder
- func (bb *BufferBuilder) Write(r rune, style string) *BufferBuilder
- func (bb *BufferBuilder) WriteSpaces(w int, style string) *BufferBuilder
- func (bb *BufferBuilder) WriteString(text, style string) *BufferBuilder
- func (bb *BufferBuilder) WriteStyleds(ss []*Styled) *BufferBuilder
- 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 TranslateStyle ¶ added in v0.9.0
Types ¶
type Buffer ¶ added in v0.11.0
type Buffer struct {
Width, Col int
// 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) TrimToLines ¶ added in v0.11.0
TrimToLines trims a buffer to the lines [low, high).
type BufferBuilder ¶ added in v0.12.0
type BufferBuilder 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
}
BufferBuilder supports building of Buffer.
func NewBufferBuilder ¶ added in v0.12.0
func NewBufferBuilder(width int) *BufferBuilder
NewBufferBuilder makes a new BufferBuilder, initially with one empty line.
func (*BufferBuilder) Buffer ¶ added in v0.12.0
func (bb *BufferBuilder) Buffer() *Buffer
Buffer returns a Buffer built by the BufferBuilder.
func (*BufferBuilder) Cursor ¶ added in v0.12.0
func (bb *BufferBuilder) Cursor() Pos
func (*BufferBuilder) Extend ¶ added in v0.12.0
func (bb *BufferBuilder) Extend(b2 *Buffer, moveDot bool) *BufferBuilder
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 (*BufferBuilder) ExtendRight ¶ added in v0.12.0
func (bb *BufferBuilder) ExtendRight(b2 *Buffer, w int) *BufferBuilder
ExtendRight extends bb to the right. It pads each line in bb to be at least of width w and appends the corresponding line in b2 to it, making new lines in bb when b2 has more lines than bb. BUG(xiaq): after calling ExtendRight, the widths of some lines can exceed bb.width.
func (*BufferBuilder) Newline ¶ added in v0.12.0
func (bb *BufferBuilder) Newline()
Newline starts a newline.
func (*BufferBuilder) SetDot ¶ added in v0.12.0
func (bb *BufferBuilder) SetDot(dot Pos) *BufferBuilder
func (*BufferBuilder) SetDotToCursor ¶ added in v0.12.0
func (bb *BufferBuilder) SetDotToCursor() *BufferBuilder
func (*BufferBuilder) SetEagerWrap ¶ added in v0.12.0
func (bb *BufferBuilder) SetEagerWrap(v bool) *BufferBuilder
func (*BufferBuilder) SetIndent ¶ added in v0.12.0
func (bb *BufferBuilder) SetIndent(indent int) *BufferBuilder
func (*BufferBuilder) SetLines ¶ added in v0.12.0
func (bb *BufferBuilder) SetLines(lines ...[]Cell) *BufferBuilder
func (*BufferBuilder) Write ¶ added in v0.12.0
func (bb *BufferBuilder) Write(r rune, style string) *BufferBuilder
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 (*BufferBuilder) WriteSpaces ¶ added in v0.12.0
func (bb *BufferBuilder) WriteSpaces(w int, style string) *BufferBuilder
WriteSpaces writes w spaces.
func (*BufferBuilder) WriteString ¶ added in v0.12.0
func (bb *BufferBuilder) WriteString(text, style string) *BufferBuilder
WriteString writes a string to a buffer, with one style.
func (*BufferBuilder) WriteStyleds ¶ added in v0.12.0
func (bb *BufferBuilder) WriteStyleds(ss []*Styled) *BufferBuilder
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(bb *BufferBuilder) }
Renderer wraps the Render method.
func NewModeLineRenderer ¶ added in v0.12.0
NewModeLineRenderer returns a Renderer for a mode line.
func NewModeLineWithScrollBarRenderer ¶ added in v0.12.0
type Styled ¶ added in v0.9.0
Styled is a piece of text with style.
func (*Styled) IterateKeys ¶ added in v0.12.0
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 bb.width.