bootblock

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package bootblock recognizes the startup summary an application printed and reports the next one as a difference from it.

The two halves of a reload know different things. The application resolved the configuration, and is the only place the values and their winning places exist; api:cli-dev restarted the process, and is the only place that knows a restart happened. Rather than teach the application that reloads exist, the loop reads back what it printed.

The cost of that is here and nowhere else: the layout of a startup summary becomes something a program reads as well as a person. The scanner and the parser below are the only code that assumes anything about it, and a block they cannot read is passed through unchanged, which is the behavior it replaces.

Index

Constants

This section is empty.

Variables

View Source
var Art = []string{
	"   .-.   .-.   ",
	" .(   ) (   ). ",
	"(   o     o   )",
	"(    \\___/    )",
	" '-.__.___.__-'",
}

Art is the framework's popcorn mascot, and its first row is how a startup summary is found in a stream. Every row is padded to the same width so the summary text lines up beside it, and every glyph is ASCII so no terminal renders it at an unexpected width.

Functions

func Render

func Render(out *strings.Builder, facts []FactChange, changes []Change, dim func(string) string)

Render writes a reload report: the facts that changed, then the changed rows in the tree they came from. dim styles the mark naming what happened to a row; pass a function that returns its argument unchanged to render without color.

Types

type Change

type Change struct {
	Key  string
	Kind Kind
	Old  pwtree.Entry
	New  pwtree.Entry
}

Change is one row of a reload report.

func Diff

func Diff(previous, current Report) []Change

Diff reports what the current summary says that the previous one did not. Removals come first and the rest follows the current summary's own order, so a section reads the way it reads in a full tree.

type FactChange

type FactChange struct{ Label, Old, New string }

FactChange is one thing the banner or the listening line said differently. These are not configuration keys, so they are reported above the tree rather than inside it.

func Facts

func Facts(previous, current Report) []FactChange

Facts compares what the banner and the listening line reported. The start time is not among them: comparing it would make every reload a change.

type Kind

type Kind int

Kind is what happened to one key between two summaries.

const (
	// Changed covers a new value and a new winning place alike, because the
	// summary reports the place for the same reason it reports the value.
	Changed Kind = iota
	// Added is a key the previous summary did not report at all, which is what
	// enabling a gated section looks like from here.
	Added
	// Removed is a key this summary no longer reports.
	Removed
)

type Report

type Report struct {
	Lines       []string
	Version     string
	Environment string
	ConfigFile  string
	Listening   string
	Entries     []pwtree.Entry
}

Report is one startup summary read back from what it printed. Lines is kept so a caller can print the summary rather than describe it, which is what the first one of a session gets.

func Parse

func Parse(lines []string) (Report, bool)

Parse reads a block the Scanner accumulated. It fails rather than guesses: a banner that no longer says what it used to leaves the caller with a block it should print unchanged.

type Scanner

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

Scanner accumulates the lines of one startup summary as they arrive.

func (*Scanner) Feed

func (s *Scanner) Feed(line string) (taken, complete bool)

Feed offers one line. taken reports that the line belonged to the summary and has been kept; complete reports that the summary ends here, with this line when it was taken and before it when it was not.

func (*Scanner) Holding

func (s *Scanner) Holding() bool

Holding reports whether a summary is being accumulated.

func (*Scanner) Take

func (s *Scanner) Take() []string

Take returns the accumulated lines and readies the scanner for the next summary.

Jump to

Keyboard shortcuts

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