Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Black = "" K = "" Red = "" R = "" Green = "" G = "" Yellow = "" Y = "" Blue = "" B = "" Magenta = "" M = "" Cyan = "" C = "" White = "" W = "" Reset = "" X = "" Clear = "" CurOn = "" CurOff = "" )
Functions ¶
func RandomColor ¶
RandomColor returns a random color ANSI escape between Black (30) and White (37)
Example (Interactive) ¶
package main
import (
"fmt"
"strings"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
string := C.RandomColor(true)
colorAdded := strings.HasPrefix(string, "\x1b[3")
fmt.Println(colorAdded)
}
Output: true
Example (Noninteractive) ¶
package main
import (
"fmt"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
fmt.Printf("%q\n", C.RandomColor())
}
Output: ""
func SetColor ¶
func SetColor()
SetColor will place the color ANSI escape characters in place of the empty strings. Allowing color to be used.
Example (Interactive) ¶
package main
import (
"fmt"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
C.SetColor()
fmt.Printf("%q\n", C.Black+"black"+C.Reset)
fmt.Printf("%q\n", C.Red+"red"+C.Reset)
fmt.Printf("%q\n", C.Green+"green"+C.Reset)
fmt.Printf("%q\n", C.Yellow+"yellow"+C.Reset)
fmt.Printf("%q\n", C.Blue+"blue"+C.Reset)
fmt.Printf("%q\n", C.Magenta+"magenta"+C.Reset)
fmt.Printf("%q\n", C.Cyan+"cyan"+C.Reset)
fmt.Printf("%q\n", C.White+"white"+C.Reset)
}
Output: "\x1b[30mblack\x1b[0m" "\x1b[31mred\x1b[0m" "\x1b[32mgreen\x1b[0m" "\x1b[33myellow\x1b[0m" "\x1b[34mblue\x1b[0m" "\x1b[35mmagenta\x1b[0m" "\x1b[36mcyan\x1b[0m" "\x1b[37mwhite\x1b[0m"
Example (Noninteractive) ¶
package main
import (
"fmt"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
fmt.Printf("%q\n", C.Black+"black"+C.Reset)
fmt.Printf("%q\n", C.Red+"red"+C.Reset)
fmt.Printf("%q\n", C.Green+"green"+C.Reset)
fmt.Printf("%q\n", C.Yellow+"yellow"+C.Reset)
fmt.Printf("%q\n", C.Blue+"blue"+C.Reset)
fmt.Printf("%q\n", C.Magenta+"magenta"+C.Reset)
fmt.Printf("%q\n", C.Cyan+"cyan"+C.Reset)
fmt.Printf("%q\n", C.White+"white"+C.Reset)
}
Output: "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"
Example (Shortcutinteractive) ¶
package main
import (
"fmt"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
fmt.Printf("%q\n", C.K+"black"+C.X)
fmt.Printf("%q\n", C.R+"red"+C.X)
fmt.Printf("%q\n", C.G+"green"+C.X)
fmt.Printf("%q\n", C.Y+"yellow"+C.X)
fmt.Printf("%q\n", C.B+"blue"+C.X)
fmt.Printf("%q\n", C.M+"magenta"+C.X)
fmt.Printf("%q\n", C.C+"cyan"+C.X)
fmt.Printf("%q\n", C.W+"white"+C.X)
}
Output: "\x1b[30mblack\x1b[0m" "\x1b[31mred\x1b[0m" "\x1b[32mgreen\x1b[0m" "\x1b[33myellow\x1b[0m" "\x1b[34mblue\x1b[0m" "\x1b[35mmagenta\x1b[0m" "\x1b[36mcyan\x1b[0m" "\x1b[37mwhite\x1b[0m"
Example (Shortcutnoninteractive) ¶
package main
import (
"fmt"
C "github.com/ScriptAlchemist/go-termcolor"
)
func main() {
fmt.Printf("%q\n", C.K+"black"+C.X)
fmt.Printf("%q\n", C.R+"red"+C.X)
fmt.Printf("%q\n", C.G+"green"+C.X)
fmt.Printf("%q\n", C.Y+"yellow"+C.X)
fmt.Printf("%q\n", C.B+"blue"+C.X)
fmt.Printf("%q\n", C.M+"magenta"+C.X)
fmt.Printf("%q\n", C.C+"cyan"+C.X)
fmt.Printf("%q\n", C.W+"white"+C.X)
}
Output: "black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.