fakewidget

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package fakewidget implements a fake widget that is useful for testing the termdash infrastructure.

Index

Constants

This section is empty.

Variables

View Source
var MinimumSize = image.Point{24, 5}

MinimumSize is the minimum size required to draw this widget.

Functions

func Draw

func Draw(t terminalapi.Terminal, cvs *canvas.Canvas, meta *widgetapi.Meta, opts widgetapi.Options, events ...terminalapi.Event) error

Draw draws the content that would be expected after placing the Mirror widget onto the provided canvas and forwarding the given events.

func DrawWithMirror

func DrawWithMirror(mirror *Mirror, t terminalapi.Terminal, cvs *canvas.Canvas, meta *widgetapi.Meta, events ...terminalapi.Event) error

DrawWithMirror is like Draw, but uses the provided Mirror instead of creating one.

func MustDraw

func MustDraw(t terminalapi.Terminal, cvs *canvas.Canvas, meta *widgetapi.Meta, opts widgetapi.Options, events ...terminalapi.Event)

MustDraw is like Draw, but panics on all errors.

func MustDrawWithMirror

func MustDrawWithMirror(mirror *Mirror, t terminalapi.Terminal, cvs *canvas.Canvas, meta *widgetapi.Meta, events ...terminalapi.Event)

MustDrawWithMirror is like DrawWithMirror, but panics on all errors.

Types

type Mirror

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

Mirror is a fake widget. The fake widget draws a border around its assigned canvas and writes the size of its assigned canvas on the first line of the canvas. It writes the last received keyboard event onto the second line. It writes the last received mouse event onto the third line. If a non-empty string is provided via the Text() method, that text will be written right after the canvas size on the first line. If the widget's container is focused it writes "focus" onto the fourth line.

The widget requests the same options that are provided to the constructor. If the options or canvas size don't allow for the lines mentioned above, the widget skips the ones it has no space for.

This is thread-safe and must not be copied. Implements widgetapi.Widget.

func New

func New(opts widgetapi.Options) *Mirror

New returns a new fake widget. The widget will return the provided options on a call to Options().

func (*Mirror) Draw

func (mi *Mirror) Draw(cvs *canvas.Canvas, meta *widgetapi.Meta) error

Draw draws up to there lines on the canvas, assuming there is space for them. Returns an error if the canvas is so small that it cannot even draw a 2x2 border on it, or of any of the text lines end up being longer than the width of the canvas. Draw implements widgetapi.Widget.Draw.

func (*Mirror) Keyboard

func (mi *Mirror) Keyboard(k *terminalapi.Keyboard) error

Keyboard draws the received key on the canvas. Sending the keyboard.KeyEsc causes this widget to forget the last keyboard event and return an error instead. Keyboard implements widgetapi.Widget.Keyboard.

func (*Mirror) Mouse

func (mi *Mirror) Mouse(m *terminalapi.Mouse) error

Mouse draws the canvas coordinates of the mouse event and the name of the received mouse button on the canvas. Sending the mouse.ButtonRight causes this widget to forget the last mouse event and return an error instead. Mouse implements widgetapi.Widget.Mouse.

func (*Mirror) Options

func (mi *Mirror) Options() widgetapi.Options

Options implements widgetapi.Widget.Options.

func (*Mirror) Text

func (mi *Mirror) Text(txt string)

Text stores a text that should be displayed right after the canvas size on the first line of the output.

Jump to

Keyboard shortcuts

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