Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToHumanReadable(bytes int64, separator string) string
- func Colored(text string, color Color) string
- func PrintBoxHeadingContent(heading []string, headingColors []Color, content []KeyValue, keyColor Color, ...)
- func PrintColor(col Color, a ...any)
- func PrintfColor(format string, col Color, a ...any)
- func PrintlnColor(message string, col Color)
- func TestBoxPrint()
- func ZeroIfNegative(a int) int
- type BoxChars
- type Color
- type KeyValue
Constants ¶
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 ¶
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
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 ¶
BytesToHumanReadable converts bytes to human-readable format (KB, MB, GB) Output: "12 MB" or "12 GB" or "890 KB"
func Colored ¶
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 PrintfColor ¶
func PrintlnColor ¶
func ZeroIfNegative ¶
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?