output

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 10 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 output renders run results for humans (coloured, readable) and for machines (one JSON object per result). The string-returning renderers in render.go are shared with the terminal UI; the functions here are the io.Writer wrappers the CLI uses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Body

func Body(w io.Writer, res *runner.Result)

Body writes only the response body, pretty-printed when it is JSON.

func Checks

func Checks(t Theme, res *runner.Result, width int, expected bool) string

Checks renders the assertions, captures and errors of a result. With expected set, failed assertions show the expected value as well as the actual one.

func Describe

func Describe(t Theme, d *runner.Description, headers []httpfile.Header) string

Describe renders what `apic describe` shows. headers are the request's raw headers in file order.

func HighlightJSON

func HighlightJSON(t Theme, s string) string

HighlightJSON colours the keys, strings, numbers and literals of an already-indented, valid JSON document. It works line by line (JSON strings never span lines) and passes anything unexpected through untouched, so a document that is not JSON comes back unchanged.

func Human

func Human(w io.Writer, res *runner.Result, verbose bool)

Human writes a readable report of a result.

func Indent

func Indent(s string) string

Indent prefixes every line with two spaces.

func JSON

func JSON(w io.Writer, res *runner.Result) error

JSON writes one result as a single JSON line.

func Mask

func Mask(v runner.VarInfo) string

Mask returns a variable's value, or *** when it is a secret.

func Readiness

func Readiness(t Theme, d *runner.Description) string

Readiness renders the boxed verdict at the end of a description.

func RenderBody

func RenderBody(t Theme, raw []byte) string

RenderBody pretty-prints and highlights a JSON body; other bodies are returned as they are. The result has no trailing newline.

func RequestDetail

func RequestDetail(t Theme, res *runner.Result) string

RequestDetail renders the request headers and body (verbose mode).

func RequestLine

func RequestLine(t Theme, res *runner.Result) string

RequestLine renders "METHOD url" with the URL masked when redacting.

func ResponseHeaders

func ResponseHeaders(t Theme, res *runner.Result) string

ResponseHeaders renders the response headers sorted and lower-cased, with sensitive values masked and every value masked when redacting.

func Result

func Result(t Theme, res *runner.Result, o Options) string

Result renders the whole report for one request, as `apic run` prints it.

func Section

func Section(t Theme, title string) string

Section renders a bold section title preceded by a blank line.

func Size

func Size(n int) string

Size formats a byte count.

func StatusLine

func StatusLine(t Theme, res *runner.Result) string

StatusLine renders "200 OK · 87 ms · 412 B"; when the request never got a response it renders the errors instead.

func Summary

func Summary(w io.Writer, results []*runner.Result)

Summary writes the per-request table and totals of a flow.

func SummaryLine

func SummaryLine(t Theme, results []*runner.Result) string

SummaryLine renders "3 passed" or "1 failed, 3 passed".

func SummaryTable

func SummaryTable(t Theme, results []*runner.Result) string

SummaryTable renders one row per request followed by the totals line, for flows of more than one request.

func Truncate

func Truncate(s string, n int) string

Truncate flattens newlines and cuts s to n runes, appending an ellipsis.

func Variables

func Variables(t Theme, vars []runner.VarInfo, hints bool) string

Variables renders a variable table: name, value (masked when secret) and source, with hints for missing ones.

Types

type Options

type Options struct {
	Verbose bool // request headers and body, response headers
	Width   int  // where long values are cut; 0 means 80
}

Options controls how a result is rendered for humans.

type Theme

type Theme struct {
	Bold    lipgloss.Style
	Dim     lipgloss.Style
	OK      lipgloss.Style
	Warn    lipgloss.Style
	Fail    lipgloss.Style
	URL     lipgloss.Style
	Header  lipgloss.Style
	Capture lipgloss.Style
	Accent  lipgloss.Style

	// JSON syntax highlighting.
	Key lipgloss.Style
	Str lipgloss.Style
	Num lipgloss.Style
	Lit lipgloss.Style
	// contains filtered or unexported fields
}

Theme holds every style apic uses for human output, shared by the CLI renderers and the terminal UI so both look the same. Colours collapse to plain text automatically when lipgloss's colour profile is Ascii (--no-color, NO_COLOR, --json, or output that is not a terminal).

func Default

func Default() Theme

Default is the theme apic ships with.

func (Theme) Latency

func (t Theme) Latency(ms int64) string

Latency renders a duration in milliseconds, coloured by how long it took.

func (Theme) Mark

func (t Theme) Mark(pass bool) string

Mark renders a pass or fail tick.

func (Theme) Method

func (t Theme) Method(m string) string

Method renders an HTTP method in its colour.

func (Theme) Status

func (t Theme) Status(code int, text string) string

Status renders "200 OK" coloured by status class.

func (Theme) StatusCode

func (t Theme) StatusCode(code int) string

StatusCode renders the status number on its own, coloured by class, for the places too narrow for the reason phrase.

Jump to

Keyboard shortcuts

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