Help us shape the future of Go! Take the 2026 Go Developer Survey

ui

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: ISC Imports: 6 Imported by: 6

README

UI

This package provides a simple interface with implementations for printing information in command-line applications. It supports various verbosity levels as well as formatting styles.

Quick Start

package main

import "github.com/gardenbed/charm/ui"

func main() {
  u := ui.New(ui.Info)
  u.Infof(ui.Green, "Hello, %s!", "World")
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black   = Style{FgBlack}
	Red     = Style{FgRed}
	Green   = Style{FgGreen}
	Yellow  = Style{FgYellow}
	Blue    = Style{FgBlue}
	Magenta = Style{FgMagenta}
	Cyan    = Style{FgCyan}
	White   = Style{FgWhite}
)

ANSI Colors

Functions

This section is empty.

Types

type ANSICode

type ANSICode int
const (
	Reset ANSICode = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)
const (
	FgBlack ANSICode = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)
const (
	BgBlack ANSICode = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)
const (
	Fg256 ANSICode = 38
	Bg256 ANSICode = 48
)

type Level

type Level int

Level represents the verbosity level.

const (
	// Trace shows all messages.
	Trace Level = iota
	// Debug shows Debug, Info, Warn, and Error messages.
	Debug
	// Info shows Info, Warn, and Error messages.
	Info
	// Warn shows Warn and Error messages.
	Warn
	// Error shows only Error messages.
	Error
	// None does not show any messages.
	None
)

type Style

type Style []ANSICode

Style allows multiple ANSI codes.

func Bg256Color added in v0.2.0

func Bg256Color(code int) Style

Bg256Color creates a style for a 256-color background color.

func BgTrueColor added in v0.2.0

func BgTrueColor(r, g, b int) Style

BgTrueColor creates a style for a 24-bit background color.

func Fg256Color added in v0.2.0

func Fg256Color(code int) Style

Fg256Color creates a style for a 256-color foreground color.

func FgTrueColor added in v0.2.0

func FgTrueColor(r, g, b int) Style

FgTrueColor creates a style for a 24-bit foreground color.

type UI

type UI interface {
	// Output method independent of the verbosity level
	Printf(format string, a ...interface{})

	// Leveled output methods
	GetLevel() Level
	SetLevel(l Level)
	Tracef(s Style, format string, a ...interface{})
	Debugf(s Style, format string, a ...interface{})
	Infof(s Style, format string, a ...interface{})
	Warnf(s Style, format string, a ...interface{})
	Errorf(s Style, format string, a ...interface{})
}

UI is the interface for interacting with users in command-line applications.

func New

func New(level Level) UI

New creates a new user interface. This is a concurrent-safe UI and can be used across multiple Go routines.

func NewNop

func NewNop() UI

NewNop creates a nop user interface for testing purposes.

Jump to

Keyboard shortcuts

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