ansi

package module
v2.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2018 License: MIT Imports: 0 Imported by: 20

README

ansi

Project status GoDoc License

ansi contains a bunch of constants and possibly additional terminal related functionality in the future.

Why another ANSI library?

I already had the ANSI escape sequences the way I want them, but was repeating the same code in multiple projects and so created this to stop that; it solves nothing new.

Installation

Use go get

go get -u github.com/go-playground/ansi

Usage

package main

import (
	"fmt"

	"github.com/go-playground/ansi"
)

// make your own combinations if you want
const blinkRed = ansi.Red + ansi.Blink + ansi.Underline

func main() {

	// Foreground
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.GrayBackground, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Gray, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.DarkGray, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Red, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightRed, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Green, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightGreen, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Yellow, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightYellow, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Blue, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightBlue, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Magenta, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightMagenta, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Cyan, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.LightCyan, "testing foreground", ansi.Reset)
	fmt.Printf("%s%s%s\n\n", ansi.White, "testing foreground", ansi.Reset)

	// Background
	fmt.Printf("%s%s%s\n", ansi.Gray+ansi.BlackBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.RedBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.GreenBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.YellowBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.BlueBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.MagentaBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n", ansi.Black+ansi.CyanBackground, "testing background", ansi.Reset)
	fmt.Printf("%s%s%s\n\n", ansi.Black+ansi.GrayBackground, "testing background", ansi.Reset)

	// Inverse
	fmt.Printf("%s%s%s\n\n", ansi.Inverse, "testing inverse", ansi.InverseOff)

	// Italics
	fmt.Printf("%s%s%s\n\n", ansi.Italics, "testing italics", ansi.ItalicsOff)

	// Underline
	fmt.Printf("%s%s%s\n\n", ansi.Underline, "testing underline", ansi.UnderlineOff)

	// Blink
	fmt.Printf("%s%s%s\n\n", ansi.Blink, "testing blink", ansi.BlinkOff)

	// Bold
	fmt.Printf("%s%s%s %s\n\n", ansi.Bold, "testing bold", ansi.BoldOff, "and normal strings")

	// Custom combination
	fmt.Printf("%s%s%s\n", blinkRed, "blink red underline", ansi.Reset)
}

Licenses

Documentation

Index

Constants

View Source
const (
	Reset             EscSeq = "\x1b[0m"
	Italics                  = "\x1b[3m"
	Underline                = "\x1b[4m"
	Blink                    = "\x1b[5m"
	Inverse                  = "\x1b[7m"
	ItalicsOff               = "\x1b[23m"
	UnderlineOff             = "\x1b[24m"
	BlinkOff                 = "\x1b[25m"
	InverseOff               = "\x1b[27m"
	Black                    = "\x1b[30m"
	DarkGray                 = "\x1b[30;1m"
	Red                      = "\x1b[31m"
	LightRed                 = "\x1b[31;1m"
	Green                    = "\x1b[32m"
	LightGreen               = "\x1b[32;1m"
	Yellow                   = "\x1b[33m"
	LightYellow              = "\x1b[33;1m"
	Blue                     = "\x1b[34m"
	LightBlue                = "\x1b[34;1m"
	Magenta                  = "\x1b[35m"
	LightMagenta             = "\x1b[35;1m"
	Cyan                     = "\x1b[36m"
	LightCyan                = "\x1b[36;1m"
	Gray                     = "\x1b[37m"
	White                    = "\x1b[37;1m"
	ResetForeground          = "\x1b[39m"
	BlackBackground          = "\x1b[40m"
	RedBackground            = "\x1b[41m"
	GreenBackground          = "\x1b[42m"
	YellowBackground         = "\x1b[43m"
	BlueBackground           = "\x1b[44m"
	MagentaBackground        = "\x1b[45m"
	CyanBackground           = "\x1b[46m"
	GrayBackground           = "\x1b[47m"
	ResetBackground          = "\x1b[49m"
	Bold                     = "\x1b[1m"
	BoldOff                  = "\x1b[22m"
)

ANSI escape sequences NOTE: in a standard xterm terminal the light colors will appear BOLD instead of the light variant

Variables

This section is empty.

Functions

This section is empty.

Types

type EscSeq

type EscSeq string

EscSeq is a predefined ANSI escape sequence

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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