Documentation ¶
Overview ¶
This document demonstrates the working of tint: a minimal bare-bone version of terminal styling implemented for Go applications with no external dependencies. It provides you with different types of functions that you can use to style your terminal output with ease.
Tint was originally created to use in the 'orbpkg' project: https://github.com/orbpkg/orb and uses near to 0ms for processing color expressions: https://godoc.org/github.com/printzero/tint/#Tint.Exp. Although the time taken to process is directly propotional to the number of characters in the string input.
Example ¶
package main import ( "tint" ) func main() { // Initialize tint t := tint.Init() // prints output in red t.Println("This output is red", tint.Red) }
Output:
Example (Attributes) ¶
This example demonstrates how attributes are defined in colors and when and how to use those attributes. As of `v0.0.2`tint has 5 attributes: Dim, Bold, Italic, Underline, Strike (strikethrough) These attributes are functions that are exposed over the color struct.
package main import ( "tint" ) func main() { // create pointer to Tint t := tint.Init() // Dim attribute t.Println("Dim sentence.", tint.Yellow.Dim()) // Bold attribute t.Println("Bold sentence.", tint.Yellow.Bold()) // Italic attribute t.Println("Italic sentence.", tint.Yellow.Italic()) // Underline attribute t.Println("Underlined sentence.", tint.Yellow.Underline()) // Strike attribute t.Println("Strikeout sentence.", tint.Yellow.Strike()) }
Output:
Example (Difference) ¶
This example demonstrates how colors are accessed differently than tint functions.
package main import ( "tint" ) func main() { // create pointer to Tint t := tint.Init() // Notice: how Raw function is accessed through pointer created by Init() // Notice: how color Yellow are accessed, they are static variables defined inside tint module // so you don't have to create any instance of a color t.Println("This output is red", tint.Yellow) }
Output:
Index ¶
- Variables
- type TerminalLevel
- type Tint
- func (t *Tint) Exp(expStr string, colors ...color) string
- func (t *Tint) Log(text string, colors ...color)
- func (t *Tint) Print(text string, colors ...color)
- func (t *Tint) Println(text string, colors ...color)
- func (t *Tint) Raw(text string, colors ...color) string
- func (t *Tint) Swatch(colors ...color) func(text string)
- func (t *Tint) SwatchRaw(colors ...color) func(text string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var BgBlack = color{ // contains filtered or unexported fields }
BgBlack applies Black Background color
var BgBlue = color{ // contains filtered or unexported fields }
BgBlue applies Blue Background color
var BgCyan = color{ // contains filtered or unexported fields }
BgCyan applies Cyan Background color
var BgGreen = color{ // contains filtered or unexported fields }
BgGreen applies Green Background color
var BgLightGrey = color{ // contains filtered or unexported fields }
BgLightGrey applies Light Grey Background color
var BgMagenta = color{ // contains filtered or unexported fields }
BgMagenta applies Magenta Background color
var BgRed = color{ // contains filtered or unexported fields }
BgRed applies Red Background color
var BgWhite = color{ // contains filtered or unexported fields }
BgWhite applies White Background color
var BgYellow = color{ // contains filtered or unexported fields }
BgYellow applies Yellow Background color
var Black = color{ // contains filtered or unexported fields }
Black color
var Blue = color{ // contains filtered or unexported fields }
Blue color
var Cyan = color{ // contains filtered or unexported fields }
Cyan color
var Green = color{ // contains filtered or unexported fields }
Green color
var Magenta = color{ // contains filtered or unexported fields }
Magenta color
var Normal = color{ // contains filtered or unexported fields }
Normal equates to no style
var Red = color{ // contains filtered or unexported fields }
Red color
var White = color{ // contains filtered or unexported fields }
White color
var Yellow = color{ // contains filtered or unexported fields }
Yellow color
Functions ¶
This section is empty.
Types ¶
type TerminalLevel ¶
type TerminalLevel int
TerminalLevel of color support for terminal and information of current terminal that is useful to tint.
const ( // LevelNone for terminal that supports no colot LevelNone TerminalLevel = iota + 1 // Level16bit for terminal that supports 16bit colors Level16bit // Level256 for terminal that supports 256 bit colors Level256 // Level16m for terminal that supports 16 million colors (truecolor) Level16m )
type Tint ¶
type Tint struct { Level TerminalLevel SupportsColor bool LogInstance *log.Logger }
Tint struct holds the whole library
func Init ¶
func Init() *Tint
Init initializes variables that tint uses and then returns the pointer to a Tint struct
func (*Tint) Exp ¶
Exp returns a string constructed from a series of color expressions given as an argument. The colors are passed as a replacement to each word that is wrapped around `@()`.
The string "@(Hello), @(World)!" where 'Hello' is inside a tint color expression and 'World' inside another, 'Hello' will get replaced by the first color and 'World' will get replaced by the second color passed inside this function.
Take a look at the below example.
Example ¶
package main import ( "fmt" "tint" ) func main() { // Initialize tint t := tint.Init() coloredString := t.Exp("@(Hello), @(World)!", tint.White.Bold(), tint.Blue) fmt.Println(coloredString) }
Output:
func (*Tint) Raw ¶
Raw returns the raw string with applied colors
Example ¶
package main import ( "fmt" "tint" ) func main() { // Initialize tint t := tint.Init() // get a colored string to be used as terminal output output := t.Raw("Rejoice fellow gopher, your test cases have passed.", tint.Green) // use it anywhere as input - fmt, log ... fmt.Println(output) }
Output: