print

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 2 Imported by: 2

Documentation

Index

Constants

View Source
const (
	Reset        = "\033[0m"
	Red          = "\033[31m"
	Green        = "\033[32m"
	Yellow       = "\033[33m"
	Blue         = "\033[34m"
	Purple       = "\033[35m"
	Cyan         = "\033[36m"
	Gray         = "\033[37m"
	DarkGray     = "\033[90m"
	LightRed     = "\033[91m"
	LightGreen   = "\033[92m"
	LightYellow  = "\033[93m"
	LightBlue    = "\033[94m"
	LightMagenta = "\033[95m"
	LightCyan    = "\033[96m"
	White        = "\033[97m"
)

ANSI color codes

Variables

View Source
var (
	ColorRed          = Color{Red}
	ColorGreen        = Color{Green}
	ColorYellow       = Color{Yellow}
	ColorBlue         = Color{Blue}
	ColorPurple       = Color{Purple}
	ColorCyan         = Color{Cyan}
	ColorGray         = Color{Gray}
	ColorDarkGray     = Color{DarkGray}
	ColorLightRed     = Color{LightRed}
	ColorLightGreen   = Color{LightGreen}
	ColorLightYellow  = Color{LightYellow}
	ColorLightBlue    = Color{LightBlue}
	ColorLightMagenta = Color{LightMagenta}
	ColorLightCyan    = Color{LightCyan}
	ColorWhite        = Color{White}
	ColorNothing      = Color{""}
	ColorReset        = Color{Reset}
)

Predefined colors for convenience as variables (can be changed) These are the colors that can be used directly You can use these colors directly in your code Example: fmt.Println(ColorRed.Code + "This is red text" + Reset) You can also use the Color struct to create your own colors Example: myColor := Color{Code: "\033[38;5;82m"} // Custom color

View Source
var UnicodeBox = BoxChars{
	TopLeft:     "┌",
	TopRight:    "┐",
	BottomLeft:  "└",
	BottomRight: "┘",
	Horizontal:  "─",
	Vertical:    "│",
}

UnicodeBox is the default box characters used for drawing boxes You can change this to use different styles Example: UnicodeBox = BoxChars{TopLeft: "╔", TopRight: "╗", BottomLeft: "╚", BottomRight: "╝", Horizontal: "═", Vertical: "║"} Example: UnicodeBox = BoxChars{TopLeft: "╭", TopRight: "╮", BottomLeft: "╰", BottomRight: "╯", Horizontal: "─", Vertical: "│"} Example: UnicodeBox = BoxChars{TopLeft: "┏", TopRight: "┓", BottomLeft: "┗", BottomRight: "┛", Horizontal: "━", Vertical: "┃"} Example: UnicodeBox = BoxChars{TopLeft: "╓", TopRight: "╖", BottomLeft: "╙", BottomRight: "╜", Horizontal: "─", Vertical: "│"} Example: UnicodeBox = BoxChars{TopLeft: "┌", TopRight: "┐", BottomLeft: "└", BottomRight: "┘", Horizontal: "─", Vertical: "│"}

Functions

func BytesToHumanReadable

func BytesToHumanReadable(bytes int64, separator string) string

BytesToHumanReadable converts bytes to human-readable format (KB, MB, GB) Output: "12 MB" or "12 GB" or "890 KB"

func Colored

func Colored(text string, color Color) string

Colored is a function that takes a string and a color code and returns the string with the color code applied This is used to colorize the text Example: Colored("Hello World", ColorRed.Code) // This will return the string with red color code

func PrintBoxHeadingContent

func PrintBoxHeadingContent(heading []string, headingColors []Color, content []KeyValue, keyColor Color, valueColor Color)

func PrintColor

func PrintColor(col Color, a ...any)

Mapping for Print, Println and Printf

func PrintfColor

func PrintfColor(format string, col Color, a ...any)

func PrintlnColor

func PrintlnColor(message string, col Color)

func TestBoxPrint

func TestBoxPrint()

Here is the example to call this.

func ZeroIfNegative

func ZeroIfNegative(a int) int

Helper function to get maximum value (to ensure no negative padding)

Types

type BoxChars

type BoxChars struct {
	TopLeft     string
	TopRight    string
	BottomLeft  string
	BottomRight string
	Horizontal  string
	Vertical    string
}

BoxChars represents the characters used to draw a box This is used to draw a box around the text You can change these characters to use different styles Example: BoxChars{TopLeft: "╔", TopRight: "╗", BottomLeft: "╚", BottomRight: "╝", Horizontal: "═", Vertical: "║"} Example: BoxChars{TopLeft: "┌", TopRight: "┐", BottomLeft: "└", BottomRight: "┘", Horizontal: "─", Vertical: "│"} Example: BoxChars{TopLeft: "╭", TopRight: "╮", BottomLeft: "╰", BottomRight: "╯", Horizontal: "─", Vertical: "│"} Example: BoxChars{TopLeft: "┏", TopRight: "┓", BottomLeft: "┗", BottomRight: "┛", Horizontal: "━", Vertical: "┃"} Example: BoxChars{TopLeft: "╓", TopRight: "╖", BottomLeft: "╙", BottomRight: "╜", Horizontal: "─", Vertical: "│"}

type Color

type Color struct {
	Code string
}

Color represents a color code for terminal output, for readibility

type KeyValue

type KeyValue struct {
	Key       string
	Value     string
	OneColumn bool // If true, this entry will use the full width (one column)
	EmptyLine bool // If true, this will render as an empty line with just borders
}

Used to print 2 columns of key-value pairs in a box, between left and right border KeyValue represents a key-value pair TODO: change this to KeyValueStrings and maybe put them in object?

func Content

func Content(singleColumn, empty bool, k interface{}, v interface{}) KeyValue

Just alias to make the code shorter

Jump to

Keyboard shortcuts

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