interact

package module
v0.0.0-...-ccaf28f Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2022 License: MIT Imports: 10 Imported by: 0

README

Interact

Build Status Code Coverage Latest Version Documentation Go Report Card

Interactive terminal utilities for asynchronous Go CLIs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Input

type Input interface {
	io.Reader
	Fd() uintptr
}

Input is a terminal input device.

func NewInput

func NewInput(r io.Reader) (Input, error)

NewInput returns an Input that reads from r.

type Key

type Key string

Key represents a key on a keyboard.

const (
	// KeyEscape is the ESCAPE key.
	KeyEscape Key = "\x00\x1b"

	// KeyBackspace is the BACKSPACE key.
	KeyBackspace Key = "\x00\x7f"

	// KeyDelete is the DELETE key.
	KeyDelete Key = "\x1b[3~"

	// KeyEnter is the ENTER or RETURN key.
	KeyEnter Key = "\x00\x0d"

	// KeyUp is the UP ARROW key.
	KeyUp Key = "\x1b[A"

	// KeyDown is the DOWN ARROW key.
	KeyDown Key = "\x1b[B"

	// KeyRight is the RIGHT ARROW key.
	KeyRight Key = "\x1b[C"

	// KeyLeft is the LEFT ARROW key.
	KeyLeft Key = "\x1b[D"
)

func (Key) IsRune

func (k Key) IsRune() bool

IsRune returns true if the key can be represented as a Unicode rune.

func (Key) Rune

func (k Key) Rune() (rune, bool)

Rune returns the unicode rune representation of the key,

func (Key) String

func (k Key) String() string

type KeyReader

type KeyReader struct {
	Reader *RawReader
	// contains filtered or unexported fields
}

KeyReader reads key-presses from a RawReader.

func (*KeyReader) ReadKey

func (r *KeyReader) ReadKey(ctx context.Context) (Key, error)

ReadKey reads the next key press.

type Output

type Output interface {
	io.Writer
	Fd() uintptr
}

Output is a terminal output device.

func NewOutput

func NewOutput(w io.Writer) (Output, error)

NewOutput returns an Output that writes to w.

type RawReader

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

RawReader reads from a terminal input device in "raw" mode.

func NewRawReader

func NewRawReader(in Input) (*RawReader, error)

NewRawReader returns a reader that reads from t in "raw" mode.

func (*RawReader) Close

func (r *RawReader) Close() error

Close closes the reader, restoring the terminal to its original mode.

It does not close the underlying input device.

func (*RawReader) Read

func (r *RawReader) Read(ctx context.Context) (byte, error)

Read reads a single byte from the terminal.

It blocks until a byte becomes available or ctx is canceled.

func (*RawReader) TryRead

func (r *RawReader) TryRead() (byte, bool, error)

TryRead reads a single byte from the terminal.

It does not block; if no byte is available ok is false.

Directories

Path Synopsis
Package termios allows reading and writing of terminal settings using the syscall.Termios type.
Package termios allows reading and writing of terminal settings using the syscall.Termios type.

Jump to

Keyboard shortcuts

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