term

package
v0.0.0-...-80afc61 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DockPos

type DockPos int

DockPos indicates which side of the split-region the "Docked"/fixed-size section of a split is anchored to.

const (
	// PosBelow anchors to the bottom
	PosBelow DockPos = iota
	// PosAbove anchors to the top
	PosAbove
	// PosLeft anchors to the left
	PosLeft
	// PosRight anchors to the right
	PosRight
)

type Flushable

type Flushable interface {
	// FlushTo flushes content to the screen.  It should only write to the
	// areas of the screen that it has been assigned to (generally via being
	// Resizable).
	FlushTo(screen tcell.Screen)
}

Flushable contains content that can be flushed to a screen.

type GraphView

type GraphView struct {
	Graph *plot.PlatonicGraph

	DomainLabeler plot.DomainLabeler
	RangeLabeler  plot.RangeLabeler

	DomainTickSpacing int
	RangeTickSpacing  int
	// contains filtered or unexported fields
}

GraphView is a widget that displays the given graph with on the screen. You *must* supply a domain and range labeler. Default spacings will be chosen for the tick spacing if not specified.

func (*GraphView) FlushTo

func (g *GraphView) FlushTo(screen tcell.Screen)

func (*GraphView) SetBox

func (g *GraphView) SetBox(box PositionBox)

type PositionBox

type PositionBox struct {
	// StartCol and StartRow indicate the starting row and column
	// (zero-indexed) of this region.
	StartCol, StartRow int
	// Cols and Rows indicate the count of columns in this region,
	// and will be non-zero positive numbers.
	Cols, Rows int
}

PositionBox describes a region of the screen.

type PromptView

type PromptView struct {
	Screen screenIsh

	// SetupPrompt initializes the go-prompt prompt each time it requests new
	// input.
	SetupPrompt func(requiredOpts ...prompt.Option) *prompt.Prompt
	// HandleInput is called when the prompt returns with an entered command or whatnot.
	// Returned text is written before displaying a new prompt, and stop can be used to
	// indicate that even event loop should be stopped and the screen shut down (e.g. an
	// exit command).
	HandleInput func(input string) (text *string, stop bool)
	// OnSetup is called during Run once the reader and writer are initialized.  It's
	// useful for avoiding races when adding this to be displayed -- you shouldn't try
	// to use this for displaying until OnSetup has been called.
	OnSetup func()
	// contains filtered or unexported fields
}

PromptView is a widget that displays a go-prompt prompt. It feeds input from HandleKey to go-prompt and writes output to an internal buffer that can later be flushed to the screen as expected. Since go-prompt is written around having some control of the screen, unlike most widgets this one should be "persistent" across updates, and the internals go to some lengths to keep things threadsafe.

Due to the internals, this widget shouldn't be used until Run is called and you've received a callback to OnSetup.

func (*PromptView) FlushTo

func (v *PromptView) FlushTo(screen tcell.Screen)

func (*PromptView) HandleKey

func (v *PromptView) HandleKey(evt *tcell.EventKey)

HandleKey receives key events from an input loop. Use this as the runner's KeyHandler.

func (*PromptView) Run

func (v *PromptView) Run(ctx context.Context, initialInput *string, shutdownScreen func()) error

Run starts the go-prompt even loop, repeatedly asking the user for input, handling the input and dispatching the result to HandleInput. If given, initial input is prepopulated into the prompt followed by a synthetic "enter" event. shutdownScreen will be called when HandleInput asks for to be stopped. It's generally the Runner's context's cancel function.

func (*PromptView) SetBox

func (v *PromptView) SetBox(box PositionBox)

type Resizable

type Resizable interface {
	// SetBox sets the size that this widget should fill.  This is *not* an
	// indication that the content should be drawn to the screen (that's what
	// Flushable is for).
	SetBox(PositionBox)
}

Resizable widgets know how to receive a section of the screen that they're supposed to write to, and resize their content to fit that section.

type Runner

