segmentdisplay

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: Apache-2.0 Imports: 15 Imported by: 30

Documentation

Overview

Package segmentdisplay is a widget that displays text by simulating a segment display.

Index

Constants

View Source
const DefaultGapPercent = 20

DefaultGapPercent is the default value for the GapPercent option.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to provide options.

func AlignHorizontal

func AlignHorizontal(h align.Horizontal) Option

AlignHorizontal sets the horizontal alignment for the individual display segments. Defaults to alignment in the center.

func AlignVertical

func AlignVertical(v align.Vertical) Option

AlignVertical sets the vertical alignment for the individual display segments. Defaults to alignment in the middle

func GapPercent

func GapPercent(perc int) Option

GapPercent sets the size of the horizontal gap between individual segments (characters) expressed as a percentage of the segment height.

func MaximizeDisplayedText

func MaximizeDisplayedText() Option

MaximizeDisplayedText tells the widget to maximize the amount of characters that are displayed. When this option is set and the user has provided more text than we can fit on the canvas, the widget will prefer to decrease the height of individual characters and fit more of them on the canvas. This is the default behavior.

func MaximizeSegmentHeight

func MaximizeSegmentHeight() Option

MaximizeSegmentHeight tells the widget to maximize the height of the individual display segments. When this option is set and the user has provided more text than we can fit on the canvas, the widget will prefer to maximize height of individual characters which will result in earlier trimming of the text.

type SegmentDisplay

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

SegmentDisplay displays ASCII content by simulating a segment display.

Automatically determines the size of individual segments with goal of maximizing the segment size or with fitting the entire text depending on the provided options.

Segment displays support only a subset of ASCII characters, provided options determine the behavior when an unsupported character is encountered.

Implements widgetapi.Widget. This object is thread-safe.

func New

func New(opts ...Option) (*SegmentDisplay, error)

New returns a new SegmentDisplay.

func (*SegmentDisplay) Capacity added in v0.9.0

func (sd *SegmentDisplay) Capacity() int

Capacity returns the number of characters that can fit into the canvas. This is essentially the number of individual segments that can fit on the canvas at the time the last call to draw. Returns zero if draw wasn't called.

Note that this capacity changes each time the terminal resizes, so there is no guarantee this remains the same next time Draw is called. Should be used as a hint only.

func (*SegmentDisplay) Draw

func (sd *SegmentDisplay) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the SegmentDisplay widget onto the canvas. Implements widgetapi.Widget.Draw.

func (*SegmentDisplay) Keyboard

Keyboard input isn't supported on the SegmentDisplay widget.

func (*SegmentDisplay) Mouse

Mouse input isn't supported on the SegmentDisplay widget.

func (*SegmentDisplay) Options

func (sd *SegmentDisplay) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*SegmentDisplay) Reset

func (sd *SegmentDisplay) Reset()

Reset resets the widget back to empty content.

func (*SegmentDisplay) Write

func (sd *SegmentDisplay) Write(chunks []*TextChunk, opts ...Option) error

Write writes text for the widget to display. Subsequent calls replace text written previously. All the provided text chunks are broken into characters and each character is displayed in one segment.

The provided write options determine the behavior when text contains unsupported characters and set cell options for cells that contain individual display segments.

Each of the text chunks can have its own options. At least one chunk must be specified.

Any provided options override options given to New.

type TextChunk

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

TextChunk is a part of or the full text that will be displayed.

func NewChunk

func NewChunk(text string, wOpts ...WriteOption) *TextChunk

NewChunk creates a new text chunk.

type WriteOption

type WriteOption interface {
	// contains filtered or unexported methods
}

WriteOption is used to provide options to Write().

func WriteCellOpts

func WriteCellOpts(opts ...cell.Option) WriteOption

WriteCellOpts sets options on the cells that contain the text.

func WriteErrOnUnsupported

func WriteErrOnUnsupported(opts ...cell.Option) WriteOption

WriteErrOnUnsupported instructs Write to return an error when the text contains a character the display doesn't support. The default behavior is to sanitize the text, see WriteSanitize().

func WriteSanitize

func WriteSanitize(opts ...cell.Option) WriteOption

WriteSanitize instructs Write to sanitize the text, replacing all characters the display doesn't support with a space ' ' character. This is the default behavior.

Directories

Path Synopsis
Binary segmentdisplaydemo shows the functionality of a segment display.
Binary segmentdisplaydemo shows the functionality of a segment display.

Jump to

Keyboard shortcuts

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