elvish: github.com/elves/elvish/pkg/ui Index | Files

package ui

import "github.com/elves/elvish/pkg/ui"

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

Index

Package Files

key.go style.go text.go text_segment.go text_string.go text_styling.go text_util.go ui.go

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

type Color Uses

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 TrueColor Uses

func TrueColor(r, g, b uint8) Color

TrueColor returns a 24-bit true color.

func XTerm256Color Uses

func XTerm256Color(i uint8) Color

XTerm256Color returns a color from the xterm 256-color palette.

type Key Uses

type Key struct {
    Rune rune
    Mod  Mod
}

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

func K Uses

func K(r rune, mods ...Mod) Key

K constructs a new Key.

func ToKey Uses

func ToKey(k interface{}) (Key, error)

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

func (Key) Equal Uses

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

func (Key) Hash Uses

func (k Key) Hash() uint32

func (Key) Kind Uses

func (k Key) Kind() string

func (Key) Repr Uses

func (k Key) Repr(int) string

func (Key) String Uses

func (k Key) String() string

type Keys Uses

type Keys []Key

Keys implements sort.Interface.

func (Keys) Len Uses

func (ks Keys) Len() int

func (Keys) Less Uses

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

func (Keys) Swap Uses

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

type Mod Uses

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 RuneStylesheet Uses

type RuneStylesheet map[rune]Styling

RuneStylesheet maps runes to stylings.

type Segment Uses

type Segment struct {
    Style
    Text string
}

Segment is a string that has some style applied to it.

func StyleSegment Uses

func StyleSegment(seg *Segment, ts ...Styling) *Segment

StyleSegment returns a new Segment with the given Styling's applied. It does not modify the given Segment.

func (*Segment) Clone Uses

func (s *Segment) Clone() *Segment

Clone returns a copy of the Segment.

func (*Segment) Concat Uses

func (s *Segment) Concat(v interface{}) (interface{}, error)

Concat implements Segment+string, Segment+Segment and Segment+Text.

func (*Segment) CountRune Uses

func (s *Segment) CountRune(r rune) int

CountRune counts the number of times a rune occurs in a Segment.

func (*Segment) Index Uses

func (s *Segment) Index(k interface{}) (v interface{}, ok bool)

Index provides access to the attributes of a styled-segment.

func (*Segment) IterateKeys Uses

func (*Segment) IterateKeys(fn func(v interface{}) bool)

IterateKeys feeds the function with all valid attributes of styled-segment.

func (*Segment) Kind Uses

func (*Segment) Kind() string

Kind returns "styled-segment".

func (*Segment) RConcat Uses

func (s *Segment) RConcat(v interface{}) (interface{}, error)

RConcat implements string+Segment.

func (*Segment) Repr Uses

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

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 Uses

func (s *Segment) SplitByRune(r rune) []*Segment

SplitByRune splits a Segment by the given rune.

func (*Segment) String Uses

func (s *Segment) String() string

String returns a string representation of the styled segment. This now always assumes VT-style terminal output. TODO: Make string conversion sensible to environment, e.g. use HTML when output is web.

func (*Segment) VTString Uses

func (s *Segment) VTString() string

VTString renders the styled segment using VT-style escape sequences.

type Style Uses

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 Uses

func ApplyStyling(s Style, ts ...Styling) Style

ApplyStyling returns a new Style with the given Styling's applied.

func StyleFromSGR Uses

func StyleFromSGR(s string) Style

StyleFromSGR builds a Style from an SGR sequence.

func (*Style) ImportFromOptions Uses

func (s *Style) ImportFromOptions(options map[string]interface{}) error

ImportFromOptions assigns all recognized values from a map to the current Style.

func (Style) SGR Uses

func (s Style) SGR() string

SGR returns SGR sequence for the style.

type Styling Uses

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 Uses

func ParseStyling(s string) Styling

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 Stylings Uses

func Stylings(ts ...Styling) Styling

Stylings joins several transformers into one.

type Text Uses

type Text []*Segment

Text contains of a list of styled Segments.

func MarkLines Uses

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 Uses

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 Uses

func StyleText(t Text, ts ...Styling) Text

StyleText returns a new Text with the given Styling's applied. It does not modify the given Text.

func T Uses

func T(s string, ts ...Styling) Text

T constructs a new Text with the given content and the given Styling's applied.

func (Text) Clone Uses

func (t Text) Clone() Text

Clone returns a deep copy of Text.

func (Text) Concat Uses

func (t Text) Concat(v interface{}) (interface{}, error)

Concat implements Text+string, Text+Segment and Text+Text.

func (Text) ConcatSegments Uses

func (t Text) ConcatSegments(segs ...*Segment) Text

ConcatSegments returns a new Text with the new Segment's added to the end.

func (Text) ConcatText Uses

func (t Text) ConcatText(t2 Text) Text

ConcatSegments returns a new Text with the new Text added to the end.

func (Text) CountLines Uses

func (t Text) CountLines() int

CountLines counts the number of lines in a Text. It is equal to t.CountRune('\n') + 1.

func (Text) CountRune Uses

func (t Text) CountRune(r rune) int

CountRune counts the number of times a rune occurs in a Text.

func (Text) Index Uses

func (t Text) Index(k interface{}) (interface{}, error)

Index provides access to the underlying styled-segment.

func (Text) IterateKeys Uses

func (t Text) IterateKeys(fn func(interface{}) bool)

IterateKeys feeds the function with all valid indicies of the styled-text.

func (Text) Kind Uses

func (Text) Kind() string

Kind returns "styled-text".

func (Text) Partition Uses

func (t Text) Partition(indicies ...int) []Text

Partition partitions the Text at n indicies into n+1 Text values.

func (Text) RConcat Uses

func (t Text) RConcat(v interface{}) (interface{}, error)

RConcat implements string+Text.

func (Text) Repr Uses

func (t Text) Repr(indent int) string

Repr returns the representation of the current Text. It is just a wrapper around the containing Segments.

func (Text) SplitByRune Uses

func (t Text) SplitByRune(r rune) []Text

SplitByRune splits a Text by the given rune.

func (Text) String Uses

func (t Text) String() 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 Uses

func (t Text) TrimWcwidth(wmax int) Text

TrimWcwidth returns the largest prefix of t that does not exceed the given visual width.

func (Text) VTString Uses

func (t Text) VTString() string

VTString renders the styled text using VT-style escape sequences.

Package ui imports 9 packages (graph) and is imported by 17 packages. Updated 2020-01-22. Refresh now. Tools for package owners.