Documentation
¶
Overview ¶
Package ui renders mdc's interactive output: shared styles and the live progress view.
Index ¶
- Variables
- func Failure(t discover.Target, err error) string
- func NameStyle(name string) lipgloss.Style
- func ProjectTitle(t discover.Target) string
- func RenderStats(rows []ContainerStats, aggregate bool, width int) string
- func RenderTable(cols []Column, rows [][]string, width int) string
- func RunLive(ctx context.Context, targets []discover.Target, ...) ([]runner.Outcome, error)
- func RunStats(ctx context.Context, aggregate bool, ...) error
- func Section(t discover.Target, body string) string
- func SkippedLine(t discover.Target, reason string) string
- func Terminal(f *os.File) io.Writer
- func TerminalWidth() int
- type Column
- type ContainerStats
- type ContainerStatsView
- type Live
- type LogStream
- type LogStreamOptions
- type ProjectStatsView
- type StatsSink
- type Style
- type Usage
Constants ¶
This section is empty.
Variables ¶
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 NameStyle ¶
NameStyle returns a style whose colour is stable for name, for prefixing log lines by project or service.
func ProjectTitle ¶
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 ¶
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 SkippedLine ¶
SkippedLine is the single dim line shown for a project that has nothing to do.
func Terminal ¶
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 ¶
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 ¶
Prompt returns the compose prompt to give backend.Service for t. Questions from all targets are asked one at a time; cancellation declines them.
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 ¶
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.
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.
type Style ¶
Style is a lipgloss style.
func StateStyle ¶
StateStyle colours a container state, or its health when that is worse than the state suggests.