ansi

package
v0.0.0-...-c3069ff Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 3 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Reset  = "\033[0m" // Reset the escape sequence
	Red    = "\033[31m"
	Green  = "\033[32m"
	Yellow = "\033[33m"
	Blue   = "\033[34m"
	Purple = "\033[35m"
	Cyan   = "\033[36m"
	Gray   = "\033[37m"
	White  = "\033[97m"
)

Ansi colors

View Source
const (
	Bold      = "\033[1m"
	Underline = "\033[4m"
	Inverse   = "\033[7m"
)

Ansi styles

View Source
const (
	LightRed    = "\033[91m"
	LightGreen  = "\033[92m"
	LightYellow = "\033[93m"
	LightBlue   = "\033[94m"
	LightPurple = "\033[95m"
	LightCyan   = "\033[96m"
)

Ansi 256 light colors

View Source
const (
	DarkRed    = "\033[31m"
	DarkGreen  = "\033[32m"
	DarkYellow = "\033[33m"
	DarkBlue   = "\033[34m"
	DarkPurple = "\033[35m"
	DarkCyan   = "\033[36m"
)

Ansi 256 dark colors

View Source
const (
	BgRed    = "\033[41m"
	BgGreen  = "\033[42m"
	BgYellow = "\033[43m"
	BgBlue   = "\033[44m"
	BgPurple = "\033[45m"
	BgCyan   = "\033[46m"
	BgGray   = "\033[47m"
)

Background colors

View Source
const (
	CursorUp    = "\033[A" // Move the cursor up
	CursorDown  = "\033[B" // Move the cursor down
	CursorRight = "\033[C" // Move the cursor right
	CursorLeft  = "\033[D" // Move the cursor left
)

Cursor movement

View Source
const (
	ClearScreen = "\033[2J" // Clear the screen
	ClearLine   = "\033[K"  // Clear the current line
	Backspace   = "\b"      // Backspace key
	Delete      = "\033[3~" // Delete key
	Enter       = "\r"      // Return carriage
	Tab         = "\t"      // Tab

	// Cursor positioning
	Home     = "\033[H"
	Position = "\033[%d;%dH"
	GetPos   = "\033[6n"

	// Save and restore cursor position
	SaveCursor    = "\033[s"
	RestoreCursor = "\033[u"

	// Hide and show cursor
	HideCursor = "\033[?25l"
	ShowCursor = "\033[?25h"

	// Overwrite the current line
	Overwrite = "\033[1A\033[2K"
)

Terminal control

View Source
const (
	RoundedTopLeft     = "╭" // Top left corner of a rounded box
	RoundedTopRight    = "╮" // Top right corner of a rounded box
	RoundedBottomLeft  = "╰" // Bottom left corner of a rounded box
	RoundedBottomRight = "╯" // Bottom right corner of a rounded box
	RoundedHoriz       = "─" // Horizontal line of a rounded box
	RoundedVert        = "│" // Vertical line of a rounded box
)

Rounded box characters

Variables

This section is empty.

Functions

func AddPadding

func AddPadding(content string, width int) string

AddPadding adds padding to a string to make it a certain width

func ColorF

func ColorF(color, format string, a ...interface{}) string

ColorF returns a formatted string with a color

func Errorf

func Errorf(format string, a ...interface{}) error

ErrorF returns a formatted error message

func FormatRoundedBox

func FormatRoundedBox(content string) string

FormatRoundedBox formats a string into a rounded box with proper padding

func GetCursorPos

func GetCursorPos() string

func GetWidth

func GetWidth(content string) int

Get the width of a multiline string

func HexBgAndFg

func HexBgAndFg(hexFg, hexBg, msg string) (string, error)

HexBgAndFg returns a string with a background and foreground color

func HexColor256

func HexColor256(r, g, b int, msg string) string

HexColor256 converts RGB values to an ANSI 256 color escape sequence and applies it to a message

func HexToBg

func HexToBg(hex string) (string, error)

HexToBg converts a hex color to a background color

func HexToRGB

func HexToRGB(hex string) (int, int, int, error)

HexToRGB converts a hex color string to an RGB string

Example:

U8color.HexColor256("#3498db") or U8Color.HexToColor("3498d")

HexToRGB converts a hex color string to an RGB string

func ItalicF

func ItalicF(format string, a ...interface{}) string

ItalicF returns a formatted string with italic style

func PrintBold

func PrintBold(msg string)

PrintBold prints a bold message to the console

func PrintColor

func PrintColor(color, msg string)

PrintColor prints a colored message to the console

func PrintColorAndBg

func PrintColorAndBg(color, bg, msg string)

PrintColorAndBg prints a colored message with a background to the console

func PrintColorAndBgBold

func PrintColorAndBgBold(color, bg, msg string)

PrintColorAndBgBold prints a colored bold message with a background to the console

func PrintColorBold

func PrintColorBold(color, msg string)

PrintColorBold prints a colored bold message to the console

func PrintColorUnderline

func PrintColorUnderline(color, msg string)

PrintColorUnderline prints a colored underlined message to the console

func PrintColorf

func PrintColorf(color, format string, a ...interface{})

PrintColorf prints a colored formatted message to the console

func PrintDebug

func PrintDebug(msg string)

PrintDebug prints a debug message to the console

func PrintError

func PrintError(msg string)

PrintError prints an error message to the console

func PrintErrorf

func PrintErrorf(format string, a ...interface{})

PrintErrorf prints a formatted error message to the console

func PrintInfo

func PrintInfo(msg string)

PrintInfo prints an info message to the console

func PrintInverse

func PrintInverse(msg string)

PrintInverse prints an inverted message to the console

func PrintItalic

func PrintItalic(msg string)

PrintItalic prints an italic message to the console

func PrintRoundedBottom

func PrintRoundedBottom(width int)

PrintRoundedBottom prints a rounded bottom

func PrintRoundedTop

func PrintRoundedTop(width int)

PrintRoundedTop prints a rounded top

func PrintSuccess

func PrintSuccess(msg string)

PrintSuccess prints a success message to the console

func PrintUnderline

func PrintUnderline(msg string)

PrintUnderline prints an underlined message to the console

func PrintWarning

func PrintWarning(msg string)

PrintWarning prints a warning message to the console

func RGBToColor256

func RGBToColor256(r, g, b int) int

RGBToColor256 converts RGB values to the nearest xterm 256 color code

func SPrintRoundedBottom

func SPrintRoundedBottom(width int) string

SPrintRoundedBottom returns a string with a rounded bottom

func SPrintRoundedTop

func SPrintRoundedTop(width int) string

SPrintRoundedTop returns a string with a rounded top

func SetCursorPos

func SetCursorPos(x, y int)

SetCursorPos sets the cursor position

func SprintHexf

func SprintHexf(hex string, msg string) (string, error)

SprintHexf returns a string with a hex color

Types

type U8Color

type U8Color string
const (
	SetColor  U8Color = "38"
	SetNormal U8Color = "5"
	SetHex    U8Color = "2"
	SetBgHex          = "48"
)
var Bit8Color U8Color

func (U8Color) Color256

func (s U8Color) Color256(color U8Color, msg string) string

Jump to

Keyboard shortcuts

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