cout

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cout provides verbosity-levelled, coloured console output for command-line tools.

Tools separate what they *log* (clog, stderr, for diagnosing the tool) from what they *print* (this package, for the person running it). Every print call carries a minimum verbosity so a --quiet or --verbose flag is honoured in one place, and colour tags such as <red>...</> are rendered by gookit/color, which strips them when stdout is not a colour terminal.

Tags are rendered anywhere in the final string, arguments included, so helpers may build coloured fragments and pass them through %s.

Index

Constants

This section is empty.

Variables

Err is where Errorf writes. It defaults to stderr and is separate from Out so errors stay visible when Out is redirected or discarded.

Level controls the output verbosity. Tools set it once from their flags before any output call; it is a plain variable rather than a setter so the cobra flag-handling block in every tool stays a one-line assignment.

Out is where normal output goes. It defaults to stdout; tools whose stdout is a data channel (a JSON emitter, an MCP server on stdio) point it at stderr so progress messages never corrupt the stream.

Functions

func Errorf

func Errorf(format string, args ...any)

Errorf prints an error to Err in every mode except silent, so failures stay visible even when Out is machine-readable (quiet) or suppressed.

func Printf

func Printf(format string, args ...any)

Printf prints normal output; suppressed in quiet and silent modes. Console write failures are not actionable, so they are dropped.

func Println

func Println(args ...any)

Println prints normal output followed by a newline, rendering colour tags in its arguments; suppressed in quiet and silent modes.

func QuietOnlyf

func QuietOnlyf(format string, args ...any)

QuietOnlyf prints only in quiet mode. Use it when quiet mode has its own terse format for a line that normal mode prints differently via Printf, so the two never appear together.

func Quietf

func Quietf(format string, args ...any)

Quietf prints in quiet mode and above. Use it for the one line a script would parse, which should also appear in normal output alongside any decoration Printf adds around it.

func Sprintf

func Sprintf(format string, args ...any) string

Sprintf formats like fmt.Sprintf and renders colour tags in the result. Use it to build coloured fragments that are later passed to Printf and friends, or to colour text destined for somewhere other than Out.

func Verbosef

func Verbosef(format string, args ...any)

Verbosef prints detail that only matters when someone asked for it with -v; suppressed at Normal and below.

func Writer

func Writer() io.Writer

Writer returns Out when Level is Normal or above and io.Discard below, for code that streams output through something else (a tabwriter, an encoder) and cannot go through Printf.

Types

type Verbosity

type Verbosity int

Verbosity is how much a tool prints. The levels are ordered, so "print at Normal and above" is a plain comparison.

const (
	// VerbositySilent prints nothing at all, not even errors. For callers that
	// only want the exit code.
	VerbositySilent Verbosity = iota
	// VerbosityQuiet prints only the minimal machine-readable lines (Quietf,
	// QuietOnlyf) and errors.
	VerbosityQuiet
	// VerbosityNormal is the default: everything a person wants to see.
	VerbosityNormal
	// VerbosityVerbose adds the detail behind Verbosef, typically -v.
	VerbosityVerbose
)

The verbosity levels, from least to most output.

func (Verbosity) String

func (v Verbosity) String() string

String returns the level's name in lower case, matching the flag that usually selects it.

Jump to

Keyboard shortcuts

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