console

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: GPL-2.0 Imports: 12 Imported by: 0

README

planeconsole

The monitor console used by the tools in this platform.

Documentation

Overview

Package console provides a generic console toolkit used by `dhcplane console attach`.

Index

Constants

View Source
const DefaultMaxLines = 10000

Variables

This section is empty.

Functions

func Attach

func Attach(opts AttachOptions) error

Attach connects to the server socket and renders the full interactive UI locally.

func LevelOf

func LevelOf(s string) string

LevelOf derives a coarse level from the line prefix.

func MakeTagStyler

func MakeTagStyler(fg, bg, attrs string) func(s string, noColour bool) string

MakeTagStyler returns a styler that wraps text with a tview tag [fg:bg:attrs]..[-:-:-]. fg/bg can be named or hex; attrs is like "b", "bu", "i", "u", "d", "t".

Types

type AttachOptions

type AttachOptions struct {
	Socket            string // optional override; if empty, auto-detect default path order
	SocketCandidates  []string
	SocketResolver    func() (string, error)
	NoColour          bool
	Transparent       bool
	Title             string // optional title override
	DisconnectMessage string
	OnExit            func(int)
}

AttachOptions control how the client connects and renders.

type Broker

type Broker struct {
	// contains filtered or unexported fields
}

func NewBroker

func NewBroker(opts BrokerOptions) *Broker

func (*Broker) Append

func (b *Broker) Append(line string)

func (*Broker) Appendf

func (b *Broker) Appendf(format string, args ...any)

func (*Broker) Start

func (b *Broker) Start() error

func (*Broker) Stop

func (b *Broker) Stop()

type BrokerOptions

type BrokerOptions struct {
	Config           Config
	SocketCandidates []string
	ListenerFactory  func() (string, net.Listener, error)
}

type Config

type Config struct {
	MaxLines   int
	Counters   []CounterSpec
	Highlights []HighlightSpec
}

Config captures shared presentation rules exchanged between broker and UI.

func (Config) EffectiveMaxLines

func (cfg Config) EffectiveMaxLines() int

EffectiveMaxLines returns a sane positive value for ring buffer sizing.

type CounterSpec

type CounterSpec struct {
	Match         string `json:"match"`
	CaseSensitive bool   `json:"case_sensitive"`
	Label         string `json:"label"`
	WindowSeconds int    `json:"window_s"`
}

CounterSpec describes a rolling counter filter matched against log lines.

type HighlightSpec

type HighlightSpec struct {
	Match         string `json:"match"`
	CaseSensitive bool   `json:"case_sensitive"`
	Style         *Style `json:"style,omitempty"`
}

HighlightSpec describes a substring highlight with an optional style.

type Line

type Line struct {
	Type  string `json:"type"`
	TsUs  int64  `json:"ts_us"`
	Text  string `json:"text"`
	Level string `json:"level"`
}

Line carries a single console line with its original timestamp and a coarse level.

type Meta

type Meta struct {
	Type       string          `json:"type"`
	MaxLines   int             `json:"max_lines"`
	Counters   []CounterSpec   `json:"counters"`
	Highlights []HighlightSpec `json:"highlights"`
}

Meta is the first message broker sends to each client describing limits and rules.

func MakeMeta

func MakeMeta(cfg Config) Meta

MakeMeta converts the static config into a Meta payload ready for JSON encoding.

type Notice

type Notice struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

Notice informs a slow client that some lines were dropped locally.

type Style

type Style struct {
	FG    string `json:"fg"`
	BG    string `json:"bg"`
	Attrs string `json:"attrs"`
}

Style defines a simple tview tag style: [FG:BG:ATTRS] ... [-:-:-] FG/BG accept named colors ("red") or hex ("#ff3366"); empty keeps current. Attrs is a compact string like "b", "bu", "i", "u", "d", "t".

type UI

type UI struct {
	// contains filtered or unexported fields
}

UI represents the interactive client UI.

func NewUI

func NewUI(opts UIOptions) *UI

New creates a new console UI with the given options.

func (*UI) Append

func (u *UI) Append(line string)

Append appends a new line to the console UI (client side only).

func (*UI) Appendf

func (u *UI) Appendf(format string, args ...any)

Appendf is like Append but with formatting.

func (*UI) ApplyConfig

func (u *UI) ApplyConfig(cfg Config)

ApplyConfig replaces current counters, highlights, and max-lines settings with cfg.

func (*UI) Do

func (u *UI) Do(fn func())

Do queues the given function to be executed in the UI event loop.

func (*UI) HighlightMap

func (u *UI) HighlightMap(match string, caseSensitive bool, style Style)

HighlightMap registers a highlight rule with the given match string (substring), case sensitivity, and style. Each time a line is appended, all registered highlight rules are applied in order (first-registered wins) to style matching substrings. If no style is given (empty), the match is ignored.

func (*UI) HighlightMapFunc

func (u *UI) HighlightMapFunc(match string, caseSensitive bool, styler func(s string, noColour bool) string)

HighlightMapFunc registers a rule with a custom styler. The styler is called with the matched substring and noColour flag.

func (*UI) RegisterCounter

func (u *UI) RegisterCounter(match string, caseSensitive bool, label string, windowSeconds int)

RegisterCounter registers a counter with the given match string (substring), case sensitivity, label, and rolling window in seconds (default 60s if <=0). Each time a line is appended that contains the match string, the counter is incremented. The status bar shows the count of matches within the rolling window.

func (*UI) SetTitle

func (u *UI) SetTitle(s string)

SetTitle sets the title of the UI, shown in the help modal.

func (*UI) Tick

func (u *UI) Tick(label string)

Tick increments the counter with the given label by one.

type UIOptions

type UIOptions struct {
	HelpExtra     []string
	MaxLines      int
	OnExit        func(code int)
	Rules         Config
	NoColour      bool
	MouseEnabled  bool
	DisableTopBar bool // false = show top bar (Title | Counters); true = legacy: no top bar
}

UIOptions defines options for the console UI.

Jump to

Keyboard shortcuts

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