ansi

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 1 Imported by: 0

README

ANSI

ANSI Example

The ansi component provides a simple and user-friendly way to add color and formatting to terminal output in Go applications. Enhance your command-line interfaces with vibrant text, background colors, and text styles, making your output more readable and visually appealing.

You can found an example with and without options here

Documentation

Index

Constants

View Source
const (
	Reset      = ESC + "[0m"
	Bold       = ESC + "[1m"
	Faint      = ESC + "[2m"
	Italic     = ESC + "[3m"
	Underline  = ESC + "[4m"
	Blink      = ESC + "[5m"
	Reverse    = ESC + "[7m"
	CrossedOut = ESC + "[9m"
)

Ex: fmt.Println(ansi.Underline + "Underlined text")

View Source
const (
	Black   = ESC + "[30m"
	Red     = ESC + "[31m"
	Green   = ESC + "[32m"
	Yellow  = ESC + "[33m"
	Blue    = ESC + "[34m"
	Magenta = ESC + "[35m"
	Cyan    = ESC + "[36m"
	White   = ESC + "[37m"

	BrightBlack   = ESC + "[90m"
	BrightRed     = ESC + "[91m"
	BrightGreen   = ESC + "[92m"
	BrightYellow  = ESC + "[93m"
	BrightBlue    = ESC + "[94m"
	BrightMagenta = ESC + "[95m"
	BrightCyan    = ESC + "[96m"
	BrightWhite   = ESC + "[97m"
)

Ex: fmt.Println(ansi.Blue + "Blue text")

View Source
const (
	BgBlack   = ESC + "[40m"
	BgRed     = ESC + "[41m"
	BgGreen   = ESC + "[42m"
	BgYellow  = ESC + "[43m"
	BgBlue    = ESC + "[44m"
	BgMagenta = ESC + "[45m"
	BgCyan    = ESC + "[46m"
	BgWhite   = ESC + "[47m"

	BgBrightBlack   = ESC + "[100m"
	BgBrightRed     = ESC + "[101m"
	BgBrightGreen   = ESC + "[102m"
	BgBrightYellow  = ESC + "[103m"
	BgBrightBlue    = ESC + "[104m"
	BgBrightMagenta = ESC + "[105m"
	BgBrightCyan    = ESC + "[106m"
	BgBrightWhite   = ESC + "[107m"
)

Ex: fmt.Println(ansi.BgBlue + "Text with a blue background")

View Source
const (
	CursorHome      = ESC + "[H"
	CursorSave      = ESC + "[s"
	CursorRestore   = ESC + "[u"
	CursorVisible   = ESC + "[?25h"
	CursorInvisible = ESC + "[?25l"
)
View Source
const (
	AlternativeBufferEnable  = ESC + "[?1049h"
	AlternativeBufferDisable = ESC + "[?1049l"
)
View Source
const (
	ScreenSave      = ESC + "[?47h"
	ScreenRestore   = ESC + "[?47l"
	ScreenClear     = ESC + "[2J"
	ScreenClearUp   = ESC + "[1J"
	ScreenClearDown = ESC + "[0J"
	ScreenClearEnd  = ESC + "[J"
)
View Source
const (
	LineClear      = ESC + "[2K"
	LineClearStart = ESC + "[1K"
	LineClearEnd   = ESC + "[K"
)
View Source
const ESC = "\033"

Escape code

Variables

This section is empty.

Functions

func Bg256

func Bg256(color uint8) string

256 Background Color Ex: fmt.Println(ansi.Bg256(27) + "Text with a blue background")

func BgRgb

func BgRgb(red, green, blue uint8) string

RGB Background Color Ex: fmt.Println(ansi.BgRgb(30, 30, 255) + "Text with a blue background")

func CursorCol

func CursorCol(col int) string

Move cursor to {col} Ex: fmt.Print(ansi.CursorCol(10))

func CursorDownN

func CursorDownN(line int) string

Move cursor {line} down Ex: fmt.Print(ansi.CursorDown(10))

func CursorLeftN

func CursorLeftN(col int) string

Move cursor {col} left Ex: fmt.Print(ansi.CursorLeft(10))

func CursorMove

func CursorMove(x, y int) string

Move cursor to {col}, {line} Ex: fmt.Print(ansi.CursorMove(10,20))

func CursorRightN

func CursorRightN(col int) string

Move cursor {col} right Ex: fmt.Print(ansi.CursorRight(10))

func CursorUpN

func CursorUpN(line int) string

Move cursor {line} up Ex: fmt.Print(ansi.CursorUp(10))

func Fg256

func Fg256(color uint8) string

256 Foreground Color Ex: fmt.Println(ansi.Fg256(27) + "Blue text")

func FgRgb

func FgRgb(red, green, blue uint8) string

RGB Foreground Color Ex: fmt.Println(ansi.FgRgb(30, 30, 255) + "Blue text")

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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