text

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 14 Imported by: 61

Documentation

Overview

Package text contains a widget that displays textual data.

Index

Constants

View Source
const (
	DefaultScrollUpRune   = '⇧'
	DefaultScrollDownRune = '⇩'
)

The default scroll runes for content scrolling

View Source
const (
	DefaultScrollMouseButtonUp   = mouse.ButtonWheelUp
	DefaultScrollMouseButtonDown = mouse.ButtonWheelDown
)

The default mouse buttons for content scrolling.

View Source
const (
	DefaultScrollKeyUp       = keyboard.KeyArrowUp
	DefaultScrollKeyDown     = keyboard.KeyArrowDown
	DefaultScrollKeyPageUp   = keyboard.KeyPgUp
	DefaultScrollKeyPageDown = keyboard.KeyPgDn
)

The default keys for content scrolling.

View Source
const (
	DefaultMaxTextCells = 0
)

The default value for the MaxTextCells option. Use zero as no limit, for logs you may wish to try 10,000 or higher.

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 to New().

func DisableScrolling

func DisableScrolling() Option

DisableScrolling disables the scrolling of the content using keyboard and mouse.

func MaxTextCells added in v0.16.0

func MaxTextCells(max int) Option

MaxTextCells limits the text content to this number of terminal cells. This is useful when sending large amounts of text to the Text widget, e.g. when tailing logs as it will limit the memory usage. When the newly added content goes over this number of cells, the Text widget behaves as a circular buffer and drops earlier content to accommodate the new one. Note the count is in cells, not runes, some wide runes can take multiple terminal cells.

func RollContent

func RollContent() Option

RollContent configures the text widget so that it rolls the text content up if more text than the size of the container is added. If not provided, the content is trimmed instead.

func ScrollKeys

func ScrollKeys(up, down, pageUp, pageDown keyboard.Key) Option

ScrollKeys configures the keyboard keys that scroll the content. The provided keys must be unique, e.g. the same key cannot be both up and down.

func ScrollMouseButtons

func ScrollMouseButtons(up, down mouse.Button) Option

ScrollMouseButtons configures the mouse buttons that scroll the content. The provided buttons must be unique, e.g. the same button cannot be both up and down.

func ScrollRunes added in v0.13.0

func ScrollRunes(up, down rune) Option

ScrollRunes configures the text widgets scroll runes, shown at the top and bottom of a scrollable text widget. If not provided, the default scroll runes will be used.

func WrapAtRunes

func WrapAtRunes() Option

WrapAtRunes configures the text widget so that it automatically wraps lines that are longer than the width of the widget at rune boundaries. If not provided, long lines are trimmed instead.

func WrapAtWords added in v0.8.0

func WrapAtWords() Option

WrapAtWords configures the text widget so that it automatically wraps lines that are longer than the width of the widget at word boundaries. If not provided, long lines are trimmed instead.

type Text

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

Text displays a block of text.

Each line of the text is either trimmed or wrapped according to the provided options. The entire text content is either trimmed or rolled up through the canvas according to the provided options.

By default the widget supports scrolling of content with either the keyboard or mouse. See the options for the default keys and mouse buttons.

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

func New

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

New returns a new text widget.

func (*Text) Draw

func (t *Text) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws the text onto the canvas. Implements widgetapi.Widget.Draw.

func (*Text) Keyboard

func (t *Text) Keyboard(k *terminalapi.Keyboard, meta *widgetapi.EventMeta) error

Keyboard implements widgetapi.Widget.Keyboard.

func (*Text) Mouse

func (t *Text) Mouse(m *terminalapi.Mouse, meta *widgetapi.EventMeta) error

Mouse implements widgetapi.Widget.Mouse.

func (*Text) Options

func (t *Text) Options() widgetapi.Options

Options of the widget

func (*Text) Reset

func (t *Text) Reset()

Reset resets the widget back to empty content.

func (*Text) Write

func (t *Text) Write(text string, wOpts ...WriteOption) error

Write writes text for the widget to display. Multiple calls append additional text. The text contain cannot control characters (unicode.IsControl) or space character (unicode.IsSpace) other than:

' ', '\n'

Any newline ('\n') characters are interpreted as newlines when displaying the text.

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 WriteReplace added in v0.7.0

func WriteReplace() WriteOption

WriteReplace instructs the text widget to replace the entire text content on this write instead of appending.

Directories

Path Synopsis
Binary textdemo displays a couple of Text widgets.
Binary textdemo displays a couple of Text widgets.

Jump to

Keyboard shortcuts

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