backend

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 3 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package backend defines the runtime abstraction used by interact/ui.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileRequired indicates the backend requires an *os.File input.
	ErrFileRequired = errors.New("interact/backend: file input required")
	// ErrTTYRequired indicates the backend requires a terminal input stream.
	ErrTTYRequired = errors.New("interact/backend: tty required")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	NewSession(in io.Reader, out io.Writer) (Session, error)
}

Backend creates a terminal interaction session.

type Event

type Event struct {
	Type   EventType
	Key    Key
	Text   string
	Width  int
	Height int
}

Event is a normalized terminal input event.

type EventType

type EventType int

EventType defines the type of an interaction event.

const (
	EventUnknown EventType = iota
	EventKey
	EventInterrupt
	EventResize
)

type Key

type Key string

Key defines a normalized key value.

const (
	KeyUnknown   Key = ""
	KeyEnter     Key = "enter"
	KeyUp        Key = "up"
	KeyDown      Key = "down"
	KeyLeft      Key = "left"
	KeyRight     Key = "right"
	KeyHome      Key = "home"
	KeyEnd       Key = "end"
	KeyTab       Key = "tab"
	KeyShiftTab  Key = "shift+tab"
	KeyPageUp    Key = "pageup"
	KeyPageDown  Key = "pagedown"
	KeySpace     Key = "space"
	KeyEsc       Key = "esc"
	KeyBackspace Key = "backspace"
	KeyDelete    Key = "delete"
	KeyCtrlC     Key = "ctrl+c"
	KeyCtrlA     Key = "ctrl+a"
	KeyCtrlE     Key = "ctrl+e"
	KeyCtrlK     Key = "ctrl+k"
	KeyCtrlU     Key = "ctrl+u"
	KeyCtrlW     Key = "ctrl+w"
	KeyY         Key = "y"
	KeyN         Key = "n"
)

type Session

type Session interface {
	Render(view View) error
	ReadEvent(ctx context.Context) (Event, error)
	Size() (width, height int)
	Close() error
}

Session represents one terminal interaction session.

type View

type View struct {
	Lines        []string
	CursorRow    int
	CursorColumn int
	Width        int
	Height       int
	HideCursor   bool
}

View is a minimal renderable terminal frame.

Directories

Path Synopsis
Package fake provides an in-memory backend for interaction tests.
Package fake provides an in-memory backend for interaction tests.
Package plain provides a line-based backend for interact/ui.
Package plain provides a line-based backend for interact/ui.
Package readline provides a minimal raw-terminal event backend for interact/ui.
Package readline provides a minimal raw-terminal event backend for interact/ui.

Jump to

Keyboard shortcuts

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