ui

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package ui defines a thin framework for building terminal UIs using tcell and accompanying widgets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnnotatedText

type AnnotatedText struct {
	// Text block to render. This may be multi-line.
	Text  string
	Style tcell.Style
	// contains filtered or unexported fields
}

AnnotatedText is a block of text rendered with annotations.

func (*AnnotatedText) Draw

func (at *AnnotatedText) Draw(view views.View)

Draw draws the annotated text onto the provided view.

func (*AnnotatedText) HandleEvent

func (at *AnnotatedText) HandleEvent(tcell.Event) bool

HandleEvent returns false.

func (*AnnotatedText) SetAnnotations

func (at *AnnotatedText) SetAnnotations(anns ...TextAnnotation)

SetAnnotations changes the annotations for an AnnotatedText. Offsets MUST not overlap.

type App

type App struct {
	// Root is the main application widget.
	Root Widget

	// Screen upon which to draw.
	Screen tcell.Screen

	// Logger to post messages to. Optional.
	Log *log.Logger
	// contains filtered or unexported fields
}

App drives the main UI for the application.

func (*App) Start

func (app *App) Start()

Start starts the app, rendering the root widget on the screen indefinitely until Stop is called.

func (*App) Stop

func (app *App) Stop()

Stop informs the application that it's time to stop. This will cause the Run function to unblock and return.

func (*App) Wait

func (app *App) Wait() error

Wait waits until the application is stopped with Stop.

type OverlayTextAnnotation

type OverlayTextAnnotation struct {
	Overlay string
	Style   tcell.Style // style for the overlay

	// Offset in the text over which to draw this overlay.
	Offset int
}

OverlayTextAnnotation overlays a different text over a section of text in AnnotatedText.

type Pos

type Pos struct{ X, Y int }

Pos is a position in the terminal UI.

func DrawText

func DrawText(s string, style tcell.Style, view views.View, pos Pos) Pos

DrawText draws a string on the provided view at the specified position. Returns the new position, after having drawn the text, making it possible to continue drawing at the last written position.

pos = DrawText("foo\nb", style, view, pos)
pos = DrawText("ar", style, view, pos)

Text that bleeds outside the bounds of the view is ignored.

func (Pos) Get

func (p Pos) Get() (x, y int)

Get returns the coordinates as a pair.

x, y = pos.Get()

func (Pos) String

func (p Pos) String() string

type StyleTextAnnotation

type StyleTextAnnotation struct {
	Style tcell.Style // style for this section

	// Offset in the text, and the length of it for which this alternative
	// style applies.
	Offset, Length int
}

StyleTextAnnotation changes the style of a section of text in AnnotatedText.

type TextAnnotation

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

TextAnnotation changes what gets rendered for AnnotatedText.

type Widget

type Widget interface {
	// Draw draws the widget on the supplied view. Widgets do not need to
	// clear the view; the caller will do that for them.
	Draw(views.View)

	// HandleEvent handles the given event, or returns false if the event
	// wasn't meant for it.
	HandleEvent(tcell.Event) (handled bool)
}

Widget is a drawable object that may handle events.

Jump to

Keyboard shortcuts

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