Documentation ¶
Overview ¶
Package Colorify is a simple but straightforward attempt to create a stdout colorification/beautification module. Its based on a very simple premise of creating a simple set of colored and formatted output, only the io.Writer/os.stdout intrerfaces. Implementation is inspired by fatih/color package which is by all means a more feature rich and mature project. This is just a very simple re-implementation of the same.
Package colorify is an ANSI color package to output colorized or SGR defined output to the standard output. Quickstart on ways to use this:
// Init colorify with color palette in struct. import "github.com/mainak90/colorify" red := colorify.Colorify{Color: colorify.Red, Attr: colorify.Underline} yellow := colorify.Colorify{Color: colorify.Yellow, Attr: colorify.Regular} // Start the init function redPrint := red.New() yellowPrint := yellow.New() // Use various fmt package interfaces to output in colour redPrint.Println("This", "is", "Sparta") yellowPrint.Println("This is yellow regular!!!") fmt.Println(yellowPrint.Sprintf("Sprintf message")) io.WriteString(os.Stdout, yellowPrint.Sprintln("This", "is", "Sparta")) redPrint.Printf("%s", "This", "is", "a", "word") // Colors supported Red, Green, Yellow, Blue, Purple, Cyan, White // Formatting attributes supported Bold, Italics, Underline, Reverse, Strikethrough
Help furnish this package with more add-on features.
Index ¶
- Constants
- Variables
- func Done() string
- type Attr
- type Color
- type Colorify
- func (c *Colorify) Fprint(w io.Writer, msg ...interface{}) (n int, err error)
- func (c *Colorify) Fprintf(w io.Writer, format string, msg ...interface{}) (n int, err error)
- func (c *Colorify) Fprintln(w io.Writer, msg ...interface{}) (n int, err error)
- func (c *Colorify) Printf(format string, msg ...interface{}) (n int, err error)
- func (c *Colorify) Println(msg ...interface{}) (n int, err error)
- func (c *Colorify) Sprintf(msg ...interface{}) string
- func (c *Colorify) Sprintln(msg ...interface{}) string
Constants ¶
const Base = "\033["
Base const for the base str __repr__ for colors.
Variables ¶
var ( Reset Color = "0m" Red Color = "31m" Green Color = "32m" Yellow Color = "33m" Blue Color = "34m" Purple Color = "35m" Cyan Color = "36m" Gray Color = "37m" White Color = "97m" Bold Attr = "1;" Transparent Attr = "2;" Italics Attr = "3;" Underline Attr = "4;" Reverse Attr = "7;" Strikethrough Attr = "9;" Regular Attr = "0;" )
Color str __repr__ vars for each supported colors.
Functions ¶
Types ¶
type Attr ¶
type Attr string
Custom type Attr stores the string attributes for the colored output. Typically Bold and Underlines are typical attributes.
type Colorify ¶
Main struct for interfacing with all golang fmt functions. Elems --> 1. Color --> The colored o/p choice. 2. Attr --> Added string attributes like bold/underline etc 3. NoColour --> Automatically set attribute which disables coloration if not o/p to tty 4. ColorScheme --> The string __repr__ of the generated color scheme.
func (*Colorify) Fprint ¶
Fprint: Implements the fmt.Fprint interface just with the colorification addon.
func (*Colorify) Fprintf ¶
Fprintf: Implements the fmt.Fprintf interface just with the colorification addon.
func (*Colorify) Fprintln ¶
Fprintln: Implements the fmt.Fprintln interface just with the colorification addon.
func (*Colorify) Printf ¶
Printf: Implements the fmt.Printf interface just with the colorification addon.