Documentation
¶
Overview ¶
Package console draws MagicHandy's launch console: the window that opens with the app on Windows. It shows the brand, where to open the app, recent activity in plain language, and a few keys. It never commands motion; its Stop key calls the action the caller supplies, which is the app's own emergency-stop path.
Index ¶
- Variables
- type Actions
- type Dashboard
- func (d *Dashboard) Finish(err error) bool
- func (d *Dashboard) Handler(level slog.Leveler) slog.Handler
- func (d *Dashboard) SetActions(actions Actions)
- func (d *Dashboard) SetRemote(url string)
- func (d *Dashboard) SetRunning()
- func (d *Dashboard) SetServer(url, access string, simulated bool)
- func (d *Dashboard) SetStopping()
- func (d *Dashboard) Start()
- type StopOutcome
- type Terminal
Constants ¶
This section is empty.
Variables ¶
var ErrNotInteractive = errors.New("console: not an interactive terminal")
ErrNotInteractive reports that input or output is redirected, or that the console cannot draw colour and move the cursor. Callers then keep plain structured logs.
Functions ¶
This section is empty.
Types ¶
type Actions ¶
type Actions struct {
// Open opens the app in the default browser.
Open func() error
// Copy puts the app link on the clipboard. Nil hides the key.
Copy func() error
OpenRemote func() error
CopyRemote func() error
// Stop stops motion through the app's emergency-stop path.
Stop func(context.Context) (StopOutcome, error)
// Quit begins a clean shutdown of the app.
Quit func()
}
Actions are what the console keys do. The dashboard only calls them.
type Dashboard ¶
type Dashboard struct {
// contains filtered or unexported fields
}
Dashboard draws the launch console. Logging, keys and status changes are posted to one goroutine that owns all state and drawing, so a slow or paused console never holds up the app.
func (*Dashboard) Finish ¶
Finish leaves the dashboard and restores the terminal. A last line says the app stopped, or why it could not keep running. When this process alone owns the window, which closes as soon as it exits, it waits for a key so the reason can be read. It reports whether it showed err.
func (*Dashboard) Handler ¶
Handler returns a slog handler that shows log records as recent activity. Handle never blocks on the terminal.
func (*Dashboard) SetActions ¶
SetActions connects the keys to the app.
func (*Dashboard) SetRemote ¶
SetRemote records the separate remote origin. An empty address means disabled.
func (*Dashboard) SetRunning ¶
func (d *Dashboard) SetRunning()
SetRunning marks the app ready to open.
func (*Dashboard) SetServer ¶
SetServer records where the app can be opened and how it can be reached.
func (*Dashboard) SetStopping ¶
func (d *Dashboard) SetStopping()
SetStopping marks the app as shutting down.
type StopOutcome ¶
type StopOutcome int
StopOutcome says what a Stop from the console achieved.
const ( // StopConfirmed means the device acknowledged the stop. StopConfirmed StopOutcome = iota // StopUnconfirmed means the stop was sent but the device did not confirm it. StopUnconfirmed // StopNothingConnected means no device was set up to receive a stop. StopNothingConnected )
type Terminal ¶
type Terminal interface {
Write(p []byte) (int, error)
// Size reports the visible columns and rows.
Size() (columns, rows int)
// ReadKey blocks until a key is pressed. A lone Escape is '\x1b'.
ReadKey() (rune, error)
// Restore returns input and output to the modes they had before Open.
Restore() error
// RichGlyphs reports whether the host renders stars and bullets that
// console fonts lack. Such hosts also open links on Ctrl+click.
RichGlyphs() bool
// SoleOwner reports whether this process alone uses the window, as when
// it was started from a shortcut; the window then closes when it exits.
SoleOwner() bool
}
Terminal is the text console the dashboard draws in.