ansi

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: MIT Imports: 8 Imported by: 3

README

go-ansi

Version

import "mpldr.codes/ansi"

Write pretty terminal output the easy way.

Want your text green? ansi.Green("I am Shrek")

Want it black on a red ground? ansi.RedBG(ansi.Black("You can just combine them"))

Moving around is as simple as Specifying direction ansi.Up()

ANSI Support

  • movement
  • line operations (clearing lines)
  • fore- and background colour
  • formatting (bold, italic, strikethrough, …)
  • stripping ANSI-Codes
  • hyperlinks (WIP)

User Choice

This library implements the (informal) NO_COLOR standard. This disables all colour-related ANSI-Codes but does not restrict any other function (like cursor movement or formatting). If this behavior is unwanted please stay on version 1.3.0 or below.

License

This library is licensed under the MIT License which can be found here.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UnsetBlue func() string = UnsetBlack

UnsetBlue resets the foreground color from blue to default.

View Source
var UnsetBlueBG func() string = UnsetBlackBG

UnsetBlueBG resets the background color from blue to default.

View Source
var UnsetColor256 func() string = UnsetBlack

UnsetColor256 resets the color

View Source
var UnsetColor256BG func() string = UnsetBlackBG

UnsetColor256BG resets the background color

View Source
var UnsetColorTrue func() string = UnsetBlack

UnsetColorTrue removes the RGB-color

View Source
var UnsetColorTrueBG func() string = UnsetBlackBG

UnsetColorTrueBG removes the RGB-background

View Source
var UnsetCyan func() string = UnsetBlack

UnsetCyan resets the foreground color from cyan to default.

View Source
var UnsetCyanBG func() string = UnsetBlackBG

UnsetCyanBG resets the background color from cyan to default.

View Source
var UnsetGreen func() string = UnsetBlack

UnsetGreen resets the foreground color from green to default.

View Source
var UnsetGreenBG func() string = UnsetBlackBG

UnsetGreenBG resets the background color from green to default.

View Source
var UnsetMagenta func() string = UnsetBlack

UnsetMagenta resets the foreground color from magenta to default.

View Source
var UnsetMagentaBG func() string = UnsetBlackBG

UnsetMagentaBG resets the background color from magenta to default.

View Source
var UnsetRed func() string = UnsetBlack

UnsetRed resets the foreground color from red to default.

View Source
var UnsetRedBG func() string = UnsetBlackBG

UnsetRedBG resets the background color from red to default.

View Source
var UnsetWhite func() string = UnsetBlack

UnsetWhite resets the foreground color from white to default.

View Source
var UnsetWhiteBG func() string = UnsetBlackBG

UnsetWhiteBG resets the background color from white to default.

View Source
var UnsetYellow func() string = UnsetBlack

UnsetYellow resets the foreground color from yellow to default.

View Source
var UnsetYellowBG func() string = UnsetBlackBG

UnsetYellowBG resets the background color from yellow to default.

Functions

func Black

func Black(content ...interface{}) string

Black wraps the content in ANSI codes to make its foreground color black

func BlackBG

func BlackBG(content ...interface{}) string

BlackBG wraps the content in ANSI codes to make its background color black

func Blink(content ...interface{}) string

Blink is equivalent to SetBlink() + content + UnsetBlink(), content will thereby blink.

func Blue

func Blue(content ...interface{}) string

Blue wraps the content in ANSI codes to make its foreground color blue

func BlueBG

func BlueBG(content ...interface{}) string

BlueBG wraps the content in ANSI codes to make its background color blue

func Bold

func Bold(content ...interface{}) string

Bold is equivalent to SetBold() + content + UnsetBold(), content will thereby be printed in bold.

func ClearBegin

func ClearBegin() string

ClearBegin clears the entire screen to (0;0)

func ClearEnd

func ClearEnd() string

ClearEnd clears to the end of the screen

func ClearLeft

func ClearLeft() string

ClearLeft clears all characters left of the cursor from the display

func ClearLine

func ClearLine() string

ClearLine clears all characters on the line

func ClearRight

func ClearRight() string

ClearRight clears all characters right of the cursor from the display

func ClearScreen

func ClearScreen() string

ClearScreen clears the entire screen and moves the cursor to (0;0)

func ClearScreenBuffer

func ClearScreenBuffer() string

ClearScreenBuffer clears the entire screen and the screenbuffer

func Color256

func Color256(color int, content ...interface{}) string

Color256 sets a Term256 color that is applied to the provided text

func Color256BG

func Color256BG(color int, content ...interface{}) string

Color256BG sets a Term256 color that is applied to the provided text as the background color

func ColorTrue

func ColorTrue(r, g, b int, content ...interface{}) string

ColorTrue sets a RGB-Color that is set as the background color, writes the

func ColorTrueBG

func ColorTrueBG(r, g, b int, content ...interface{}) string

