input

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: MIT Imports: 5 Imported by: 0

README

powerline

Go Reference

Demo using go run ./examples/input:

Demo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedMessage = fmt.Errorf("unsupported message")

ErrUnsupportedMessage is returned on an attempt to Send an unsupported object or message.

Functions

This section is empty.

Types

type Option

type Option func(r *reader)

Option tells the Reader how to behave.

func WatchMouseAll

func WatchMouseAll() Option

WatchMouseAll makes Reader watch and pipe Mouse click and move events.

func WatchMouseClick

func WatchMouseClick() Option

WatchMouseClick makes Reader watch and pipe Mouse click events.

func WatchWindowSize

func WatchWindowSize() Option

WatchWindowSize makes Reader watch and pipe Window size/resize events.

func WithInput

func WithInput(input io.Reader) Option

WithInput makes Reader listen for events on the given source. Use this if you want to use something other than os.Stdin as the source of events.

type Reader

type Reader interface {
	// Begin begins reading inputs.
	Begin(ctx context.Context)
	// End terminates reading.
	End()
	// Errors returns the channel with errors encountered while reading.
	Errors() <-chan error
	// KeyEvents returns the channel with events from the Keyboard.
	KeyEvents() <-chan tea.KeyMsg
	// MouseEvents returns the channel with events from the Mouse.
	MouseEvents() <-chan tea.MouseMsg
	// Send sends the message over the appropriate channel back to client. This
	// can be useful for testing and automated inputs.
	Send(msg any) error
	// WindowSizeEvents returns the channel with resize events from the Terminal
	// window.
	WindowSizeEvents() <-chan tea.WindowSizeMsg
	// Reset resets everything and prepares for new input, and will block if
	// called when reading is in progress and has not been End-ed yet.
	Reset() error
}

Reader channels Key, Mouse and Window Resize events to the caller through the publicly defined channels below. The caller needs to drain all the channels to prevent blocking.

It uses BubbleTea framework underneath the hood to make this happen, but provides a cleaner interface to just input handling.

func NewReader

func NewReader(opts ...Option) Reader

NewReader returns a new Reader with the provided options applied on it.

Jump to

Keyboard shortcuts

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