ui

package
v4.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2019 License: BSD-3-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

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

BuffersHeight computes the combined height of a number of buffers.

func CellsWidth

func CellsWidth(cs []Cell) int

CellsWidth returns the total width of a Cell slice.

func CompareCells

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

func TranslateStyle(s string) string

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 NewBuffer

func NewBuffer(width int) *Buffer

NewBuffer builds a new buffer, with one empty line.

func Render

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

func (b *Buffer) Cursor() Pos

Cursor returns the current position of the cursor.

func (*Buffer) Extend

func (b *Buffer) Extend(b2 *Buffer, moveDot bool)

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

func (b *Buffer) ExtendRight(b2 *Buffer, w int)

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) Newline

func (b *Buffer) Newline()

Newline starts a newline.

func (*Buffer) SetDot

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

func (*Buffer) SetEagerWrap

func (b *Buffer) SetEagerWrap(v bool) *Buffer

func (*Buffer) SetIndent

func (b *Buffer) SetIndent(indent int) *Buffer

func (*Buffer) SetLines

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

func (*Buffer) TrimToLines

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

TrimToLines trims a buffer to the lines [low, high).

func (*Buffer) Write

func (b *Buffer) Write(r rune, style string)

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

func (b *Buffer) WriteSpaces(w int, style string)

WriteSpaces writes w spaces.

func (*Buffer) WriteString

func (b *Buffer) WriteString(text, style string)

WriteString writes a string to a buffer, with one style.

func (*Buffer) WriteStyleds

func (b *Buffer) WriteStyleds(ss []*Styled)

WriteStyleds writes a slice of styled structs.

type Cell

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

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

func (Key) Hash

func (k Key) Hash() uint32

func (Key) Kind

func (k Key) Kind() string

func (Key) Repr

func (k Key) Repr(int) string

func (Key) String

func (k Key) String() string

type Keys

type Keys []Key

Keys implements sort.Interface.

func (Keys) Len

func (ks Keys) Len() int

func (Keys) Less

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

func (Keys) Swap

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

type Pos struct {
	Line, Col int
}

Pos is the position within a buffer.

type Renderer

type Renderer interface {
	// Render renders onto a Buffer.
	Render(b *Buffer)
}

Renderer wraps the Render method.

func NewModeLineRenderer

func NewModeLineRenderer(title, filter string) Renderer

NewModeLineRenderer returns a Renderer for a mode line.

func NewModeLineWithScrollBarRenderer

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

type Styled

type Styled struct {
	Text   string
	Styles Styles
}

Styled is a piece of text with style.

func Unstyled

func Unstyled(s string) Styled

func (*Styled) Equal

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

func (*Styled) Hash

func (s *Styled) Hash() uint32

func (*Styled) Index

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

func (*Styled) IterateKeys

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

func (*Styled) Kind

func (s *Styled) Kind() string

func (*Styled) Repr

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

func (*Styled) String

func (s *Styled) String() string

type Styles

type Styles []string

func JoinStyles

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

func StylesFromString

func StylesFromString(s string) Styles

func (Styles) Eq

func (ss Styles) Eq(rhs Styles) bool

func (Styles) Hash

func (ss Styles) Hash() uint32

func (Styles) String

func (s Styles) String() string

Notes

Bugs

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

Jump to

Keyboard shortcuts

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