Documentation
¶
Overview ¶
Package console provides a generic console toolkit used by `dhcplane console attach`.
Index ¶
- Constants
- func Attach(opts AttachOptions) error
- func LevelOf(s string) string
- func MakeTagStyler(fg, bg, attrs string) func(s string, noColour bool) string
- type AttachOptions
- type Broker
- type BrokerOptions
- type Config
- type CounterSpec
- type HighlightSpec
- type Line
- type Meta
- type Notice
- type Style
- type UI
- func (u *UI) Append(line string)
- func (u *UI) Appendf(format string, args ...any)
- func (u *UI) ApplyConfig(cfg Config)
- func (u *UI) Do(fn func())
- func (u *UI) HighlightMap(match string, caseSensitive bool, style Style)
- func (u *UI) HighlightMapFunc(match string, caseSensitive bool, styler func(s string, noColour bool) string)
- func (u *UI) RegisterCounter(match string, caseSensitive bool, label string, windowSeconds int)
- func (u *UI) SetTitle(s string)
- func (u *UI) Tick(label string)
- type UIOptions
Constants ¶
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.
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
type BrokerOptions ¶
type Config ¶
type Config struct {
MaxLines int
Counters []CounterSpec
Highlights []HighlightSpec
}
Config captures shared presentation rules exchanged between broker and UI.
func (Config) EffectiveMaxLines ¶
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.
type Style ¶
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 (*UI) ApplyConfig ¶
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 ¶
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 ¶
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.