ansi

package
v1.20210815.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 6 Imported by: 6

Documentation

Overview

Package ansi contains helpers for working with ansi colors.

These colors are used by the terminal.

Index

Constants

View Source
const (
	TableTopLeft     = "┌"
	TableTopRight    = "┐"
	TableBottomLeft  = "└"
	TableBottomRight = "┘"
	TableMidLeft     = "├"
	TableMidRight    = "┤"
	TableVertBar     = "│"
	TableHorizBar    = "─"
	TableTopSep      = "┬"
	TableBottomSep   = "┴"
	TableMidSep      = "┼"
	NewLine          = "\n"
)

Table character constants.

View Source
const (
	ColorReset = "\033[0m"
)

Utility Color Codes

Variables

This section is empty.

Functions

func Apply

func Apply(colorCode Color, text string) string

Apply applies a given color.

func Black

func Black(text string) string

Black applies a given color.

func Blue

func Blue(text string) string

Blue applies a given color.

func Bold

func Bold(colorCode Color, text string) string

Bold applies a given color as bold.

func Cyan

func Cyan(text string) string

Cyan applies a given color.

func Green

func Green(text string) string

Green applies a given color.

func LightBlack

func LightBlack(text string) string

LightBlack applies a given color.

func LightBlue

func LightBlue(text string) string

LightBlue applies a given color.

func LightCyan

func LightCyan(text string) string

LightCyan applies a given color.

func LightGreen

func LightGreen(text string) string

LightGreen applies a given color.

func LightPurple

func LightPurple(text string) string

LightPurple applies a given color.

func LightRed

func LightRed(text string) string

LightRed applies a given color.

func LightWhite

func LightWhite(text string) string

LightWhite applies a given color.

func LightYellow

func LightYellow(text string) string

LightYellow applies a given color.

func Purple

func Purple(text string) string

Purple applies a given color.

func Red

func Red(text string) string

Red applies a given color.

func Table

func Table(wr io.Writer, columns []string, rows [][]string) (err error)

Table writes a table to a given writer.

func TableForSlice

func TableForSlice(wr io.Writer, collection interface{}) error

TableForSlice prints a table for a given slice. It will infer column names from the struct fields. If it is a mixed array (i.e. []interface{}) it will probably panic.

func Underline

func Underline(colorCode Color, text string) string

Underline applies a given color as underline.

func White

func White(text string) string

White applies a given color.

func Yellow

func Yellow(text string) string

Yellow applies a given color.

Types

type Color

type Color string

Color represents an ansi color code fragment.

const (
	ColorBlack  Color = "30m"
	ColorRed    Color = "31m"
	ColorGreen  Color = "32m"
	ColorYellow Color = "33m"
	ColorBlue   Color = "34m"
	ColorPurple Color = "35m"
	ColorCyan   Color = "36m"
	ColorWhite  Color = "37m"
)

Color codes

const (
	ColorLightBlack  Color = "90m"
	ColorLightRed    Color = "91m"
	ColorLightGreen  Color = "92m"
	ColorLightYellow Color = "93m"
	ColorLightBlue   Color = "94m"
	ColorLightPurple Color = "95m"
	ColorLightCyan   Color = "96m"
	ColorLightWhite  Color = "97m"
)

BrightColorCodes

const (
	ColorBackgroundBlack  Color = "40m"
	ColorBackgroundRed    Color = "41m"
	ColorBackgroundGreen  Color = "42m"
	ColorBackgroundYellow Color = "43m"
	ColorBackgroundBlue   Color = "44m"
	ColorBackgroundPurple Color = "45m"
	ColorBackgroundCyan   Color = "46m"
	ColorBackgroundWhite  Color = "47m"
)

BackgroundColorCodes

const (
	ColorBackgroundBrightBlack  Color = "100m"
	ColorBackgroundBrightRed    Color = "101m"
	ColorBackgroundBrightGreen  Color = "102m"
	ColorBackgroundBrightYellow Color = "103m"
	ColorBackgroundBrightBlue   Color = "104m"
	ColorBackgroundBrightPurple Color = "105m"
	ColorBackgroundBrightCyan   Color = "106m"
	ColorBackgroundBrightWhite  Color = "107m"
)

BackgroundColorCodes

func (Color) Apply

func (c Color) Apply(text string) string

Apply applies a color to a given string.

func (Color) Bold

func (c Color) Bold() string

Bold escapes the color for use in the terminal as a bold color.

func (Color) Normal

func (c Color) Normal() string

Normal escapes the color for use in the terminal.

func (Color) Underline

func (c Color) Underline() string

Underline escapes the color for use in the terminal as underlined color.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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