ui

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2018 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package ui contains types that may be used by different editor frontends.

Index

Constants

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

View Source
var Default = Key{DefaultBindingRune, 0}

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

View Source
var ErrKeyMustBeString = errors.New("key must be key or string value")

Functions

func BuffersHeight added in v0.11.0

func BuffersHeight(bufs ...*Buffer) (l int)

BuffersHeight computes the combined height of a number of buffers.

func CellsWidth added in v0.11.0

func CellsWidth(cs []Cell) int

CellsWidth returns the total width of a Cell slice.

func CompareCells added in v0.11.0

func CompareCells(r1, r2 []Cell) (bool, int)

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

func TranslateStyle(s string) string

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

func NewBuffer(width int) *Buffer

NewBuffer builds a new buffer, with one empty line.

func Render added in v0.11.0

func Render(r Renderer, width int) *Buffer

Render creates a new Buffer with the given width, and lets a Renderer render onto it.

func (*Buffer) Cursor added in v0.11.0

func (b *Buffer) Cursor() Pos

Cursor returns the current position of the cursor.

func (*Buffer) SetDot added in v0.11.0

func (b *Buffer) SetDot(dot Pos) *Buffer

func (*Buffer) SetLines added in v0.11.0

func (b *Buffer) SetLines(lines ...[]Cell) *Buffer

func (*Buffer) TrimToLines added in v0.11.0

func (b *Buffer) TrimToLines(low, high int)

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

type Cell struct {
	Text  string
	Width byte
	Style string
}

Cell is an indivisible unit on the screen. It is not necessarily 1 column wide.

type Key

type Key struct {
	Rune rune
	Mod  Mod
}

Key represents a single keyboard input, typically assembled from a escape sequence.

func ToKey

func ToKey(k interface{}) Key

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

func (Key) Equal added in v0.10.0

func (k Key) Equal(other interface{}) bool

func (Key) Hash added in v0.10.0

func (k Key) Hash() uint32

func (Key) Kind added in v0.10.0

func (k Key) Kind() string

func (Key) Repr added in v0.10.0

func (k Key) Repr(int) string

func (Key) String

func (k Key) String() string

type Keys added in v0.11.0

type Keys []Key

Keys implements sort.Interface.

func (Keys) Len added in v0.11.0

func (ks Keys) Len() int

func (Keys) Less added in v0.11.0

func (ks Keys) Less(i, j int) bool

func (Keys) Swap added in v0.11.0

func (ks Keys) Swap(i, j int)

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

type Pos struct {
	Line, Col int
}

Pos is the position within a buffer.

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

func NewModeLineRenderer(title, filter string) Renderer

NewModeLineRenderer returns a Renderer for a mode line.

func NewModeLineWithScrollBarRenderer added in v0.12.0

func NewModeLineWithScrollBarRenderer(base Renderer, n, low, high int) Renderer

type Styled added in v0.9.0

type Styled struct {
	Text   string
	Styles Styles
}

Styled is a piece of text with style.

func Unstyled added in v0.9.0

func Unstyled(s string) Styled

func (*Styled) Equal added in v0.10.0

func (s *Styled) Equal(a interface{}) bool

func (*Styled) Hash added in v0.10.0

func (s *Styled) Hash() uint32

func (*Styled) Index added in v0.12.0

func (s *Styled) Index(k interface{}) (interface{}, bool)

func (*Styled) IterateKeys added in v0.12.0

func (s *Styled) IterateKeys(f func(interface{}) bool)

func (*Styled) Kind added in v0.9.0

func (s *Styled) Kind() string

func (*Styled) Repr added in v0.9.0

func (s *Styled) Repr(indent int) string

func (*Styled) String added in v0.9.0

func (s *Styled) String() string

type Styles added in v0.9.0

type Styles []string

func JoinStyles added in v0.9.0

func JoinStyles(so Styles, st ...Styles) Styles

func StylesFromString added in v0.9.0

func StylesFromString(s string) Styles

func (Styles) Eq added in v0.10.0

func (ss Styles) Eq(rhs Styles) bool

func (Styles) Hash added in v0.10.0

func (ss Styles) Hash() uint32

func (Styles) String added in v0.9.0

func (s Styles) String() string

Notes

Bugs

  • after calling ExtendRight, the widths of some lines can exceed bb.width.

Jump to

Keyboard shortcuts

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