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(int) string
- func (s *Segment) SplitByRune(r rune) []*Segment
- func (s *Segment) String() string
- func (s *Segment) VTString() string
- type Style
- type Styling
- type StylingRegion
- type Text
- func Concat(texts ...Text) Text
- func MarkLines(args ...interface{}) Text
- func MarkText(line string, stylesheet RuneStylesheet, style string) Text
- func ParseSGREscapedText(s string) Text
- func StyleRegions(s string, regions []StylingRegion) Text
- func StyleText(t Text, ts ...Styling) Text
- func T(s string, ts ...Styling) Text
- func (t Text) Clone() Text
- func (t Text) Concat(rhs interface{}) (interface{}, error)
- 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(indices ...int) []Text
- func (t Text) RConcat(lhs 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 a 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 // Function key names that are aliases for their ASCII representation. Tab = '\t' Enter = '\n' Backspace = 0x7f )
Special negative runes to represent function keys, used in the Rune field of the Key struct. This also has a few function names that are aliases for simple runes. See keyNames below for mapping these values to strings.
Variables ¶
var Default = Key{DefaultBindingRune, 0}
Default is used in the key binding table to indicate a default binding.
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) Concat ¶
Concat implements Segment+string, Segment+float64, Segment+Segment and Segment+Text.
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) MergeFromOptions ¶
MergeFromOptions merges 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.
var ( Reset Styling = reset{} FgDefault Styling = setForeground{nil} FgBlack Styling = setForeground{Black} FgRed Styling = setForeground{Red} FgGreen Styling = setForeground{Green} FgYellow Styling = setForeground{Yellow} FgBlue Styling = setForeground{Blue} FgMagenta Styling = setForeground{Magenta} FgCyan Styling = setForeground{Cyan} FgWhite Styling = setForeground{White} FgBrightBlack Styling = setForeground{BrightBlack} FgBrightRed Styling = setForeground{BrightRed} FgBrightGreen Styling = setForeground{BrightGreen} FgBrightYellow Styling = setForeground{BrightYellow} FgBrightBlue Styling = setForeground{BrightBlue} FgBrightMagenta Styling = setForeground{BrightMagenta} FgBrightCyan Styling = setForeground{BrightCyan} FgBrightWhite Styling = setForeground{BrightWhite} BgDefault Styling = setBackground{nil} BgBlack Styling = setBackground{Black} BgRed Styling = setBackground{Red} BgGreen Styling = setBackground{Green} BgYellow Styling = setBackground{Yellow} BgBlue Styling = setBackground{Blue} BgMagenta Styling = setBackground{Magenta} BgCyan Styling = setBackground{Cyan} BgWhite Styling = setBackground{White} BgBrightBlack Styling = setBackground{BrightBlack} BgBrightRed Styling = setBackground{BrightRed} BgBrightGreen Styling = setBackground{BrightGreen} BgBrightYellow Styling = setBackground{BrightYellow} BgBrightBlue Styling = setBackground{BrightBlue} BgBrightMagenta Styling = setBackground{BrightMagenta} BgBrightCyan Styling = setBackground{BrightCyan} BgBrightWhite Styling = setBackground{BrightWhite} Bold Styling = boolOn{boldField{}} Dim Styling = boolOn{dimField{}} Italic Styling = boolOn{italicField{}} Underlined Styling = boolOn{underlinedField{}} Blink Styling = boolOn{blinkField{}} Inverse Styling = boolOn{inverseField{}} NoBold Styling = boolOff{boldField{}} NoDim Styling = boolOff{dimField{}} NoItalic Styling = boolOff{italicField{}} NoUnderlined Styling = boolOff{underlinedField{}} NoBlink Styling = boolOff{blinkField{}} NoInverse Styling = boolOff{inverseField{}} ToggleBold Styling = boolToggle{boldField{}} ToggleDim Styling = boolToggle{dimField{}} ToggleItalic Styling = boolToggle{italicField{}} ToggleUnderlined Styling = boolToggle{underlinedField{}} ToggleBlink Styling = boolToggle{blinkField{}} ToggleInverse Styling = boolToggle{inverseField{}} )
Common stylings.
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.
func StylingFromSGR ¶
StylingFromSGR builds a Style from an SGR sequence.
type StylingRegion ¶
StylingRegion represents a region to apply styling.
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 ParseSGREscapedText ¶
ParseSGREscapedText parses SGR-escaped text into a Text. It also removes non-SGR CSI sequences sequences in the text.
func StyleRegions ¶
func StyleRegions(s string, regions []StylingRegion) Text
StyleRegions applies styling to the specified regions in s.
The regions are sorted by start position. If multiple Regions share the same starting position, the one with the highest priority is kept; the other regions are removed. If a Region starts before the end of the previous Region, it is also removed.
func StyleText ¶
StyleText returns a new Text with the given Styling's applied. It does not modify the given Text.
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 indices 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.