term

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package term provides terminal I/O, output formatting, and color conventions for the Krewire ecosystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Paint

func Paint(text string, color Color, styles []Style) string

Paint wraps text in ANSI escape sequences for the given color and styles. Use Terminal.Paint instead when the output may not support colors.

Types

type Color

type Color int

Color is an ANSI 16-color palette value.

const (
	// ColorBlack is ANSI black.
	ColorBlack Color = 30
	// ColorRed is ANSI red.
	ColorRed Color = 31
	// ColorGreen is ANSI green.
	ColorGreen Color = 32
	// ColorYellow is ANSI yellow.
	ColorYellow Color = 33
	// ColorBlue is ANSI blue.
	ColorBlue Color = 34
	// ColorMagenta is ANSI magenta.
	ColorMagenta Color = 35
	// ColorCyan is ANSI cyan.
	ColorCyan Color = 36
	// ColorWhite is ANSI white.
	ColorWhite Color = 37
	// ColorDefault is the terminal default foreground.
	ColorDefault Color = 39
)

type Style

type Style int

Style is a text rendering style.

const (
	// StyleBold is bold weight.
	StyleBold Style = 1
	// StyleDim is dim intensity.
	StyleDim Style = 2
	// StyleUnderline is underlined text.
	StyleUnderline Style = 4
)

type Terminal

type Terminal struct {
	// ColorSupported reports whether ANSI color codes should be emitted.
	ColorSupported bool
}

Terminal guards against emitting color codes when the destination does not support them.

func NewTerminal

func NewTerminal() *Terminal

NewTerminal detects color support from the NO_COLOR and TERM environment variables.

func (*Terminal) Paint

func (t *Terminal) Paint(text string, color Color, styles []Style) string

Paint colors text, degrading to plain text when color is unsupported.

Jump to

Keyboard shortcuts

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