type Runner struct {

	// KeyHandler receives key events produced during Run.  It must be specified.
	KeyHandler func(*tcell.EventKey)

	// MakeScreen allows custom screens to be used.  Mainly useful for testing.
	// Most cases can use the default value.
	MakeScreen func() (tcell.Screen, error)

	// OnStart is run once the main screen is initialized and the event loop is
	// *about* to start.  Useful for avoiding race conditions regarding the screen
	// being initialized (mainly for the prompt widget & testing).
	OnStart func()
	// contains filtered or unexported fields
}

Runner is in charge of handling the main event loop. It sets up the screen and handles events (input, resizes, etc), delegating out to the views and key handlers.

The normal operation works like such:

At any given point in time, the runner has a given View.

When Run starts the main loop, it sets up the screen, and listens for events dispatching them as such:

- "Resize" events trigger a resize & redraw of the current view - "Update" events populate a new view and redraw - "Repaint" events repain the current view - "Key" events get sent to the KeyHandler

It's expected that a separate goroutine will receive key events, construct a new view based on their operation or based on outside events (like timers for animation, new graph data, etc), compute a new view, and send an update. Think of it kinda like a functional reactive UI framework, except a bit inside-out.

func (*Runner) HideCursor

func (r *Runner) HideCursor()

HideCursor hides the cursor.

func (*Runner) RequestRepaint

func (r *Runner) RequestRepaint()

RequestRepaint requests a repaint of the current view, if any. It will not block.

func (*Runner) RequestUpdate

func (r *Runner) RequestUpdate(newView View)

RequestRepaint replaces the current view & requests a paint of it. It will not block.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, initialView View) error

Run initializes the screen, starts the event loop (potentially with an optional initial view), and runs it until the given context is closed. When the context is closed, the screen is shut down, and the Run stops.

func (*Runner) ShowCursor

func (r *Runner) ShowCursor(col, row int)

ShowCursor shows the cursor at the given location.

type SplitView

type SplitView struct {
	// Dock indicates the position of the fixed-size pane.
	Dock DockPos

	// DockSize indicates the desired size of the fixed-size pane, in rows or
	// columns (depending on where the dock is).
	DockSize int
	// DockMaxPercent caps the actual size of the dock to a percentage of the screen.
	// For instance, if DockSize is 10, the screen size is 20, and DockMaxPercent is 25,
	// the actual dock size used would be 5.
	DockMaxPercent int

	// Docked contains the content for the docked pane.  If also Flushable, it
	// will receive calls to FlushTo as well.
	Docked Resizable
	// Flexed contains the content for the non-docked pane.  If also Flushable,
	// it will receive calls to FlushTo as well.
	Flexed Resizable
}

SplitView is a "view" that, given an overall size, knows how to divide that size between a "docked" fixed-size pane and another chunk of content. It's used for sidebars, terminals at the bottom of the screen, etc.

func (*SplitView) FlushTo

func (v *SplitView) FlushTo(screen tcell.Screen)

func (*SplitView) SetBox

func (v *SplitView) SetBox(box PositionBox)

type StaticResizable

type StaticResizable struct {
	PositionBox
}

StaticResizable just records the size it was given, without doing anything else.

func (*StaticResizable) SetBox

func (r *StaticResizable) SetBox(box PositionBox)

type TextBox

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

TextBox is a semi-static (i.e. not a text input widget) text container to which styled text can be written. It will automatically wrap text as necessary. If the text doesn't fit, some will be scrolled out of view.

func (*TextBox) FlushTo

func (t *TextBox) FlushTo(screen tcell.Screen)

func (*TextBox) SetBox

func (t *TextBox) SetBox(box PositionBox)

func (*TextBox) WriteString

func (t *TextBox) WriteString(str string, sty tcell.Style)

WriteString writes the given text to the text box in the given style, wrapping & scrolling if necessary.

type View

type View interface {
	Flushable
	Resizable
}

View represents a widget -- it can display (Flushable) and be given a size (Resizable).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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