This repository has been archived on 2021-08-10. You can view files and clone it, but cannot push or open issues or pull requests.
gtools/colour/colour.go

154 lines
4.1 KiB
Go

package colour
import (
"fmt"
"os"
"strings"
)
// Base Colours
const (
FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"
)
// Text Attributes
const (
Reset = "\x1b[0m"
Bold = "\x1b[1m"
Underscore = "\x1b[4m"
Reverse = "\x1b[7m"
Hidden = "\x1b[8m"
)
// BlackTitle Printf with bold black
func BlackTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgBlack+format+Reset, a...)
}
// RedTitle Printf with bold red
func RedTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgRed+format+Reset, a...)
}
// GreenTitle Printf with bold green
func GreenTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgGreen+format+Reset, a...)
}
// YellowTitle Printf with bold yellow
func YellowTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgYellow+format+Reset, a...)
}
// BlueTitle Printf with bold blue
func BlueTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgBlue+format+Reset, a...)
}
// MagentaTitle Printf with bold magenta
func MagentaTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgMagenta+format+Reset, a...)
}
// CyanTitle Printf with bold cyan
func CyanTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgCyan+format+Reset, a...)
}
// WhiteTitle Printf with bold white
func WhiteTitle(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, Bold+FgWhite+format+Reset, a...)
}
// Black Printf with the colour black
func Black(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgBlack+format+Reset, a...)
}
// Red Printf with the colour red
func Red(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgRed+format+Reset, a...)
}
// Green Printf with the colour green
func Green(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgGreen+format+Reset, a...)
}
// Yellow Printf with the colour yellow
func Yellow(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgYellow+format+Reset, a...)
}
// Blue Printf with the blue
func Blue(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgBlue+format+Reset, a...)
}
// Magenta Printf with the magenta
func Magenta(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgMagenta+format+Reset, a...)
}
// Cyan Printf with the cyan
func Cyan(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgCyan+format+Reset, a...)
}
// White Printf with the white
func White(format string, a ...interface{}) (n int, err error) {
return fmt.Fprintf(os.Stdout, FgWhite+format+Reset, a...)
}
// String formats string with coloured text
func String(format string, value ...string) string {
return strings.Join(value, "") + format + Reset
}
// BlackString formats string with black text
func BlackString(format string) string {
return String(format, FgBlack)
}
// RedString formats string with red text
func RedString(format string) string {
return String(format, FgRed)
}
// GreenString formats string with green text
func GreenString(format string) string {
return String(format, FgGreen)
}
// YellowString formats string with yellow text
func YellowString(format string) string {
return String(format, FgYellow)
}
// BlueString formats string with blue text
func BlueString(format string) string {
return String(format, FgBlue)
}
// MagentaString formats string with magenta text
func MagentaString(format string) string {
return String(format, FgMagenta)
}
// CyanString formats string with cyan text
func CyanString(format string) string {
return String(format, FgCyan)
}
// WhiteString formats string with white text
func WhiteString(format string) string {
return String(format, FgWhite)
}