ColorTrueBG sets a RGB-Color that is set as the background color, writes the text and clears the background color

func Conceal

func Conceal(content ...interface{}) string

Conceal is equivalent to SetConceal() + content + UnsetConceal(), content will thereby be displayed as spaces. It will still be visible if written to a file

func Cyan

func Cyan(content ...interface{}) string

Cyan wraps the content in ANSI codes to make its foreground color cyan

func CyanBG

func CyanBG(content ...interface{}) string

CyanBG wraps the content in ANSI codes to make its background color cyan

func DoubleUnderscore

func DoubleUnderscore(content ...interface{}) string

DoubleUnderscore is equivalent to SetDoubleUnderscore() + content + UnsetDoubleUnderscore(), content will thereby be double-underscored.

func Down

func Down() string

Down moves the cursor down one row

func DownX

func DownX(x int) string

DownX moves the cursor down x rows

func EnableANSI

func EnableANSI()

EnableANSI allows windows terminals to also enjoy the beauty of formatted output. This is not in the init function to prevent messing with the users environment. On other OSes this function does absolutely nothing but does still exist to allow easy cross-platform development. If you are on any OS other than Windows and your Terminal does not support ANSI Sequences I'd reccomend you get a normal terminal emulator.

func Faint

func Faint(content ...interface{}) string

Faint is equivalent to SetFaint() + content + UnsetFaint(), content will thereby be printed in a less intense color.

func FastBlink(content ...interface{}) string

FastBlink is equivalent to SetFastBlink() + content + UnsetFastBlink(), content will thereby blink fast.

func Font

func Font(font int, content ...interface{}) string

Font applies the specified fontface to the text

func Fraktur

func Fraktur(content ...interface{}) string

Fraktur is equivalent to SetFraktur() + content + UnsetFraktur(), content will thereby be printed in Frakturschrift. This is very rarely support.

func GetLengthWithoutCodes

func GetLengthWithoutCodes(content string) int

func Green

func Green(content ...interface{}) string

Green wraps the content in ANSI codes to make its foreground color green

func GreenBG

func GreenBG(content ...interface{}) string

GreenBG wraps the content in ANSI codes to make its background color green

func Italic

func Italic(content ...interface{}) string

Italic is equivalent to SetItalic() + content + UnsetItalic(), content will thereby be italic.

func Left

func Left() string

Left moves the cursor Left one row. As far as I am aware the correct term is "backward". Please be wary of potential implications in RTL context.

func LeftX

func LeftX(x int) string

LeftX moves the cursor Left x rows. As far as I am aware the correct term is "backward". Please be wary of potential implications in RTL context.

func Link(target url.URL, text string) string

Link creates a terminal Hyperlink that can be clicked, if the terminal emulator supports it.

func LinkFile

func LinkFile(file string, label string) string

func LinkString

func LinkString(target string, text string) string

func Magenta

func Magenta(content ...interface{}) string

Magenta wraps the content in ANSI codes to make its foreground color magenta

func MagentaBG

func MagentaBG(content ...interface{}) string

MagentaBG wraps the content in ANSI codes to make its background color magenta

func MoveCursor

func MoveCursor(x, y int) string

MoveCursor moves the cursor to position (x;y)

func OverrideNoColor

func OverrideNoColor()

OverrideNoColor allows re-enabling color codes if the user explicitly enabled it by means of a configuration entry or commandline flag.

func Red

func Red(content ...interface{}) string

Red wraps the content in ANSI codes to make its foreground color red

func RedBG

func RedBG(content ...interface{}) string

RedBG wraps the content in ANSI codes to make its background color red

func Reset

func Reset() string

Reset clears all colors and styles (bold, underscore, blink, concealed)

func RestorePos

func RestorePos() string

RestorePos restores the cursor position from the void. (see SavePos for more)

func ReverseVideo

func ReverseVideo(content ...interface{}) string

ReverseVideo is equivalent to SetReverseVideo() + content + UnsetReverseVideo(), content will thereby be inverted. This means that the background color and the foreground color will be switched.

func Right() string

Right moves the cursor right one row. As far as I am aware the correct term is "forward". Please be wary of potential implications in RTL context.

func RightX

func RightX(x int) string

RightX moves the cursor right x rows. As far as I am aware the correct term is "forward". Please be wary of potential implications in RTL context.

func SavePos

func SavePos() string

SavePos stores the current cursor position god knows where to allow restoring it.

func SetBlack

func SetBlack() string

SetBlack sets the foreground color to black

func SetBlackBG

func SetBlackBG() string

SetBlackBG sets the background color to black

func SetBlink() string

SetBlink makes the following text blink

func SetBlue

func SetBlue() string

SetBlue sets the foreground color to blue

func SetBlueBG

func SetBlueBG() string

SetBlueBG sets the background color to blue

func SetBold

func SetBold() string

