avyos.dev/pkg/format

package format

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants1
Variables0
Functions9
Types3

Constants

const (
	Reset     = "\033[0m"
	Bold      = "\033[1m"
	Dim       = "\033[2m"
	Underline = "\033[4m"

	Black   = "\033[30m"
	Red     = "\033[31m"
	Green   = "\033[32m"
	Yellow  = "\033[33m"
	Blue    = "\033[34m"
	Magenta = "\033[35m"
	Cyan    = "\033[36m"
	White   = "\033[37m"

	BgBlack   = "\033[40m"
	BgRed     = "\033[41m"
	BgGreen   = "\033[42m"
	BgYellow  = "\033[43m"
	BgBlue    = "\033[44m"
	BgMagenta = "\033[45m"
	BgCyan    = "\033[46m"
	BgWhite   = "\033[47m"
)

ANSI color codes

Functions

func Color(color, text string) string

Color applies a color to text if colors are enabled.

func DisableColor()

DisableColor disables color output.

func EnableColor()

EnableColor enables color output.

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

Error formats an error message in red.

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

Info formats an info message in cyan.

func Percent(value, total float64) string

Percent formats a percentage.

func Size(bytes int64) string

Size formats a byte count as a human-readable string.

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

Success formats a success message in green.

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

Warn formats a warning message in yellow.

Types

ProgressBar

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

ProgressBar represents a progress bar.

Functions

func NewProgressBar(total int64, width int) *ProgressBar

NewProgressBar creates a new progress bar.

Methods

func (p *ProgressBar) Finish()

Finish completes the progress bar.

func (p *ProgressBar) Increment(n int64)

Increment increments the progress by n.

func (p *ProgressBar) SetLabel(label string)

SetLabel sets the label for the progress bar.

func (p *ProgressBar) Update(current int64)

Update updates the progress bar.

Table

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

Table represents a formatted table.

Functions

func NewTable(headers ...string) *Table

NewTable creates a new table with the given headers.

Methods

func (t *Table) AddRow(cols ...string)

AddRow adds a row to the table.

func (t *Table) Print()

Print prints the table to stdout.

func (t *Table) String() string

String returns the formatted table as a string.

Tree

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

Tree represents a tree structure for display.

Functions

func NewTree(label string) *Tree

NewTree creates a new tree node.

Methods

func (t *Tree) AddChild(child *Tree) *Tree

AddChild adds a child node to the tree.

func (t *Tree) AddChildLabel(label string) *Tree

AddChildLabel adds a child with the given label.

func (t *Tree) Print()

Print prints the tree to stdout.

func (t *Tree) String() string

String returns the tree as a formatted string.