Documentation ¶
Index ¶
- func IsReplayDone(err error) bool
- func IsReplayStop(err error) bool
- func MustRun(in, out *os.File, run func(*Platform) error, opts ...Option)
- func Run(in, out *os.File, run func(*Platform) error, opts ...Option) error
- type BackgroundWorker
- type BackgroundWorkers
- type Client
- type ClientFunc
- type Config
- type Context
- type EditLine
- type EditLineState
- type Escape
- type EventType
- type Events
- func (es *Events) AnyPressesOutside(box ansi.Rectangle) bool
- func (es *Events) Clear()
- func (es *Events) CountPressesIn(box ansi.Rectangle, buttonID uint8) (n int)
- func (es *Events) CountRune(rs ...rune) (n int)
- func (es *Events) DecodeBytes(b []byte)
- func (es *Events) DecodeInput(in *anansi.Input)
- func (es *Events) Empty() bool
- func (es *Events) Escape(id int) Escape
- func (es *Events) HasTerminal(r rune) bool
- func (es *Events) LastMouse(consume bool) (m Mouse, have bool)
- func (es *Events) Mouse(id int) Mouse
- func (es *Events) Rune(id int) rune
- func (es *Events) TotalCursorMovement() (move image.Point)
- func (es *Events) TotalScrollIn(box ansi.Rectangle) (n int)
- type FPSEstimate
- type HUD
- type HUDState
- type LogSink
- func (logs *LogSink) Contents() ([]byte, []int)
- func (core *LogSink) Error() error
- func (core *LogSink) Notify() error
- func (logs *LogSink) Read(p []byte) (n int, err error)
- func (logs *LogSink) SetFile(f *os.File) error
- func (logs *LogSink) Start() error
- func (logs *LogSink) Stop() error
- func (logs *LogSink) Write(p []byte) (n int, _ error)
- type LogView
- type LogViewState
- type Mouse
- type Option
- type Platform
- type StallsData
- type StallsStats
- type State
- type Telemetry
- type TelemetryState
- type Ticker
- type TimingData
- type TimingStats
- type UIID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsReplayDone ¶
IsReplayDone returns true if the error was due to a replay session finishing.
func IsReplayStop ¶
IsReplayStop returns true if the error was due to the user canceling a replay.
Types ¶
type BackgroundWorker ¶
BackgroundWorker supports doing deferred work in between frames of a platform run loop. The Start() and Stop() methods are called before/after the run loop. The Notify() method is called at the end of the run loop, before going back to sleep to wait for the next frame tick.
The astute reader will note that BackgroundWorker itself provides no support for synchronizing with the background work. Any such needs must be implemented in-situ by the BackgroundWorker; no generic support is provided to block the start of the next frame to wait for prior triggered work to finish.
type BackgroundWorkers ¶
type BackgroundWorkers struct {
// contains filtered or unexported fields
}
BackgroundWorkers implements an anansi.Context-ually managed collection of background workers.
func (BackgroundWorkers) Enter ¶
func (bg BackgroundWorkers) Enter(term *anansi.Term) error
Enter starts the background workers, stopping on and returning first error.
func (BackgroundWorkers) Exit ¶
func (bg BackgroundWorkers) Exit(term *anansi.Term) (err error)
Exit stops all background workers, returning the first error, but stopping all regardless.
func (BackgroundWorkers) Notify ¶
func (bg BackgroundWorkers) Notify() error
Notify all background workers, stopping on and returning the first error.
type Client ¶
Client runs under a platform, processing input and generating output within each frame Context.
type ClientFunc ¶
ClientFunc is a convenient way to implement a Client (e.g. for testing).
func (ClientFunc) Update ¶
func (f ClientFunc) Update(ctx *Context) error
Update runs the aliased function.
type Config ¶
type Config struct { LogFileName string CPUProfileName string TraceFileName string MemProfileName string StartTiming bool // Whether to start and LogTiming bool // log timing right away TelemetryLogFileName string // log telemetry to file // contains filtered or unexported fields }
Config uration for a Platform; populated from -platform.* flags; it implements Option, so applications may unmarshal it from some file and pass it to New().
TODO hud manipulable / dynamic
func (*Config) AddFlags ¶
AddFlags adds flag variables to the given flag set that will allow the user to set various log and profiling files from the outset. If a non-empty prefix is given, then timing variables are also wired up.
type Context ¶
type Context struct { *Platform Time time.Time Err error Redraw bool Input *Events Output *anansi.TermScreen }
Context manages frame input and output state within a Platform.
func (*Context) Update ¶
func (ctx *Context) Update()
Update runs a client round: - resets screen buffer - hides cursor (TODO) - processes user Ctrl-L to implement redraw flag - hands off to any active replay - re-reads terminal size on redraw - processes user Ctrl-R to toggle recording / replaying - runs the Platform client Update, under HUD Update - flushes screen buffer
type EditLine ¶
type EditLine struct { State EditLineState Box ansi.Rectangle Buf []byte Cur int View int // contains filtered or unexported fields }
EditLine provides basic line-editing .
type EditLineState ¶
type EditLineState uint8
EditLineState code.
const ( EditLineReady EditLineState = iota EditLineDone EditLineCanceled )
EditLineState constants.
type Events ¶
type Events struct { Type []EventType // contains filtered or unexported fields }
Events holds a queue of input events that were available at the start of the current frame's time window.
func (*Events) AnyPressesOutside ¶
AnyPressesOutside returns true if there are any mouse presses outside the given rectangle.
func (*Events) CountPressesIn ¶
CountPressesIn counts mouse presses of the given button within the given rectangle, striking them out.
func (*Events) CountRune ¶
CountRune counts occurrences of any of the given runes, striking them out.
func (*Events) DecodeBytes ¶
DecodeBytes parses from the given byte slice; useful for replays and testing.
func (*Events) DecodeInput ¶
DecodeInput decodes all input currently read into the given input.
func (*Events) HasTerminal ¶
HasTerminal returns true if the given terminal rune is in the event queue, striking it and truncating any events after it.
func (*Events) LastMouse ¶
LastMouse returns the last mouse event, striking all mouse events out (including the last!) only if consume is true.
func (*Events) TotalCursorMovement ¶
TotalCursorMovement returns the total cursor movement delta (e.g. from arrow keys) striking out all such cursor movement events. Does not recognize cursor line movements (CNL and CPL).
type FPSEstimate ¶
type FPSEstimate struct { Value float64 // contains filtered or unexported fields }
FPSEstimate keep a running Frames Per Second estimate based on a windowed average.
type HUD ¶
type HUD struct { HUDState // contains filtered or unexported fields }
HUD implements a toggle-able debug overlay.
type HUDState ¶
type HUDState struct { // last mouse for status display Mouse Mouse // structural state Visible bool TimeDetail bool ProfDetail bool FPSControl bool FPSDetail bool // theme SelectAttr ansi.SGRAttr ButtonAttr ansi.SGRAttr // user interaction state Active UIID EdLin EditLine }
HUDState contains serializable HUD state.
type LogSink ¶
type LogSink struct {
// contains filtered or unexported fields
}
LogSink implements an in-memory log buffer.
var Logs LogSink
Logs is the LogSink installed as the output for the standard "logs" package.
func (*LogSink) Contents ¶
Contents all in-memory buffered bytes and a slice containing the index of all newlines within those bytes.
func (*LogSink) SetFile ¶
SetFile sets the sink's file destination, starting or stopping a background goroutine as needed.
func (*LogSink) Start ¶
Start a background goroutine to defer file writing, transitioning to such deferred writing model; file writes will not be performed until Notify() or Stop() is next called.
type LogView ¶
type LogView struct { LogViewState // contains filtered or unexported fields }
LogView is a scrollable log viewer.
TODO currently anchored to bottom of screen, and hardcoded to 10 lines high.
func NewLogView ¶
NewLogView creates a new log view attached to the given log buffer.
type LogViewState ¶
LogViewState contains serializable LogView state.
type Mouse ¶
type Mouse struct { State ansi.MouseState ansi.Point }
Mouse represents mouse data stored in an Events queue.
var ZM Mouse
ZM is a convenience name for the zero value of Mouse.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option customizes Platform's behavior.
type Platform ¶
type Platform struct { Config State Time time.Time // internal time (rewinds during replay) Telemetry HUD HUD // contains filtered or unexported fields }
Platform is a high level abstraction for implementing frame-oriented interactive fullscreen terminal programs.
func (*Platform) Run ¶
Run a client under a platform. It loads client state from any active replay buffer, and then runs the client under a ticker loop.
func (*Platform) RunWith ¶
RunWith runs the given function under the platform anansi.Term; such function should call Platform.Run one or more times.
func (*Platform) SetStallTracking ¶
SetStallTracking sets whether output stall tracking is enabled.
func (*Platform) SetTimingEnabled ¶
SetTimingEnabled sets whether frame timing data collection is enabled.
type StallsStats ¶
type StallsStats struct { N int Time time.Time Min time.Duration Max time.Duration Sum time.Duration Pct float64 }
StallsStats stores stats computed from the last round of output StallsData.
type Telemetry ¶
type Telemetry struct { TelemetryState FPSEstimate FPSEstimate Timing TimingData Stalls StallsData // contains filtered or unexported fields }
Telemetry contains platform runtime performance data.
type TelemetryState ¶
type TelemetryState struct { TimingEnabled bool StallDataEnabled bool LogTiming bool LogStallData bool }
TelemetryState contains serializable Telemetry state.
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker implements a contextual time.Ticker, start/stopping it during terminal enter/exit.
func (*Ticker) Enter ¶
Enter starts a new ticker, after stopping any prior one for good measure; always returns nil error.
type TimingData ¶
type TimingData struct { // state Stats TimingStats // contains filtered or unexported fields }
TimingData stores inter-frame timing data.