Documentation
¶
Overview ¶
Package console is the interactive terminal console of Regulus and the plain-text and JSON output that takes its place when no terminal UI is wanted: what the hub is doing, its settings, its logs and health checks.
Index ¶
- Constants
- Variables
- func FormatBytes(n int64) string
- func Run(opt Options) error
- func UnicodeTerminal(getenv func(string) string) bool
- func UseTUI(c Choice, configTUI bool, getenv func(string) string, term Terminal) (use bool, reason string, err error)
- func WriteSettings(w io.Writer, entries []config.Entry, f Format) error
- func WriteStatus(w io.Writer, snap Snapshot, f Format, now time.Time) error
- type Agent
- type Check
- type Choice
- type Format
- type Hooks
- type Model
- type Options
- type Snapshot
- type System
- type Terminal
Constants ¶
const ( MinWidth = 60 MinHeight = 16 )
Minimum size for the full-screen console; below it the plain output is used.
const ( OK = "ok" Warn = "warn" Fail = "fail" Info = "info" )
Check statuses.
const ServiceUnit = "regulus"
ServiceUnit is the systemd unit of the hub.
Variables ¶
var T = en
T is the language in use.
Functions ¶
func UnicodeTerminal ¶
UnicodeTerminal guesses whether the terminal can show characters beyond ASCII (✓, ●, box lines) from the locale; without it the console draws with plain characters.
func UseTUI ¶
func UseTUI(c Choice, configTUI bool, getenv func(string) string, term Terminal) (use bool, reason string, err error)
UseTUI decides whether to open the full-screen console and says why not when it does not. The order is: command-line flags, then environment variables, then the configuration file (console.tui), then what the terminal looks like.
func WriteSettings ¶
WriteSettings prints the settings with their values and sources.
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"`
Status string `json:"status"`
Detail string `json:"detail"`
}
Check is one health check.
type Choice ¶
type Choice struct {
// TUI is true for --tui, false for --no-tui, nil when neither was given.
TUI *bool
// NoInput is --no-input: never ask anything, so no interactive screen.
NoInput bool
// Plain and JSON are the other output formats; they print instead of
// opening the screen.
Plain, JSON bool
}
Choice is what the person asked on the command line.
type Hooks ¶
type Hooks struct {
// ResetAdmin makes the one-time password reset link of the administrator.
ResetAdmin func(ctx context.Context) (link string, err error)
// Restart restarts the hub's service.
Restart func(ctx context.Context) error
}
Hooks are the actions that need more than the console knows how to do; the command supplies them. A nil hook hides its key.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the Bubble Tea model of the console.
type Options ¶
type Options struct {
System System
ConfigFile string
Version string
Hooks Hooks
// Unicode is false for terminals that cannot draw ✓ and the like.
Unicode bool
// Refresh is how often the screen reloads; zero turns it off (tests).
Refresh time.Duration
}
Options configures the console.
type Snapshot ¶
type Snapshot struct {
Version string `json:"version"`
// ConfigFile is the file the settings are read from and written to, or
// "" when there is none.
ConfigFile string `json:"config_file"`
// Problem is set when the configuration cannot be loaded.
Problem string `json:"problem,omitempty"`
// Service is the state of the systemd unit: active, inactive, failed,
// or unknown when systemd does not know it or is not there.
Service string `json:"service"`
// Running is true when the hub answered on its local socket.
Running bool `json:"running"`
Listen string `json:"listen"`
Port string `json:"port"`
URL string `json:"url"`
LANURLs []string `json:"lan_urls,omitempty"`
AgentListen string `json:"agent_listen,omitempty"`
DataDir string `json:"data_dir"`
DatabaseSize int64 `json:"database_bytes"`
BuiltinAgent bool `json:"builtin_agent"`
// LogLevel and Format are shown in the header of the logs.
LogLevel string `json:"log_level"`
StartedAt time.Time `json:"started_at,omitzero"`
Uptime string `json:"uptime,omitempty"`
SetupToken string `json:"setup_token,omitempty"`
Agents []Agent `json:"agents"`
Settings []config.Entry `json:"-"`
Health []Check `json:"health"`
}
Snapshot is everything the console shows about the hub at one moment.
type System ¶
type System struct {
Getenv func(string) string
Now func() time.Time
// ServiceState returns the systemd state of the hub's unit.
ServiceState func(ctx context.Context) string
// Fetch asks the running hub for its status.
Fetch func(ctx context.Context, dataDir string) (localstatus.Status, error)
// Addrs lists the IPv4 addresses of this machine, besides loopback.
Addrs func() []string
// Logs returns the last lines of the hub's log.
Logs func(ctx context.Context, n int) ([]string, error)
}
System is how the console looks at the machine. Tests replace it.