style

package
v0.0.0-...-d3199ed Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment int

Alignment represents the alignment of an object, and consists of either or both of horizontal and vertical alignment.

const (
	NoAlignment Alignment           = 1 << iota // NoAlignment indicates missing alignment info.
	Left                                        // Left indicates alignment on the left edge.
	HCenter                                     // HCenter indicates horizontally centered.
	Right                                       // Right indicates alignment on the right edge.
	Top                                         // Top indicates alignment on the top edge.
	VCenter                                     // VCenter indicates vertically centered.
	Bottom                                      // Bottom indicates alignment on the bottom edge.
	Begin       = Left | Top                    // Begin indicates alignment at the top left corner (default)
	End         = Right | Bottom                // End indicates alignment at the bottom right corner.
	Middle      = HCenter | VCenter             // Middle indicates full centering.
)

func (Alignment) String

func (a Alignment) String() string

Stringer implementation

type Bus

type Bus interface {
	Subscriber
	Publisher
}

allows to subscribe/unsubscribe to external events and publish own events

func NewBus

func NewBus() Bus

returns new event bus

type Event

type Event interface {
	EventID() EventID
}

must be implemented by anything that can be published

type EventHandler

type EventHandler func(event Event)

is function that can be subscribed to the event

type EventID

type EventID string

identifies events topic.

type FindColorFunc

type FindColorFunc func(c color.Color) color.Color

FindColorFunc

type Mask

type Mask int

Mask represents a mask of text attributes, apart from color. Note that support for attributes may vary widely across terminals.

const (
	Bold Mask = 1 << iota
	Blink
	Reverse
	Underline
	Dim
	Italic
	StrikeThrough
	Invalid          // Mark the style or attributes invalid
	None    Mask = 0 // Just normal text.
)

Attributes are not colors, but affect the display of text. They can be combined.

type Option

type Option func(s *Style)

func FromStyle

func FromStyle(clone *Style) Option

FromStyle

func WithAttrs

func WithAttrs(mask Mask) Option

WithAttrs

func WithBg

func WithBg(c color.Color) Option

WithBg

func WithBlink(on bool) Option

WithBlink

func WithBold

func WithBold(on bool) Option

WithBold

func WithDim

func WithDim(on bool) Option

WithDim

func WithFg

func WithFg(c color.Color) Option

WithFg

func WithItalic

func WithItalic(on bool) Option

WithItalic

func WithReverse

func WithReverse(on bool) Option

WithReverse

func WithStrikeThrough

func WithStrikeThrough(on bool) Option

WithStrikeThrough

func WithUnderline

func WithUnderline(on bool) Option

WithUnderline

type Orientation

type Orientation int

Orientation represents the direction of a widget or layout.

const (
	NoOrientation Orientation             = 1 << iota // NoOrientation indicates orientation has not been indicated.
	Horizontal                                        // Horizontal indicates left to right orientation.
	Vertical                                          // Vertical indicates top to bottom orientation.
	Absolute      = Vertical | Horizontal             // Absolute ???
)

func (Orientation) String

func (o Orientation) String() string

Stringer implementation

type Publisher

type Publisher interface {
	Publish(event Event)
}

allows to publish own events

type Style

type Style struct {
	Fg    color.Color
	Bg    color.Color
	Attrs Mask
}

Style represents a complete text style, including both foreground and background color. We encode it in a 64-bit int for efficiency. The coding is (MSB): <7b flags><1b><24b fgcolor><7b attr><1b><24b bgcolor>. The <1b> is set true to indicate that the color is an RGB color, rather than a named index.

This gives 24bit color options, if it ever becomes truly necessary. However, applications must not rely on this encoding.

Note that not all terminals can display all colors or attributes, and many might have specific incompatibilities between specific attributes and color combinations.

The intention is to extend styles to support palette-ing, in which case some flag bit(s) would be set, and the foreground and background colors would be replaced with a palette number and palette index.

To use Style, just declare a variable of its type.

func NewStyle

func NewStyle(opts ...Option) *Style

func (Style) Expand

func (s Style) Expand() (color.Color, color.Color, Mask)

Expand breaks a style up, returning the foreground, background, and other attributes.

func (Style) IsValid

func (s Style) IsValid() bool

func (*Style) Merge

func (s *Style) Merge(other *Style)

TODO : test

func (*Style) Normal

func (s *Style) Normal() Style

Normal returns the style with all attributes disabled.

type Subscriber

type Subscriber interface {
	Subscribe(eventID EventID, cb EventHandler) Subscription
	Unsubscribe(id Subscription)
}

allows to subscribe/unsubscribe own event handlers

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

represents active event subscription

type TermStyle

type TermStyle struct {
	sync.Mutex // guards other properties
	// contains filtered or unexported fields
}

func NewTermStyle

func NewTermStyle(colors int) *TermStyle

func (*TermStyle) Colors

func (s *TermStyle) Colors() map[color.Color]color.Color

Colors

func (*TermStyle) FindColor

func (s *TermStyle) FindColor(c color.Color) color.Color

FindColor

func (*TermStyle) Palette

func (s *TermStyle) Palette() []color.Color

Palette

type Theme

type Theme struct {
	BorderColor             color.Color // Color for borders.
	MainBackgroundColor     color.Color // Main background color for primitives.
	HoverBackgroundColor    color.Color // Background color for hovered elements.
	SelectedBackgroundColor color.Color // Background color for selected elements.
	InverseBackgroundColor  color.Color //
	TextColor               color.Color // Main text color.
	HoverTextColor          color.Color // Hovered text color.
	SelectedTextColor       color.Color // Selected text color.
	InverseTextColor        color.Color //
}

Theme defines the colors used across Applications.

Jump to

Keyboard shortcuts

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