ui

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 24 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 ui renders mdc's interactive output: shared styles and the live progress view.

Index

Constants

This section is empty.

Variables

View Source
var (
	Header = lipgloss.NewStyle().Bold(true)
	OK     = lipgloss.NewStyle().Foreground(lipgloss.Color("2"))
	Warn   = lipgloss.NewStyle().Foreground(lipgloss.Color("3"))
	Err    = lipgloss.NewStyle().Foreground(lipgloss.Color("1"))
	Dim    = lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
)

Shared styles. lipgloss downgrades or strips colour for the output terminal (including NO_COLOR) when rendering through its writers.

Functions

func Failure

func Failure(t discover.Target, err error) string

Failure is a project's title above its full error text.

func NameStyle

func NameStyle(name string) lipgloss.Style

NameStyle returns a style whose colour is stable for name, for prefixing log lines by project or service.

func ProjectTitle

func ProjectTitle(t discover.Target) string

ProjectTitle is the project name, followed by its directory when that differs from the name.

func RenderStats

func RenderStats(rows []ContainerStats, aggregate bool, width int) string

RenderStats lays out the rows as a table, per project when aggregate is set.

func RenderTable

func RenderTable(cols []Column, rows [][]string, width int) string

RenderTable lays out rows (cells may contain styling) in at most width columns. Low-value columns are dropped, then the widest remaining ones are truncated, so rows never wrap.

func RunLive

func RunLive(ctx context.Context, targets []discover.Target, fn func(ctx context.Context, live *Live) []runner.Outcome) ([]runner.Outcome, error)

RunLive shows a live view of targets while fn runs, then prints the final summary (including every failure's error text) after the view exits. Ctrl-C cancels the context passed to fn. It returns what fn returned.

outcomes, err := ui.RunLive(ctx, targets, func(ctx context.Context, live *ui.Live) []runner.Outcome {
	return runner.Run(ctx, targets, jobs, live.Track(func(ctx context.Context, t discover.Target) error {
		svc, err := be.Service(live.Processor(t), live.Prompt(t))
		if err != nil {
			return err
		}
		return svc.Start(ctx, t.ProjectName, api.StartOptions{})
	}))
})

func RunStats

func RunStats(ctx context.Context, aggregate bool, collect func(ctx context.Context, sink StatsSink) error) error

RunStats shows a table that collect keeps up to date through the sink, until collect returns, the user quits (q or ctrl+c) or ctx is cancelled.

func Section

func Section(t discover.Target, body string) string

Section is a project's title above its body.

func SkippedLine

func SkippedLine(t discover.Target, reason string) string

SkippedLine is the single dim line shown for a project that has nothing to do.

func Terminal

func Terminal(f *os.File) io.Writer

Terminal returns a writer for f that downgrades colours to what the terminal supports, and drops them under NO_COLOR.

func TerminalWidth

func TerminalWidth() int

TerminalWidth is the width of the output terminal, or 80 when unknown.

Types

type Column

type Column struct {
	Title string
	// Drop orders which columns go first when the table is too wide: higher
	// values are dropped first and 0 is never dropped.
	Drop int
}

Column describes one table column.

type ContainerStats

type ContainerStats struct {
	ID       string
	Project  string
	Name     string
	MemLimit float64
	Sampled  bool
	Usage
}

ContainerStats is one container's row. Usage is meaningful once Sampled.

type ContainerStatsView

type ContainerStatsView struct {
	Project  string
	Name     string
	CPUPerc  string
	MemUsage string
	MemPerc  string
	NetIO    string
	BlockIO  string
	PIDs     uint64
}

ContainerStatsView is a container row formatted for display and JSON output.

func ContainerViews

func ContainerViews(rows []ContainerStats) []ContainerStatsView

ContainerViews formats rows; containers not sampled yet show no figures.

type Live

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

Live is the handle given to the work running under RunLive. It is safe for concurrent use.

func (*Live) Finish

func (l *Live) Finish(o runner.Outcome)

Finish marks a target done with its outcome. Only the first call per target counts.

func (*Live) Processor

func (l *Live) Processor(t discover.Target) api.EventProcessor

Processor returns the event processor to give backend.Service for t.

func (*Live) Prompt

func (l *Live) Prompt(t discover.Target) compose.Prompt

Prompt returns the compose prompt to give backend.Service for t. Questions from all targets are asked one at a time; cancellation declines them.

func (*Live) Stop

func (l *Live) Stop() error

Stop ends the view and prints the summary of the targets finished so far. Work still running keeps its processors, which then report nowhere. It is called by RunLive once fn returns; call it earlier to hand the terminal to output that follows the progress, such as logs.

func (*Live) Track

func (l *Live) Track(fn runner.Func) runner.Func

Track wraps fn so each target is marked done in the view as soon as it returns, with the outcome runner.Run will record for it.

type LogStream

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

LogStream interleaves the output of containers from many projects into one prefixed stream. It is safe for concurrent use and writes whole lines only.

func NewLogStream

func NewLogStream(opts LogStreamOptions) *LogStream

NewLogStream creates a stream writing to opts.Out and opts.Err.

func (*LogStream) Consumer

func (s *LogStream) Consumer(project string, replicas map[string]int) api.LogConsumer

Consumer returns the log consumer of one project. replicas maps each of the project's services to how many containers it runs; the container index is shown in prefixes only for services with more than one. Its names are reserved up front so prefixes line up from the first line.

func (*LogStream) Notice

func (s *LogStream) Notice(project, text string)

Notice writes a dim line about a project as a whole.

func (*LogStream) Raw

func (s *LogStream) Raw(text string)

Raw writes text to Out unmodified, as one write.

type LogStreamOptions

type LogStreamOptions struct {
	// Out receives container output and status lines; Err receives container
	// stderr. Both are written to one whole line at a time.
	Out, Err io.Writer
	// Color colours the prefix per project and service.
	Color bool
	// Prefix puts "project/service │" before each line.
	Prefix bool
	// Timestamps puts the time a line was written before its text.
	Timestamps bool
}

LogStreamOptions choose how a LogStream decorates the lines it writes.

type ProjectStatsView

type ProjectStatsView struct {
	Project    string
	Containers int
	CPUPerc    string
	MemUsage   string
	NetIO      string
	BlockIO    string
	PIDs       uint64
}

ProjectStatsView is a project row formatted for display and JSON output.

func ProjectViews

func ProjectViews(rows []ContainerStats) []ProjectStatsView

ProjectViews sums the rows of each project. rows must be sorted by project.

type StatsSink

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

StatsSink receives the containers and samples a collector finds.

func (StatsSink) List

func (s StatsSink) List(items []ContainerStats)

List replaces the containers shown.

func (StatsSink) Sample

func (s StatsSink) Sample(id string, memLimit float64, u Usage)

Sample records one container's usage.

type Style

type Style = lipgloss.Style

Style is a lipgloss style.

func StateStyle

func StateStyle(state, health string) Style

StateStyle colours a container state, or its health when that is worse than the state suggests.

type Usage

type Usage struct {
	CPU        float64
	Memory     float64
	NetRx      float64
	NetTx      float64
	BlockRead  float64
	BlockWrite float64
	PIDs       uint64
}

Usage is the resource consumption of one or several containers.

Jump to

Keyboard shortcuts

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