SetBold makes the following text become bold

func SetColor256

func SetColor256(color int) string

SetColor256 writes the following text on the specified term256 color

func SetColor256BG

func SetColor256BG(color int) string

SetColor256BG writes the following text on the specified background color

func SetColorTrue

func SetColorTrue(r, g, b int) string

SetColorTrue sets a RGB-Color for the font

func SetColorTrueBG

func SetColorTrueBG(r, g, b int) string

SetColorTrueBG sets a RGB-Color for the background

func SetConceal

func SetConceal() string

SetConceal conceals the following text

func SetCyan

func SetCyan() string

SetCyan sets the foreground color to cyan

func SetCyanBG

func SetCyanBG() string

SetCyanBG sets the background color to cyan

func SetDoubleUnderscore

func SetDoubleUnderscore() string

SetDoubleUnderscore makes the following text become underscored

func SetFaint

func SetFaint() string

SetFaint makes the color of the following text less bright

func SetFastBlink() string

SetFastBlink makes the following text blink fast

func SetFont

func SetFont(font int) string

SetFont starts a block written in the specified font

func SetFraktur

func SetFraktur() string

SetFraktur makes the following text be printed printed in Frakturschrift

func SetGreen

func SetGreen() string

SetGreen sets the foreground color to green

func SetGreenBG

func SetGreenBG() string

SetGreenBG sets the background color to green

func SetItalic

func SetItalic() string

SetItalic makes the text following text become italic

func SetMagenta

func SetMagenta() string

SetMagenta sets the foreground color to magenta

func SetMagentaBG

func SetMagentaBG() string

SetMagentaBG sets the background color to magenta

func SetRed

func SetRed() string

SetRed sets the foreground color to red

func SetRedBG

func SetRedBG() string

SetRedBG sets the background color to red

func SetReverseVideo

func SetReverseVideo() string

SetReverseVideo makes the following text become inverted.

func SetStrikethrough

func SetStrikethrough() string

SetStrikethrough makes the following text crossed out

func SetUnderscore

func SetUnderscore() string

SetUnderscore makes the text following become underlined

func SetWhite

func SetWhite() string

SetWhite sets the foreground color to white

func SetWhiteBG

func SetWhiteBG() string

SetWhiteBG sets the background color to white

func SetYellow

func SetYellow() string

SetYellow sets the foreground color to yellow

func SetYellowBG

func SetYellowBG() string

SetYellowBG sets the background color to yellow

func Strikethrough

func Strikethrough(content ...interface{}) string

Strikethrough is equivalent to SetStrikethrough() + content + UnsetStrikethrough(), content will thereby be displayed as crossed out

func StripString

func StripString(str string) string

StripString removes all ANSI-Escape sequences from the given string and returns the cleaned version

func Underscore

func Underscore(content ...interface{}) string

Underscore is equivalent to SetUnderscore() + content + UnsetUnderscore(), content will thereby be underscored.

func UnsetBlack

func UnsetBlack() string

UnsetBlack resets the foreground color from black to default.

func UnsetBlackBG

func UnsetBlackBG() string

UnsetBlackBG resets the background color from black to default.

func UnsetBlink() string

UnsetBlink stops the text from blinking

func UnsetBold

func UnsetBold() string

UnsetBold removes the bold property

func UnsetConceal

func UnsetConceal() string

UnsetConceal removes the concealed property

func UnsetDoubleUnderscore

func UnsetDoubleUnderscore() string

UnsetDoubleUnderscore removes the double-underscore attribute

func UnsetFaint

func UnsetFaint() string

UnsetFaint removes the faint property

func UnsetFastBlink() string

UnsetFastBlink stops the text from blinking fast

func UnsetFont

func UnsetFont() string

UnsetFont resets the fontface back to the default

func UnsetFraktur

func UnsetFraktur() string

UnsetFraktur resets the font to the default

func UnsetItalic

func UnsetItalic() string

UnsetItalic removes the italic property

func UnsetReverseVideo

func UnsetReverseVideo() string

UnsetReverseVideo disables the inversion

func UnsetStrikethrough

func UnsetStrikethrough() string

UnsetStrikethrough removes the strikethrough property

func UnsetUnderscore

func UnsetUnderscore() string

UnsetUnderscore removes the underscore property

func Up

func Up() string

Up moves the cursor up one row

func UpX

func UpX(x int) string

UpX moves the cursor up x rows

func White

func White(content ...interface{}) string

White wraps the content in ANSI codes to make its foreground color white

func WhiteBG

func WhiteBG(content ...interface{}) string

WhiteBG wraps the content in ANSI codes to make its background color white

func Yellow

func Yellow(content ...interface{}) string

Yellow wraps the content in ANSI codes to make its foreground color yellow

func YellowBG

func YellowBG(content ...interface{}) string

YellowBG wraps the content in ANSI codes to make its background color yellow

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