console

package
v0.1.0-alpha.60 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: GPL-3.0 Imports: 10 Imported by: 0 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 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

Constants

This section is empty.

Variables

View Source
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 New

func New(term Terminal, version string) *Dashboard

New returns a dashboard for the terminal. Call Start to show it.

func (*Dashboard) Finish

func (d *Dashboard) Finish(err error) bool

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

func (d *Dashboard) Handler(level slog.Leveler) slog.Handler

Handler returns a slog handler that shows log records as recent activity. Handle never blocks on the terminal.

func (*Dashboard) SetActions

func (d *Dashboard) SetActions(actions Actions)

SetActions connects the keys to the app.

func (*Dashboard) SetRemote

func (d *Dashboard) SetRemote(url string)

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

func (d *Dashboard) SetServer(url, access string, simulated bool)

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.

func (*Dashboard) Start

func (d *Dashboard) Start()

Start switches the terminal to the dashboard and begins drawing.

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.

func Open

func Open() (Terminal, error)

Open reports ErrNotInteractive outside Windows, where MagicHandy keeps its structured logs; the launch console is for the window Windows opens with the app.

Jump to

Keyboard shortcuts

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