colour

package module
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: MIT Imports: 6 Imported by: 10

README

Colour terminal text for Go (Golang) Build Status

Package colour provides Quake-style colour formatting for Unix terminals.

The package level functions can be used to write to stdout (or strings or other files). If stdout is not a terminal, colour formatting will be stripped.

eg.

colour.Printf("^0black ^1red ^2green ^3yellow ^4blue ^5magenta ^6cyan ^7white^R\n")

For more control a Printer object can be created with various helper functions. This can be used to do useful things such as strip formatting, write to strings, and so on.

The following sequences are converted to their equivalent ANSI colours:

Sequence Effect
^0 Black
^1 Red
^2 Green
^3 Yellow
^4 Blue
^5 Cyan (light blue)
^6 Magenta (purple)
^7 White
^8 Black Background
^9 Red Background
^a Green Background
^b Yellow Background
^c Blue Background
^d Cyan (light blue) Background
^e Magenta (purple) Background
^f White Background
^R Reset
^U Underline
^D Dim
^B Bold
^S Strikethrough

Documentation

Overview

Package colour ([docs][1]) provides [Quake-style colour formatting][2] for Unix terminals.

It is a drop-in replacement for the fmt package.

The package level functions can be used to write to stdout (or strings or other files). If stdout is not a terminal, colour formatting will be stripped.

eg.

colour.Printf("^0black ^1red ^2green ^3yellow ^4blue ^5magenta ^6cyan ^7white^R\n")

For more control a Printer object can be created with various helper functions. This can be used to do useful things such as strip formatting, write to strings, and so on.

The following sequences are converted to their equivalent ANSI colours:

^0 = Black
^1 = Red
^2 = Green
^3 = Yellow
^4 = Blue
^5 = Cyan (light blue)
^6 = Magenta (purple)
^7 = White
^8 = Black Background
^9 = Red Background
^a = Green Background
^b = Yellow Background
^c = Blue Background
^d = Cyan (light blue) Background
^e = Magenta (purple) Background
^f = White Background
^R = Reset
^U = Underline
^B = Bold
^S = Strikethrough

[1]: http://godoc.org/github.com/alecthomas/colour [2]: http://www.holysh1t.net/quake-live-colors-nickname/

Index

Constants

This section is empty.

Variables

View Source
var (

	// Stdout is an conditional colour writer for os.Stdout.
	Stdout = TTY(os.Stdout)
	// Stderr is an conditional colour writer for os.Stderr.
	Stderr = TTY(os.Stderr)
)

Functions

func FormatString

func FormatString(s string) string

func Fprint

func Fprint(w io.Writer, args ...interface{}) (n int, err error)

func Fprintf

func Fprintf(w io.Writer, format string, args ...interface{}) (n int, err error)

func Fprintln

func Fprintln(w io.Writer, args ...interface{}) (n int, err error)

func Print

func Print(args ...interface{}) (n int, err error)

func Printf

func Printf(format string, args ...interface{}) (n int, err error)

func Println

func Println(args ...interface{}) (n int, err error)

func Sprint

func Sprint(args ...interface{}) string

func Sprintf

func Sprintf(format string, args ...interface{}) string

func Sprintln

func Sprintln(args ...interface{}) string

func StripFormatting

func StripFormatting(s string) string

Types

type Printer

type Printer interface {
	Println(args ...interface{}) (n int, err error)
	Print(args ...interface{}) (n int, err error)
	Printf(format string, args ...interface{}) (n int, err error)
}

A Printer implements functions that accept Quake-style colour formatting and print coloured text.

func Colour

func Colour(w io.Writer) Printer

Colour creats a new ANSI colour Printer on w.

func Strip

func Strip(w io.Writer) Printer

Strip returns a Printer that strips all colour codes from printed strings before writing to w.

func TTY

func TTY(w io.Writer) Printer

TTY creates a Printer that colourises output if w is a terminal, or strips formatting if it is not.

type StringPrinter

type StringPrinter struct {
	Printer
	// contains filtered or unexported fields
}

func String

func String() *StringPrinter

String creates a new Printer that writes ANSI coloured text to a buffer. Use the String() method to return the printed string.

func StringStripper

func StringStripper() *StringPrinter

StringStripper writes text stripped of colour formatting codes to a string. Use the String() method to return the printed string.

func (*StringPrinter) String

func (s *StringPrinter) String() string

Source Files

Jump to

Keyboard shortcuts

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