Documentation ¶
Overview ¶
Package ui contains types that may be used by different editor frontends.
Index ¶
- Constants
- Variables
- type Color
- type Key
- type Keys
- type Mod
- type RuneStylesheet
- type Segment
- func (s *Segment) Clone() *Segment
- func (s *Segment) Concat(v interface{}) (interface{}, error)
- func (s *Segment) CountRune(r rune) int
- func (s *Segment) Index(k interface{}) (v interface{}, ok bool)
- func (*Segment) IterateKeys(fn func(v interface{}) bool)
- func (*Segment) Kind() string
- func (s *Segment) RConcat(v interface{}) (interface{}, error)
- func (s *Segment) Repr(indent int) string
- func (s *Segment) SplitByRune(r rune) []*Segment
- func (s *Segment) String() string
- func (s *Segment) VTString() string
- type Style
- type Styling
- type Text
- func (t Text) Clone() Text
- func (t Text) Concat(v interface{}) (interface{}, error)
- func (t Text) ConcatSegments(segs ...*Segment) Text
- func (t Text) ConcatText(t2 Text) Text
- func (t Text) CountLines() int
- func (t Text) CountRune(r rune) int
- func (t Text) Index(k interface{}) (interface{}, error)
- func (t Text) IterateKeys(fn func(interface{}) bool)
- func (Text) Kind() string
- func (t Text) Partition(indicies ...int) []Text
- func (t Text) RConcat(v interface{}) (interface{}, error)
- func (t Text) Repr(indent int) string
- func (t Text) SplitByRune(r rune) []Text
- func (t Text) String() string
- func (t Text) TrimWcwidth(wmax int) Text
- func (t Text) VTString() string
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 ( FgDefault = setForeground{nil} FgBlack = setForeground{Black} FgRed = setForeground{Red} FgGreen = setForeground{Green} FgYellow = setForeground{Yellow} FgBlue = setForeground{Blue} FgMagenta = setForeground{Magenta} FgCyan = setForeground{Cyan} FgWhite = setForeground{White} FgBrightBlack = setForeground{BrightBlack} FgBrightRed = setForeground{BrightRed} FgBrightGreen = setForeground{BrightGreen} FgBrightYellow = setForeground{BrightYellow} FgBrightBlue = setForeground{BrightBlue} FgBrightMagenta = setForeground{BrightMagenta} FgBrightCyan = setForeground{BrightCyan} FgBrightWhite = setForeground{BrightWhite} BgDefault = setBackground{nil} BgBlack = setBackground{Black} BgRed = setBackground{Red} BgGreen = setBackground{Green} BgYellow = setBackground{Yellow} BgBlue = setBackground{Blue} BgMagenta = setBackground{Magenta} BgCyan = setBackground{Cyan} BgWhite = setBackground{White} BgBrightBlack = setBackground{BrightBlack} BgBrightRed = setBackground{BrightRed} BgBrightGreen = setBackground{BrightGreen} BgBrightYellow = setBackground{BrightYellow} BgBrightBlue = setBackground{BrightBlue} BgBrightMagenta = setBackground{BrightMagenta} BgBrightCyan = setBackground{BrightCyan} BgBrightWhite = setBackground{BrightWhite} Bold = boolOn(accessBold) Dim = boolOn(accessDim) Italic = boolOn(accessItalic) Underlined = boolOn(accessUnderlined) Blink = boolOn(accessBlink) Inverse = boolOn(accessInverse) NoBold = boolOff(accessBold) NoDim = boolOff(accessDim) NoItalic = boolOff(accessItalic) NoUnderlined = boolOff(accessUnderlined) NoBlink = boolOff(accessBlink) NoInverse = boolOff(accessInverse) ToggleBold = boolToggle(accessBold) ToggleDim = boolToggle(accessDim) ToggleItalic = boolToggle(accessItalic) ToggleUnderlined = boolToggle(accessUnderlined) ToggleBlink = boolToggle(accessBlink) ToggleInverse = boolToggle(accessInverse) )
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 ¶
This section is empty.
Types ¶
type Color ¶
type Color interface { String() string // contains filtered or unexported methods }
Color represents a color.
var ( Black Color = ansiColor(0) Red Color = ansiColor(1) Green Color = ansiColor(2) Yellow Color = ansiColor(3) Blue Color = ansiColor(4) Magenta Color = ansiColor(5) Cyan Color = ansiColor(6) White Color = ansiColor(7) BrightBlack Color = ansiBrightColor(0) BrightRed Color = ansiBrightColor(1) BrightGreen Color = ansiBrightColor(2) BrightYellow Color = ansiBrightColor(3) BrightBlue Color = ansiBrightColor(4) BrightMagenta Color = ansiBrightColor(5) BrightCyan Color = ansiBrightColor(6) BrightWhite Color = ansiBrightColor(7) )
Builtin ANSI colors.
func XTerm256Color ¶
XTerm256Color returns a color from the xterm 256-color palette.
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 Segment ¶
Segment is a string that has some style applied to it.
func StyleSegment ¶
StyleSegment returns a new Segment with the given Styling's applied. It does not modify the given Segment.
func (*Segment) IterateKeys ¶
IterateKeys feeds the function with all valid attributes of styled-segment.
func (*Segment) Repr ¶
Repr returns the representation of this Segment. The string can be used to construct an identical Segment. Unset or default attributes are skipped. If the Segment represents an unstyled string only this string is returned.
func (*Segment) SplitByRune ¶
SplitByRune splits a Segment by the given rune.
type Style ¶
type Style struct { Foreground Color Background Color Bold bool Dim bool Italic bool Underlined bool Blink bool Inverse bool }
Style specifies how something (mostly a string) shall be displayed.
func ApplyStyling ¶
ApplyStyling returns a new Style with the given Styling's applied.
func StyleFromSGR ¶
StyleFromSGR builds a Style from an SGR sequence.
func (*Style) ImportFromOptions ¶
ImportFromOptions assigns all recognized values from a map to the current Style.
type Styling ¶
type Styling interface {
// contains filtered or unexported methods
}
Styling specifies how to change a Style. It can also be applied to a Segment or Text.
func ParseStyling ¶
ParseStyling parses a text representation of Styling, which are kebab case counterparts to the names of the builtin Styling's. For example, ToggleInverse is expressed as "toggle-inverse".
Multiple stylings can be joined by spaces, which is equivalent to calling Stylings.
If the given string is invalid, ParseStyling returns nil.
type Text ¶
type Text []*Segment
Text contains of a list of styled Segments.
func MarkLines ¶
func MarkLines(args ...interface{}) Text
MarkLines provides a way to construct a styled text by separating the content and the styling.
The arguments are groups of either ¶
* A single string, in which case it represents an unstyled line;
- Three arguments that can be passed to MarkLine, in which case they are passed to MarkLine and the return value is used as a styled line.
Lines represented by all the groups are joined together.
This function is mainly useful for constructing multi-line Text's with alignment across those lines. An example:
var stylesheet = map[rune]string{ '-': Reverse, 'x': Stylings(Blue, BgGreen), } var text = FromMarkedLines( "foo bar foobar", stylesheet, "--- xxx ------" "lorem ipsum dolar", )
func MarkText ¶
func MarkText(line string, stylesheet RuneStylesheet, style string) Text
MarkText applies styles to all the runes in the line, using the runes in the style string. The stylesheet argument specifies which style each rune represents.
func StyleText ¶
StyleText returns a new Text with the given Styling's applied. It does not modify the given Text.
func (Text) ConcatSegments ¶
ConcatSegments returns a new Text with the new Segment's added to the end.
func (Text) ConcatText ¶
ConcatSegments returns a new Text with the new Text added to the end.
func (Text) CountLines ¶
CountLines counts the number of lines in a Text. It is equal to t.CountRune('\n') + 1.
func (Text) IterateKeys ¶
IterateKeys feeds the function with all valid indicies of the styled-text.
func (Text) Repr ¶
Repr returns the representation of the current Text. It is just a wrapper around the containing Segments.
func (Text) SplitByRune ¶
SplitByRune splits a Text by the given rune.
func (Text) String ¶
String returns a string representation of the styled text. This now always assumes VT-style terminal output.
TODO: Make string conversion sensible to environment, e.g. use HTML when output is web.
func (Text) TrimWcwidth ¶
TrimWcwidth returns the largest prefix of t that does not exceed the given visual width.