Documentation
¶
Index ¶
- Constants
- Variables
- func SplitHorizontal(r Rect, topHeight int) (top Rect, bottom Rect)
- func SplitVertical(r Rect, leftWidth int) (left Rect, right Rect)
- type App
- type Attr
- type Cell
- type Color
- type ColorType
- type Context
- type Event
- type Frame
- type FrameEvent
- type Key
- type KeyEvent
- type Mod
- type MouseAction
- type MouseButton
- type MouseEvent
- type Option
- type Options
- type PasteEndEvent
- type PasteStartEvent
- type Point
- type Program
- type Rect
- type ResizeEvent
- type Screen
- type Size
- type Style
- type Terminal
Constants ¶
const Continuation rune = -1
Continuation is a sentinel rune used in wide-character continuation cells. Screen.Flush skips emitting output for cells containing Continuation.
Variables ¶
var ( ColorDefault = Color{Type: ColorTypeDefault} ColorBlack = Color{Type: ColorTypeANSI, Idx: 0} ColorRed = Color{Type: ColorTypeANSI, Idx: 1} ColorGreen = Color{Type: ColorTypeANSI, Idx: 2} ColorYellow = Color{Type: ColorTypeANSI, Idx: 3} ColorBlue = Color{Type: ColorTypeANSI, Idx: 4} ColorMagenta = Color{Type: ColorTypeANSI, Idx: 5} ColorCyan = Color{Type: ColorTypeANSI, Idx: 6} ColorWhite = Color{Type: ColorTypeANSI, Idx: 7} )
Basic ANSI Color Constants (0-7 offset logic for standard 30-37 / 40-47)
Functions ¶
func SplitHorizontal ¶
SplitHorizontal splits r into top and bottom rectangles.
Types ¶
type App ¶
type App interface {
// Init runs once after the terminal is ready.
Init(ctx *Context) error
// Update receives input, resize events, ticks, and internal messages.
Update(ctx *Context, ev Event) error
// Draw renders the current application state onto the provided Frame.
// It should avoid mutating application state.
Draw(ctx *Context, f *Frame)
}
App is the user-provided terminal program.
type Color ¶
type Color struct {
Type ColorType
R uint8 // Used for RGB (or ANSI index if preferred)
G uint8
B uint8
Idx uint8 // Used for 256-color index or basic ANSI index
}
type Context ¶
Context gives an app controlled access to runtime state.
func (*Context) CopyToClipboard ¶
CopyToClipboard copies text to the system clipboard via the terminal.
func (*Context) Post ¶
Post schedules fn to run on the program's event loop.
Post may be called safely from any goroutine. The function runs later in the same context as Update and Draw, so it may safely modify application state.
func (*Context) Quit ¶
func (c *Context) Quit()
Quit asks the program loop to stop after the current event is handled.
func (*Context) RequestFrame ¶
RequestFrame schedules a FrameEvent for a future animation frame.
It must be called from the program's event loop, such as from Init, Update, or a callback passed to Post. To request a frame from another goroutine, call Post and request the frame from its callback.
The application should call RequestFrame again from the FrameEvent handler if more frames are needed.
For example, RequestFrame(30) means "send me one FrameEvent about 1/30 second from now".
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is a value emitted by the terminal or runtime.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame is a drawable grid of terminal cells.
func (*Frame) Clear ¶
func (f *Frame) Clear()
Clear fills the frame with spaces using the default style.
type FrameEvent ¶
FrameEvent represents a timed redraw event. It only presents on-demand
type MouseAction ¶
type MouseAction int
MouseAction identifies a mouse action.
const ( MousePress MouseAction = iota MouseRelease MouseDrag )
type MouseButton ¶
type MouseButton int
MouseButton identifies a mouse button.
const ( MouseNone MouseButton = iota MouseLeft MouseMiddle MouseRight MouseWheelUp MouseWheelDown )
type MouseEvent ¶
type MouseEvent struct {
X int // starts from 0
Y int // starts from 0
Button MouseButton
Action MouseAction
Mod Mod
}
MouseEvent represents a terminal mouse event.
func (MouseEvent) String ¶
func (m MouseEvent) String() string
String returns a human-readable representation of the mouse event.
type Option ¶
type Option func(*Options)
Option changes Program options.
func WithAltScreen ¶
WithAltScreen enables or disables the alternate terminal screen.
func WithBracketedPaste ¶
WithBracketedPaste enables or disables bracketed paste mode (\x1b[?2004h).
type Options ¶
type Options struct {
AltScreen bool
Mouse bool
Kitty bool // kitty keyboard protocol
BracketedPaste bool
}
Options configures a Program.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the default Program options.
type PasteEndEvent ¶
type PasteEndEvent struct{}
type PasteStartEvent ¶
type PasteStartEvent struct{}
type Program ¶
type Program struct {
// contains filtered or unexported fields
}
Program owns the terminal lifecycle and event loop.
func (*Program) CopyToClipboard ¶
CopyToClipboard copies text to the system clipboard via the terminal.
type Rect ¶
Rect stores a rectangle in terminal cells.
type ResizeEvent ¶
ResizeEvent represents a terminal size change.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
Screen renders frames to a terminal output stream.
type Style ¶
Style stores foreground, background, and text attributes.
func (Style) Background ¶
Background returns s with a background color.
func (Style) Foreground ¶
Foreground returns s with a foreground color.