color: github.com/gookit/color Index | Examples | Files | Directories

package color

import "github.com/gookit/color"

Package color is Command line color library. Support rich color rendering output, universal API method, compatible with Windows system

Source code and other details for the project are available at GitHub:

https://github.com/gookit/color

More usage please see README and tests.

Code:

package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "os"
    "runtime"
    "syscall"
    "testing"

    "github.com/stretchr/testify/assert"
)

func main() {
    // quick use like fmt.Print*
    Red.Println("Simple to use color")
    Green.Print("Simple to use color")
    Cyan.Printf("Simple to use %s\n", "color")
    Gray.Printf("Simple to use %s\n", "color")
    Blue.Printf("Simple to use %s\n", "color")
    Yellow.Printf("Simple to use %s\n", "color")
    Magenta.Printf("Simple to use %s\n", "color")

    // use like func
    red := FgRed.Render
    green := FgGreen.Render
    fmt.Printf("%s line %s library\n", red("Command"), green("color"))

    // custom color
    New(FgWhite, BgBlack).Println("custom color style")

    // can also:
    Style{FgCyan, OpBold}.Println("custom color style")

    // internal theme/style:
    Info.Tips("message")
    Info.Prompt("message")
    Info.Println("info message")
    Warn.Println("warning message")
    Error.Println("error message")
    Danger.Println("danger message")

    // use style tag
    Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")

    // apply a style tag
    Tag("info").Println("info style text")

    // prompt message
    Info.Prompt("prompt style message")
    Warn.Prompt("prompt style message")

    // tips message
    Info.Tips("tips style message")
    Warn.Tips("tips style message")
}

/*************************************************************
 * test global methods
 *************************************************************/

func TestSet(t *testing.T) {
    is := assert.New(t)

    // disable color
    old := Enable
    Disable()
    num, err := Set(FgGreen)
    is.Nil(err)
    is.Equal(0, num)

    num, err = Reset()
    is.Nil(err)
    is.Equal(0, num)
    Enable = old

    if runtime.GOOS == "windows" {
        return
    }

    // set
    testSetFunc(t)
}

func TestSet_OnWindows(t *testing.T) {
    if runtime.GOOS != "windows" {
        return
    }

    // set
    fd := uintptr(syscall.Stdout)

    // if run test by goland, will return false
    if IsTerminal(int(fd)) {
        testSetFunc(t)
    }
}

func testSetFunc(t *testing.T) {
    is := assert.New(t)

    // set
    rewriteStdout()
    num, err := Set(FgGreen)
    str := restoreStdout()

    is.True(num > 0)
    is.NoError(err)
    if isLikeInCmd {
        is.Equal("", str)
    } else {
        is.Equal("\x1b[32m", str)
    }
    _, _ = Reset()

    // unset
    rewriteStdout()
    _, err = Reset()
    str = restoreStdout()
    is.NoError(err)
    if isLikeInCmd {
        is.Equal("", str)
    } else {
        is.Equal("\x1b[0m", str)
    }

    if isLikeInCmd {
        // set
        rewriteStdout()
        _, err = Set(FgGreen)
        str = restoreStdout()
        is.NoError(err)
        is.Equal("", str)

        // unset
        rewriteStdout()
        _, err = Reset()
        str = restoreStdout()
        is.NoError(err)
        is.Equal("", str)
    }
}

func TestRenderCode(t *testing.T) {
    // force open color render for testing
    oldVal = ForceOpenColor()
    defer resetColorRender()

    is := assert.New(t)

    str := RenderCode("36;1", "Hi,", "babe")
    is.Equal("\x1b[36;1mHi,babe\x1b[0m", str)

    str = RenderWithSpaces("", "Hi,", "babe")
    is.Equal("Hi, babe", str)

    str = RenderWithSpaces("36;1", "Hi,", "babe")
    is.Equal("\x1b[36;1mHi, babe\x1b[0m", str)

    str = RenderCode("36;1", "Ab")
    is.Equal("\x1b[36;1mAb\x1b[0m", str)

    str = RenderCode("36;1")
    is.Equal("", str)

    Disable()
    str = RenderCode("36;1", "Te", "xt")
    is.Equal("Text", str)

    str = RenderWithSpaces("36;1", "Te", "xt")
    is.Equal("Te xt", str)
    Enable = true

    // RenderString
    str = RenderString("36;1", "Text")
    is.Equal("\x1b[36;1mText\x1b[0m", str)
    str = RenderString("", "Text")
    is.Equal("Text", str)
    str = RenderString("36;1", "")
    is.Equal("", str)

    Disable()
    str = RenderString("36;1", "Text")
    is.Equal("Text", str)
    Enable = true

    Disable()
    str = RenderString("36;1", "Text")
    is.Equal("Text", str)
    Enable = true
}

func TestClearCode(t *testing.T) {
    art := assert.New(t)
    art.Equal("Text", ClearCode("\033[36;1mText\x1b[0m"))
    // 8bit
    art.Equal("Text", ClearCode("\x1b[38;5;242mText\x1b[0m"))
    // 24bit
    art.Equal("Text", ClearCode("\x1b[38;2;30;144;255mText\x1b[0m"))
    art.Equal("Text other", ClearCode("\033[36;1mText\x1b[0m other"))
}

/*************************************************************
 * test printer
 *************************************************************/

func TestPrinter(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()
    at := assert.New(t)

    p := NewPrinter("48;5;132")

    // Color256.Sprint
    str := p.Sprint("msg")
    at.Equal("\x1b[48;5;132mmsg\x1b[0m", str)
    // Color256.Sprintf
    str = p.Sprintf("msg")
    at.Equal("\x1b[48;5;132mmsg\x1b[0m", str)

    at.False(p.IsEmpty())
    at.Equal("48;5;132", p.String())

    // Color256.Print
    p.Print("MSG")
    str = buf.String()
    buf.Reset()
    at.Equal("\x1b[48;5;132mMSG\x1b[0m", str)

    // Color256.Printf
    p.Printf("A %s", "MSG")
    str = buf.String()
    buf.Reset()
    at.Equal("\x1b[48;5;132mA MSG\x1b[0m", str)

    // Color256.Println
    p.Println("MSG")
    str = buf.String()
    buf.Reset()
    at.Equal("\x1b[48;5;132mMSG\x1b[0m\n", str)
}

/*************************************************************
 * test 16 color
 *************************************************************/

func TestColor16(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()
    at := assert.New(t)

    at.True(Bold.IsValid())
    r := Bold.Render("text")
    at.Equal("\x1b[1mtext\x1b[0m", r)
    r = LightYellow.Text("text")
    at.Equal("\x1b[93mtext\x1b[0m", r)
    r = LightWhite.Sprint("text")
    at.Equal("\x1b[97mtext\x1b[0m", r)
    r = White.Render("test", "spaces")
    at.Equal("\x1b[37mtestspaces\x1b[0m", r)
    r = Black.Renderln("test", "spaces")
    at.Equal("\x1b[30mtest spaces\x1b[0m", r)

    str := Red.Sprintf("A %s", "MSG")
    at.Equal("\x1b[31mA MSG\x1b[0m", str)

    // Color.Print
    FgGray.Print("MSG")
    str = buf.String()
    if isLikeInCmd {
        at.Equal("MSG", str)
    } else {
        at.Equal("\x1b[90mMSG\x1b[0m", str)
    }
    buf.Reset()

    // Color.Printf
    BgGray.Printf("A %s", "MSG")
    str = buf.String()
    if isLikeInCmd {
        at.Equal("A MSG", str)
    } else {
        at.Equal("\x1b[100mA MSG\x1b[0m", str)
    }
    buf.Reset()

    // Color.Println
    LightMagenta.Println("MSG")
    str = buf.String()
    if isLikeInCmd {
        at.Equal("MSG\n", str)
    } else {
        at.Equal("\x1b[95mMSG\x1b[0m\n", str)
    }
    buf.Reset()

    LightMagenta.Println()
    str = buf.String()
    at.Equal("\n", str)
    buf.Reset()

    if isLikeInCmd {
        LightCyan.Print("msg")
        LightRed.Printf("m%s", "sg")
        LightGreen.Println("msg")
        str = buf.String()
        at.Equal("msgmsgmsg\n", str)
        buf.Reset()
    }

    // Color.Darken
    blue := LightBlue.Darken()
    at.Equal(94, int(LightBlue))
    at.Equal(34, int(blue))
    c := Color(120).Darken()
    at.Equal(120, int(c))

    // Color.Light
    lightCyan := Cyan.Light()
    at.Equal(36, int(Cyan))
    at.Equal(96, int(lightCyan))
    c = Color(120).Light()
    at.Equal(120, int(c))

    // Colors vars
    _, ok := FgColors["red"]
    at.True(ok)
    _, ok = ExFgColors["lightRed"]
    at.True(ok)
    _, ok = BgColors["red"]
    at.True(ok)
    _, ok = ExBgColors["lightRed"]
    at.True(ok)
}

/*************************************************************
 * test 256 color
 *************************************************************/

func TestColor256(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()

    is := assert.New(t)

    // empty
    c := Color256{1: 99}
    is.True(c.IsEmpty())
    is.Equal("", c.String())

    // fg
    c = Bit8(132)
    is.False(c.IsEmpty())
    is.Equal(uint8(132), c.Value())
    is.Equal("38;5;132", c.String())

    // Color256.Sprint
    str := c.Sprint("msg")
    is.Equal("\x1b[38;5;132mmsg\x1b[0m", str)
    // Color256.Sprintf
    str = c.Sprintf("msg")
    is.Equal("\x1b[38;5;132mmsg\x1b[0m", str)

    // bg
    c = Bit8(132, true)
    is.False(c.IsEmpty())
    is.Equal("48;5;132", c.String())

    c = C256(132)
    // Color256.Print
    c.Print("MSG")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mMSG\x1b[0m", str)

    // Color256.Printf
    c.Printf("A %s", "MSG")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mA MSG\x1b[0m", str)

    // Color256.Println
    c.Println("MSG", "TEXT")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mMSG TEXT\x1b[0m\n", str)
}

func TestStyle256(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()

    is := assert.New(t)
    // empty
    s := S256()
    is.Equal("", s.String())
    is.Equal("MSG", s.Sprint("MSG"))

    // only fg
    s = S256(132)
    is.Equal("38;5;132", s.String())
    is.Equal("\x1b[38;5;132mMSG\x1b[0m", s.Sprint("MSG"))
    is.Equal("\x1b[38;5;132mMSG\x1b[0m", s.Sprintf("%s", "MSG"))

    // only bg
    s = S256(132)
    is.Equal("38;5;132", s.String())
    is.Equal("\x1b[38;5;132mMSG\x1b[0m", s.Sprint("MSG"))

    // fg and bg
    s = S256(132, 23)
    is.Equal("38;5;132;48;5;23", s.String())
    is.Equal("\x1b[38;5;132;48;5;23mMSG\x1b[0m", s.Sprint("MSG"))
    s = S256().Set(132, 23)
    is.Equal("38;5;132;48;5;23", s.String())
    is.Equal("\x1b[38;5;132;48;5;23mMSG\x1b[0m", s.Sprint("MSG"))
    s = S256().SetFg(132).SetBg(23)
    is.Equal("38;5;132;48;5;23", s.String())
    is.Equal("\x1b[38;5;132;48;5;23mMSG\x1b[0m", s.Sprint("MSG"))

    s = S256(132)

    // Color256.Print
    s.Print("MSG")
    str := buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mMSG\x1b[0m", str)

    // Color256.Printf
    s.Printf("A %s", "MSG")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mA MSG\x1b[0m", str)

    // Color256.Println
    s.Println("MSG")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;5;132mMSG\x1b[0m\n", str)
}

/*************************************************************
 * test rgb color
 *************************************************************/

func TestRGBColor(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()
    is := assert.New(t)

    // empty
    c := RGBColor{3: 99}
    is.True(c.IsEmpty())
    is.Equal("", c.String())

    // bg
    c = RGB(204, 204, 204, true)
    is.False(c.IsEmpty())
    is.Equal("48;2;204;204;204", c.String())

    // fg
    c = RGB(204, 204, 204)
    is.False(c.IsEmpty())
    is.Equal("38;2;204;204;204", c.String())

    // RGBColor.Sprint
    str := c.Sprint("msg")
    is.Equal("\x1b[38;2;204;204;204mmsg\x1b[0m", str)

    // RGBColor.Sprintf
    str = c.Sprintf("msg")
    is.Equal("\x1b[38;2;204;204;204mmsg\x1b[0m", str)
    is.Equal("[204 204 204]", fmt.Sprint(c.Values()))

    // RGBColor.Print
    c.Print("msg")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;2;204;204;204mmsg\x1b[0m", str)

    // RGBColor.Printf
    c.Printf("m%s", "sg")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;2;204;204;204mmsg\x1b[0m", str)

    // RGBColor.Println
    c.Println("msg")
    str = buf.String()
    buf.Reset()
    is.Equal("\x1b[38;2;204;204;204mmsg\x1b[0m\n", str)
}

func TestRGBFromString(t *testing.T) {
    forceOpenColorRender()
    defer resetColorRender()
    is := assert.New(t)

    c := RGBFromString("170,187,204")
    is.Equal("\x1b[38;2;170;187;204mmsg\x1b[0m", c.Sprint("msg"))

    c = RGBFromString("170,187,204", true)
    is.Equal("\x1b[48;2;170;187;204mmsg\x1b[0m", c.Sprint("msg"))

    c = RGBFromString("170,187,")
    is.Equal("msg", c.Sprint("msg"))

    c = RGBFromString("")
    is.Equal("msg", c.Sprint("msg"))

    c = RGBFromString("170,187,error")
    is.Equal("msg", c.Sprint("msg"))
}

func TestHexToRGB(t *testing.T) {
    is := assert.New(t)
    c := HEX("ccc") // rgb: [204 204 204]
    is.False(c.IsEmpty())
    is.Equal("38;2;204;204;204", c.String())

    c = HEX("aabbcc") // rgb: [170 187 204]
    is.Equal("38;2;170;187;204", c.String())

    c = HEX("#aabbcc") // rgb: [170 187 204]
    is.Equal("38;2;170;187;204", c.String())

    c = HEX("0xad99c0") // rgb: [170 187 204]
    is.Equal("38;2;173;153;192", c.String())

    c = HEX(" ")
    is.True(c.IsEmpty())
    is.Equal("", c.String())

    c = HEX("!#$bbcc")
    is.Equal("", c.String())

    c = HEX("#invalid")
    is.Equal("", c.String())

    c = HEX("invalid code")
    is.Equal("", c.String())
}

func TestRGBStyle(t *testing.T) {
    buf := forceOpenColorRender()
    defer resetColorRender()
    at := assert.New(t)

    s := &RGBStyle{}
    at.True(s.IsEmpty())
    at.Equal("", s.String())
    s.Set(RGB(20, 144, 234), RGB(234, 78, 23))
    at.False(s.IsEmpty())
    at.Equal("38;2;20;144;234;48;2;234;78;23", s.String())

    // NewRGBStyle
    s = NewRGBStyle(RGB(20, 144, 234))
    at.False(s.IsEmpty())
    at.Equal("38;2;20;144;234", s.String())

    s = NewRGBStyle(RGB(20, 144, 234), RGB(234, 78, 23))
    at.False(s.IsEmpty())
    at.Equal("38;2;20;144;234;48;2;234;78;23", s.String())

    // HEXStyle
    s = HEXStyle("555", "eee")
    at.False(s.IsEmpty())
    at.Equal("38;2;85;85;85;48;2;238;238;238", s.String())

    // RGBStyleFromString
    s = RGBStyleFromString("20, 144, 234", "234, 78, 23")
    at.False(s.IsEmpty())
    at.Equal("38;2;20;144;234;48;2;234;78;23", s.String())

    // RGBColor.Sprint
    at.Equal("\x1b[38;2;20;144;234;48;2;234;78;23mmsg\x1b[0m", s.Sprint("msg"))
    // RGBColor.Sprintf
    at.Equal("\x1b[38;2;20;144;234;48;2;234;78;23mmsg\x1b[0m", s.Sprintf("m%s", "sg"))

    // RGBColor.Print
    s.Print("msg")
    str := buf.String()
    buf.Reset()
    at.Equal("\x1b[38;2;20;144;234;48;2;234;78;23mmsg\x1b[0m", str)

    // RGBColor.Printf
    s.Printf("m%s", "sg")
    str = buf.String()
    buf.Reset()
    at.Equal("\x1b[38;2;20;144;234;48;2;234;78;23mmsg\x1b[0m", str)

    // RGBColor.Println
    s.Println("msg")
    str = buf.String()
    buf.Reset()
    at.Equal("\x1b[38;2;20;144;234;48;2;234;78;23mmsg\x1b[0m\n", str)
}

func TestOther(t *testing.T) {
    is := assert.New(t)

    is.True(IsConsole(os.Stdout))
    is.False(IsConsole(&bytes.Buffer{}))

    // IsMSys
    oldVal := os.Getenv("MSYSTEM")
    is.NoError(os.Setenv("MSYSTEM", "MINGW64"))
    is.True(IsMSys())
    is.NoError(os.Unsetenv("MSYSTEM"))
    is.False(IsMSys())
    _ = os.Setenv("MSYSTEM", oldVal)

    // IsSupport256Color
    oldVal = os.Getenv("TERM")
    _ = os.Unsetenv("TERM")
    is.False(IsSupportColor())
    is.False(IsSupport256Color())

    // ConEmuANSI
    mockEnvValue("ConEmuANSI", "ON", func(_ string) {
        is.True(IsSupportColor())
    })

    // ANSICON
    mockEnvValue("ANSICON", "189x2000 (189x43)", func(_ string) {
        is.True(IsSupportColor())
    })

    // "COLORTERM=truecolor"
    mockEnvValue("COLORTERM", "truecolor", func(_ string) {
        is.True(IsSupportTrueColor())
    })

    // TERM
    mockEnvValue("TERM", "screen-256color", func(_ string) {
        is.True(IsSupportColor())
    })

    // TERM
    mockEnvValue("TERM", "tmux-256color", func(_ string) {
        is.True(IsSupportColor())
    })

    // TERM
    mockEnvValue("TERM", "rxvt-unicode-256color", func(_ string) {
        is.True(IsSupportColor())
    })

    is.NoError(os.Setenv("TERM", "xterm-vt220"))
    is.True(IsSupportColor())
    // revert
    if oldVal != "" {
        is.NoError(os.Setenv("TERM", oldVal))
    } else {
        is.NoError(os.Unsetenv("TERM"))
    }
}

/*************************************************************
 * test helpers
 *************************************************************/

var oldVal bool

// force open color render for testing
func forceOpenColorRender() *bytes.Buffer {
    oldVal = isSupportColor
    isSupportColor = true

    // set output for test
    buf := new(bytes.Buffer)
    SetOutput(buf)

    return buf
}

func resetColorRender() {
    isSupportColor = oldVal
    // reset
    ResetOutput()
}

var oldStdout, newReader *os.File

// Usage:
// rewriteStdout()
// fmt.Println("Hello, playground")
// msg := restoreStdout()
func rewriteStdout() {
    oldStdout = os.Stdout
    r, w, _ := os.Pipe()
    newReader = r
    os.Stdout = w
}

func restoreStdout() string {
    if newReader == nil {
        return ""
    }

    // Notice: must close writer before read data
    // close now writer
    _ = os.Stdout.Close()
    // restore
    os.Stdout = oldStdout
    oldStdout = nil

    // read data
    out, _ := ioutil.ReadAll(newReader)

    // close reader
    _ = newReader.Close()
    newReader = nil

    return string(out)
}

// mockEnvValue will store old env value, set new val. will restore old value on end.
func mockEnvValue(key, val string, fn func(nv string)) {
    old := os.Getenv(key)
    err := os.Setenv(key, val)
    if err != nil {
        panic(err)
    }

    fn(os.Getenv(key))

    // if old is empty, unset key.
    if old == "" {
        err = os.Unsetenv(key)
    } else {
        err = os.Setenv(key, old)
    }
    if err != nil {
        panic(err)
    }
}

Index

Examples

Package Files

color.go color_16.go color_256.go color_nonwin.go color_rgb.go style.go tag.go utils.go

Constants

const (
    SettingTpl   = "\x1b[%sm"
    FullColorTpl = "\x1b[%sm%s\x1b[0m"
)

color render templates ESC 操作的表示:

"\033"(Octal 8进制) = "\x1b"(Hexadecimal 16进制) = 27 (10进制)
const (
    Red     = FgRed
    Cyan    = FgCyan
    Gray    = FgDarkGray // is light Black
    Blue    = FgBlue
    Black   = FgBlack
    Green   = FgGreen
    White   = FgWhite
    Yellow  = FgYellow
    Magenta = FgMagenta

    Bold   = OpBold
    Normal = FgDefault

    LightRed     = FgLightRed
    LightCyan    = FgLightCyan
    LightBlue    = FgLightBlue
    LightGreen   = FgLightGreen
    LightWhite   = FgLightWhite
    LightYellow  = FgLightYellow
    LightMagenta = FgLightMagenta
)

There are basic and light foreground color aliases

const (
    TplFg256 = "38;5;%d"
    TplBg256 = "48;5;%d"
)

tpl for 8 bit 256 color(`2^8`)

format:

	ESC[ … 38;5;<n> … m // 选择前景色
 ESC[ … 48;5;<n> … m // 选择背景色

example:

fg "\x1b[38;5;242m"
bg "\x1b[48;5;208m"
both "\x1b[38;5;242;48;5;208m"

links:

https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8
const (
    TplFgRGB = "38;2;%d;%d;%d"
    TplBgRGB = "48;2;%d;%d;%d"
)

24 bit RGB color RGB:

R 0-255 G 0-255 B 0-255
R 00-FF G 00-FF B 00-FF (16进制)

Format:

ESC[ … 38;2;<r>;<g>;<b> … m // 选择RGB前景色
ESC[ … 48;2;<r>;<g>;<b> … m // 选择RGB背景色

links:

https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#24

example:

fg: \x1b[38;2;30;144;255mMESSAGE\x1b[0m
bg: \x1b[48;2;30;144;255mMESSAGE\x1b[0m
both: \x1b[38;2;233;90;203;48;2;30;144;255mMESSAGE\x1b[0m
const (
    AsFg uint8 = iota
    AsBg
)

mark color is fg or bg.

const (
    // MatchExpr regex to match color tags
    // Notice: golang 不支持反向引用.  即不支持使用 \1 引用第一个匹配 ([a-z=;]+)
    // MatchExpr = `<([a-z=;]+)>(.*?)<\/\1>`
    // 所以调整一下 统一使用 `</>` 来结束标签,例如 "<info>some text</>"
    // 支持自定义颜色属性的tag "<fg=white;bg=blue;op=bold>content</>"
    // (?s:...) s - 让 "." 匹配换行
    MatchExpr = `<([a-zA-Z_=,;]+)>(?s:(.*?))<\/>`

    // AttrExpr regex to match color attributes
    AttrExpr = `(fg|bg|op)[\s]*=[\s]*([a-zA-Z,]+);?`

    // StripExpr regex used for removing color tags
    // StripExpr = `<[\/]?[a-zA-Z=;]+>`
    // 随着上面的做一些调整
    StripExpr = `<[\/]?[a-zA-Z_=,;]*>`
)

output colored text like use html tag. (not support windows cmd)

const CodeExpr = `\033\[[\d;?]+m`

CodeExpr regex to clear color codes eg "\033[1;36mText\x1b[0m"

const ResetSet = "\x1b[0m"

ResetSet 重置/正常 关闭所有属性。

Variables

var (
    // Info color style
    Info = &Theme{"info", Style{OpReset, FgGreen}}
    // Note color style
    Note = &Theme{"note", Style{OpBold, FgLightCyan}}
    // Warn color style
    Warn = &Theme{"warning", Style{OpBold, FgYellow}}
    // Light color style
    Light = &Theme{"light", Style{FgLightWhite, BgBlack}}
    // Error color style
    Error = &Theme{"error", Style{FgLightWhite, BgRed}}
    // Danger color style
    Danger = &Theme{"danger", Style{OpBold, FgRed}}
    // Debug color style
    Debug = &Theme{"debug", Style{OpReset, FgCyan}}
    // Notice color style
    Notice = &Theme{"notice", Style{OpBold, FgCyan}}
    // Comment color style
    Comment = &Theme{"comment", Style{OpReset, FgLightYellow}}
    // Success color style
    Success = &Theme{"success", Style{OpBold, FgGreen}}
    // Primary color style
    Primary = &Theme{"primary", Style{OpReset, FgBlue}}
    // Question color style
    Question = &Theme{"question", Style{OpReset, FgMagenta}}
    // Secondary color style
    Secondary = &Theme{"secondary", Style{FgDarkGray}}
)

internal themes(like bootstrap style) Usage:

color.Info.Print("message")
color.Info.Printf("a %s message", "test")
color.Warn.Println("message")
color.Error.Println("message")
var BgColors = map[string]Color{
    "black":   BgBlack,
    "red":     BgRed,
    "green":   BgGreen,
    "yellow":  BgYellow,
    "blue":    BgBlue,
    "magenta": BgMagenta,
    "cyan":    BgCyan,
    "white":   BgWhite,
    "default": BgDefault,
}

BgColors background colors map

var (
    // Enable switch color display
    Enable = true
)
var ExBgColors = map[string]Color{
    "darkGray":     BgDarkGray,
    "lightRed":     BgLightRed,
    "lightGreen":   BgLightGreen,
    "lightYellow":  BgLightYellow,
    "lightBlue":    BgLightBlue,
    "lightMagenta": BgLightMagenta,
    "lightCyan":    BgLightCyan,
    "lightWhite":   BgLightWhite,
}

ExBgColors extra background colors map

var ExFgColors = map[string]Color{
    "darkGray":     FgDarkGray,
    "lightRed":     FgLightRed,
    "lightGreen":   FgLightGreen,
    "lightYellow":  FgLightYellow,
    "lightBlue":    FgLightBlue,
    "lightMagenta": FgLightMagenta,
    "lightCyan":    FgLightCyan,
    "lightWhite":   FgLightWhite,
}

ExFgColors extra foreground colors map

var FgColors = map[string]Color{
    "black":   FgBlack,
    "red":     FgRed,
    "green":   FgGreen,
    "yellow":  FgYellow,
    "blue":    FgBlue,
    "magenta": FgMagenta,
    "cyan":    FgCyan,
    "white":   FgWhite,
    "default": FgDefault,
}

FgColors foreground colors map

var Options = map[string]Color{
    "reset":      OpReset,
    "bold":       OpBold,
    "fuzzy":      OpFuzzy,
    "italic":     OpItalic,
    "underscore": OpUnderscore,
    "blink":      OpBlink,
    "reverse":    OpReverse,
    "concealed":  OpConcealed,
}

Options color options map

var Styles = map[string]Style{
    "info":  {OpReset, FgGreen},
    "note":  {OpBold, FgLightCyan},
    "light": {FgLightWhite, BgRed},
    "error": {FgLightWhite, BgRed},

    "danger":  {OpBold, FgRed},
    "notice":  {OpBold, FgCyan},
    "success": {OpBold, FgGreen},
    "comment": {OpReset, FgMagenta},
    "primary": {OpReset, FgBlue},
    "warning": {OpBold, FgYellow},

    "question":  {OpReset, FgMagenta},
    "secondary": {FgDarkGray},
}

Styles internal defined styles, like bootstrap styles. Usage:

color.Styles["info"].Println("message")
var Themes = map[string]*Theme{
    "info":  Info,
    "note":  Note,
    "light": Light,
    "error": Error,

    "debug":   Debug,
    "danger":  Danger,
    "notice":  Notice,
    "success": Success,
    "comment": Comment,
    "primary": Primary,
    "warning": Warn,

    "question":  Question,
    "secondary": Secondary,
}

Themes internal defined themes. Usage:

color.Themes["info"].Println("message")

func AddStyle Uses

func AddStyle(name string, s Style)

AddStyle add a style

func AddTheme Uses

func AddTheme(name string, style Style)

AddTheme add a theme and style

func ApplyTag Uses

func ApplyTag(tag string, a ...interface{}) string

ApplyTag for messages

func ClearCode Uses

func ClearCode(str string) string

ClearCode clear color codes. eg:

"\033[36;1mText\x1b[0m" -> "Text"

func ClearTag Uses

func ClearTag(s string) string

ClearTag clear all tag for a string

func Disable Uses

func Disable()

Disable disable color output

func ForceOpenColor Uses

func ForceOpenColor() bool

ForceOpenColor force open color render

func Fprint Uses

func Fprint(w io.Writer, a ...interface{})

Fprint print rendered messages to writer Notice: will ignore print error

func Fprintf Uses

func Fprintf(w io.Writer, format string, a ...interface{})

Fprintf print format and rendered messages to writer. Notice: will ignore print error

func Fprintln Uses

func Fprintln(w io.Writer, a ...interface{})

Fprintln print rendered messages line to writer Notice: will ignore print error

func GetColorTags Uses

func GetColorTags() map[string]string

GetColorTags get all internal color tags

func GetTagCode Uses

func GetTagCode(name string) string

GetTagCode get color code by tag name

func HexToRGB Uses

func HexToRGB(hex string) (rgb []int)

HexToRGB hex color string to RGB numbers Usage:

rgb := HexToRGB("ccc") // rgb: [204 204 204]
rgb := HexToRGB("aabbcc") // rgb: [170 187 204]
rgb := HexToRGB("#aabbcc") // rgb: [170 187 204]
rgb := HexToRGB("0xad99c0") // rgb: [170 187 204]

func IsConsole Uses

func IsConsole(out io.Writer) bool

IsConsole 判断 w 是否为 stderr、stdout、stdin 三者之一

func IsDefinedTag Uses

func IsDefinedTag(name string) bool

IsDefinedTag is defined tag name

func IsMSys Uses

func IsMSys() bool

IsMSys msys(MINGW64) 环境,不一定支持颜色

func IsSupport256Color Uses

func IsSupport256Color() bool

IsSupport256Color render

func IsSupportColor Uses

func IsSupportColor() bool

IsSupportColor check current console is support color.

Supported:

linux, mac, or windows's ConEmu, Cmder, putty, git-bash.exe

Not support:

windows cmd.exe, powerShell.exe

func IsSupportTrueColor Uses

func IsSupportTrueColor() bool

IsSupportTrueColor render. IsSupportRGBColor

func IsTerminal Uses

func IsTerminal(_ int) bool

IsTerminal check currently is terminal

func Lprint Uses

func Lprint(l *log.Logger, a ...interface{})

Lprint passes colored messages to a log.Logger for printing. Notice: should be goroutine safe

func ParseCodeFromAttr Uses

func ParseCodeFromAttr(attr string) (code string)

ParseCodeFromAttr parse color attributes. attr like:

"fg=VALUE;bg=VALUE;op=VALUE" // VALUE please see var: FgColors, BgColors, Options

eg:

"fg=yellow"
"bg=red"
"op=bold,underscore" option is allow multi value
"fg=white;bg=blue;op=bold"
"fg=white;op=bold,underscore"

func Print Uses

func Print(a ...interface{})

Print render color tag and print messages

func Printf Uses

func Printf(format string, a ...interface{})

Printf format and print messages

func Println Uses

func Println(a ...interface{})

Println messages with new line

func Render Uses

func Render(a ...interface{}) string

Render parse color tags, return rendered string. Usage:

text := Render("<info>hello</> <cyan>world</>!")
fmt.Println(text)

func RenderCode Uses

func RenderCode(code string, args ...interface{}) string

RenderCode render message by color code. Usage:

msg := RenderCode("3;32;45", "some", "message")

func RenderString Uses

func RenderString(code string, str string) string

RenderString render a string with color code. Usage:

msg := RenderString("3;32;45", "a message")

func RenderWithSpaces Uses

func RenderWithSpaces(code string, args ...interface{}) string

RenderWithSpaces Render code with spaces. If the number of args is > 1, a space will be added between the args

func ReplaceTag Uses

func ReplaceTag(str string) string

ReplaceTag parse string, replace color tag and return rendered string

func Reset Uses

func Reset() (int, error)

Reset reset console color attributes

func ResetOutput Uses

func ResetOutput()

ResetOutput reset output

func Set Uses

func Set(colors ...Color) (int, error)

Set set console color attributes

func SetOutput Uses

func SetOutput(w io.Writer)

SetOutput set default colored text output

func Sprint Uses

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

Sprint parse color tags, return rendered string

func Sprintf Uses

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

Sprintf format and return rendered string

func String Uses

func String(s string) string

String alias of the ReplaceTag

func Text Uses

func Text(s string) string

Text alias of the ReplaceTag

func WrapTag Uses

func WrapTag(s string, tag string) string

WrapTag wrap a tag for a string "<tag>content</>"

type Color Uses

type Color uint8

Color Color16, 16 color value type 3(2^3=8) OR 4(2^4=16) bite color.

const (
    FgBlack Color = iota + 30
    FgRed
    FgGreen
    FgYellow
    FgBlue
    FgMagenta // 品红
    FgCyan    // 青色
    FgWhite
    // FgDefault revert default FG
    FgDefault Color = 39
)

Foreground colors. basic foreground colors 30 - 37

const (
    FgDarkGray Color = iota + 90 // 亮黑(灰)
    FgLightRed
    FgLightGreen
    FgLightYellow
    FgLightBlue
    FgLightMagenta
    FgLightCyan
    FgLightWhite
    // FgGray is alias of FgDarkGray
    FgGray Color = 90 // 亮黑(灰)
)

Extra foreground color 90 - 97(非标准)

const (
    BgBlack Color = iota + 40
    BgRed
    BgGreen
    BgYellow // BgBrown like yellow
    BgBlue
    BgMagenta
    BgCyan
    BgWhite
    // BgDefault revert default BG
    BgDefault Color = 49
)

Background colors. basic background colors 40 - 47

const (
    BgDarkGray Color = iota + 99
    BgLightRed
    BgLightGreen
    BgLightYellow
    BgLightBlue
    BgLightMagenta
    BgLightCyan
    BgLightWhite
    // BgGray is alias of BgDarkGray
    BgGray Color = 100
)

Extra background color 100 - 107(非标准)

const (
    OpReset         Color = iota // 0 重置所有设置
    OpBold                       // 1 加粗
    OpFuzzy                      // 2 模糊(不是所有的终端仿真器都支持)
    OpItalic                     // 3 斜体(不是所有的终端仿真器都支持)
    OpUnderscore                 // 4 下划线
    OpBlink                      // 5 闪烁
    OpFastBlink                  // 5 快速闪烁(未广泛支持)
    OpReverse                    // 7 颠倒的 交换背景色与前景色
    OpConcealed                  // 8 隐匿的
    OpStrikethrough              // 9 删除的,删除线(未广泛支持)
)

Option settings

func (Color) Code Uses

func (c Color) Code() string

Code convert to code string. eg "35"

func (Color) Darken Uses

func (c Color) Darken() Color

Darken current color. eg. 96(FgLightCyan) -> 36(FgCyan) Usage:

cyan := LightCyan.Darken()
cyan.Print("message")

func (Color) IsValid Uses

func (c Color) IsValid() bool

IsValid color value

func (Color) Light Uses

func (c Color) Light() Color

Light current color. eg: 36(FgCyan) -> 96(FgLightCyan). Usage:

lightCyan := Cyan.Light()
lightCyan.Print("message")

func (Color) Print Uses

func (c Color) Print(args ...interface{})

Print messages. Usage:

color.Green.Print("message")

OR:

green := color.FgGreen.Print
green("message")

func (Color) Printf Uses

func (c Color) Printf(format string, a ...interface{})

Printf format and print messages. Usage:

color.Cyan.Printf("string %s", "arg0")

func (Color) Println Uses

func (c Color) Println(a ...interface{})

Println messages with new line

func (Color) Render Uses

func (c Color) Render(a ...interface{}) string

Render messages by color setting Usage:

green := color.FgGreen.Render
fmt.Println(green("message"))

func (Color) Renderln Uses

func (c Color) Renderln(a ...interface{}) string

Renderln messages by color setting. like Println, will add spaces for each argument Usage:

green := color.FgGreen.Renderln
fmt.Println(green("message"))

func (Color) Sprint Uses

func (c Color) Sprint(a ...interface{}) string

Sprint render messages by color setting. is alias of the Render()

func (Color) Sprintf Uses

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

Sprintf format and render message. Usage:

	green := color.Green.Sprintf
 colored := green("message")

func (Color) String Uses

func (c Color) String() string

String convert to code string. eg "35"

func (Color) Text Uses

func (c Color) Text(message string) string

Text render a text message

type Color256 Uses

type Color256 [2]uint8

Color256 256 (8 bit) color, uint8 range at 0 - 255

颜色值使用10进制和16进制都可 0x98 = 152

颜色有两位uint8组成:

0: color value
1: color type, Fg=0 Bg=1
>1: unset value

example:

	fg color: [152, 0]
 bg color: [152, 1]

NOTICE: now support 256 color on windows CMD, PowerShell

func Bit8 Uses

func Bit8(val uint8, isBg ...bool) Color256

Bit8 create a color256

func C256 Uses

func C256(val uint8, isBg ...bool) Color256

C256 create a color256

func (Color256) IsEmpty Uses

func (c Color256) IsEmpty() bool

IsEmpty value

func (Color256) Print Uses

func (c Color256) Print(a ...interface{})

Print print message

func (Color256) Printf Uses

func (c Color256) Printf(format string, a ...interface{})

Printf format and print message

func (Color256) Println Uses

func (c Color256) Println(a ...interface{})

Println print message with newline

func (Color256) Sprint Uses

func (c Color256) Sprint(a ...interface{}) string

Sprint returns rendered message

func (Color256) Sprintf Uses

func (c Color256) Sprintf(format string, a ...interface{}) string

Sprintf returns format and rendered message

func (Color256) String Uses

func (c Color256) String() string

String convert to color code string.

func (Color256) Value Uses

func (c Color256) Value() uint8

Value return color value

type Printer Uses

type Printer struct {
    // ColorCode color code string. eg "32;45;3"
    ColorCode string
}

Printer a generic color message printer. Usage:

p := &Printer{"32;45;3"}
p.Print("message")

func NewPrinter Uses

func NewPrinter(colorCode string) *Printer

NewPrinter instance

func (*Printer) IsEmpty Uses

func (p *Printer) IsEmpty() bool

IsEmpty color code

func (*Printer) Print Uses

func (p *Printer) Print(a ...interface{})

Print rendering colored messages

func (*Printer) Printf Uses

func (p *Printer) Printf(format string, a ...interface{})

Printf format and rendering colored messages

func (*Printer) Println Uses

func (p *Printer) Println(a ...interface{})

Println rendering colored messages with newline

func (*Printer) Sprint Uses

func (p *Printer) Sprint(a ...interface{}) string

Sprint returns rendering colored messages

func (*Printer) Sprintf Uses

func (p *Printer) Sprintf(format string, a ...interface{}) string

Sprintf returns format and rendering colored messages

func (*Printer) String Uses

func (p *Printer) String() string

String returns color code string. eg: "32;45;3"

type PrinterFace Uses

type PrinterFace interface {
    fmt.Stringer
    Sprint(a ...interface{}) string
    Sprintf(format string, a ...interface{}) string
    Print(a ...interface{})
    Printf(format string, a ...interface{})
    Println(a ...interface{})
}

PrinterFace interface

type RGBColor Uses

type RGBColor [4]uint8

RGBColor definition.

The first to third digits represent the color value. The last digit represents the foreground(0), background(1), >1 is unset value

Usage:

// 0, 1, 2 is R,G,B.
// 3th: Fg=0, Bg=1, >1: unset value
RGBColor{30,144,255, 0}
RGBColor{30,144,255, 1}

NOTICE: now support RGB color on windows CMD, PowerShell

func HEX Uses

func HEX(hex string, isBg ...bool) RGBColor

HEX create RGB color from a HEX color string. Usage:

c := HEX("ccc") // rgb: [204 204 204]
c := HEX("aabbcc") // rgb: [170 187 204]
c := HEX("#aabbcc")
c := HEX("0xaabbcc")
c.Print("message")

func RGB Uses

func RGB(r, g, b uint8, isBg ...bool) RGBColor

RGB color create. Usage:

c := RGB(30,144,255)
c := RGB(30,144,255, true)
c.Print("message")

func RGBFromString Uses

func RGBFromString(rgb string, isBg ...bool) RGBColor

RGBFromString create RGB color from a string. Usage:

c := RGBFromString("170,187,204")
c.Print("message")

func (RGBColor) Code Uses

func (c RGBColor) Code() string

Code to color code string

func (RGBColor) IsEmpty Uses

func (c RGBColor) IsEmpty() bool

IsEmpty value

func (RGBColor) Print Uses

func (c RGBColor) Print(a ...interface{})

Print print message

func (RGBColor) Printf Uses

func (c RGBColor) Printf(format string, a ...interface{})

Printf format and print message

func (RGBColor) Println Uses

func (c RGBColor) Println(a ...interface{})

Println print message with newline

func (RGBColor) Sprint Uses

func (c RGBColor) Sprint(a ...interface{}) string

Sprint returns rendered message

func (RGBColor) Sprintf Uses

func (c RGBColor) Sprintf(format string, a ...interface{}) string

Sprintf returns format and rendered message

func (RGBColor) String Uses

func (c RGBColor) String() string

String to color code string

func (RGBColor) Values Uses

func (c RGBColor) Values() []int

Values to RGB values

type RGBStyle Uses

type RGBStyle struct {
    // Name of the style
    Name string
    // contains filtered or unexported fields
}

RGBStyle definition.

前/背景色 都是由4位uint8组成, 前三位是色彩值; 最后一位与RGBColor不一样的是,在这里表示是否设置了值 1 表示已设置 ^1 未设置

func HEXStyle Uses

func HEXStyle(fg string, bg ...string) *RGBStyle

HEXStyle create a RGBStyle from HEX color string. Usage:

s := HEXStyle("aabbcc", "eee")
s.Print("message")

func NewRGBStyle Uses

func NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle

NewRGBStyle create a RGBStyle.

func RGBStyleFromString Uses

func RGBStyleFromString(fg string, bg ...string) *RGBStyle

RGBStyleFromString create a RGBStyle from color value string. Usage:

s := RGBStyleFromString("170,187,204", "70,87,4")
s.Print("message")

func (*RGBStyle) Code Uses

func (s *RGBStyle) Code() string

Code convert to color code string

func (*RGBStyle) IsEmpty Uses

func (s *RGBStyle) IsEmpty() bool

IsEmpty style

func (*RGBStyle) Print Uses

func (s *RGBStyle) Print(a ...interface{})

Print print message

func (*RGBStyle) Printf Uses

func (s *RGBStyle) Printf(format string, a ...interface{})

Printf format and print message

func (*RGBStyle) Println Uses

func (s *RGBStyle) Println(a ...interface{})

Println print message with newline

func (*RGBStyle) Set Uses

func (s *RGBStyle) Set(fg, bg RGBColor) *RGBStyle

Set fg and bg color

func (*RGBStyle) SetBg Uses

func (s *RGBStyle) SetBg(bg RGBColor) *RGBStyle

SetBg set bg color

func (*RGBStyle) SetFg Uses

func (s *RGBStyle) SetFg(fg RGBColor) *RGBStyle

SetFg set fg color

func (*RGBStyle) Sprint Uses

func (s *RGBStyle) Sprint(a ...interface{}) string

Sprint returns rendered message

func (*RGBStyle) Sprintf Uses

func (s *RGBStyle) Sprintf(format string, a ...interface{}) string

Sprintf returns format and rendered message

func (*RGBStyle) String Uses

func (s *RGBStyle) String() string

String convert to color code string

type Style Uses

type Style []Color

Style a 16 color style. can add: fg color, bg color, color options

Example:

color.Style{color.FgGreen}.Print("message")

func GetStyle Uses

func GetStyle(name string) Style

GetStyle get defined style by name

func New Uses

func New(colors ...Color) Style

New create a custom style

Usage:

color.New(color.FgGreen).Print("message")
equals to:
color.Style{color.FgGreen}.Print("message")

func (Style) Code Uses

func (s Style) Code() string

Code convert to code string. returns like "32;45;3"

func (Style) IsEmpty Uses

func (s Style) IsEmpty() bool

IsEmpty style

func (Style) Print Uses

func (s Style) Print(a ...interface{})

Print render and Print text

func (Style) Printf Uses

func (s Style) Printf(format string, a ...interface{})

Printf render and print text

func (Style) Println Uses

func (s Style) Println(a ...interface{})

Println render and print text line

func (Style) Render Uses

func (s Style) Render(a ...interface{}) string

Render render text Usage:

color.New(color.FgGreen).Render("text")
color.New(color.FgGreen, color.BgBlack, color.OpBold).Render("text")

func (Style) Renderln Uses

func (s Style) Renderln(a ...interface{}) string

Renderln render text line. like Println, will add spaces for each argument Usage:

color.New(color.FgGreen).Renderln("text", "more")
color.New(color.FgGreen, color.BgBlack, color.OpBold).Render("text", "more")

func (Style) Save Uses

func (s Style) Save(name string)

Save to styles map

func (Style) Sprint Uses

func (s Style) Sprint(a ...interface{}) string

Sprint is alias of the 'Render'

func (Style) Sprintf Uses

func (s Style) Sprintf(format string, a ...interface{}) string

Sprintf format and render message.

func (Style) String Uses

func (s Style) String() string

String convert to code string. returns like "32;45;3"

type Style256 Uses

type Style256 struct {

    // Name of the style
    Name string
    // contains filtered or unexported fields
}

Style256 definition

前/背景色 都是由两位uint8组成, 第一位是色彩值; 第二位与Bit8Color不一样的是,在这里表示是否设置了值 0 未设置 ^0 已设置

func S256 Uses

func S256(fgAndBg ...uint8) *Style256

S256 create a color256 style Usage:

s := color.S256()
s := color.S256(132) // fg
s := color.S256(132, 203) // fg and bg

func (*Style256) Code Uses

func (s *Style256) Code() string

Code convert to color code string

func (*Style256) Print Uses

func (s *Style256) Print(a ...interface{})

Print print message

func (*Style256) Printf Uses

func (s *Style256) Printf(format string, a ...interface{})

Printf format and print message

func (*Style256) Println Uses

func (s *Style256) Println(a ...interface{})

Println print message with newline

func (*Style256) Set Uses

func (s *Style256) Set(fgVal, bgVal uint8) *Style256

Set fg and bg color value

func (*Style256) SetBg Uses

func (s *Style256) SetBg(bgVal uint8) *Style256

SetBg set bg color value

func (*Style256) SetFg Uses

func (s *Style256) SetFg(fgVal uint8) *Style256

SetFg set fg color value

func (*Style256) Sprint Uses

func (s *Style256) Sprint(a ...interface{}) string

Sprint returns rendered message

func (*Style256) Sprintf Uses

func (s *Style256) Sprintf(format string, a ...interface{}) string

Sprintf returns format and rendered message

func (*Style256) String Uses

func (s *Style256) String() string

String convert to color code string

type Tag Uses

type Tag string

Tag value is a defined style name Usage:

Tag("info").Println("message")

func (Tag) Print Uses

func (tg Tag) Print(a ...interface{})

Print messages

func (Tag) Printf Uses

func (tg Tag) Printf(format string, a ...interface{})

Printf format and print messages

func (Tag) Println Uses

func (tg Tag) Println(a ...interface{})

Println messages line

func (Tag) Sprint Uses

func (tg Tag) Sprint(a ...interface{}) string

Sprint render messages

func (Tag) Sprintf Uses

func (tg Tag) Sprintf(format string, a ...interface{}) string

Sprintf format and render messages

type Theme Uses

type Theme struct {
    // Name theme name
    Name string
    // Style for the theme
    Style
}

Theme definition. extends from Style

func GetTheme Uses

func GetTheme(name string) *Theme

GetTheme get defined theme by name

func NewTheme Uses

func NewTheme(name string, style Style) *Theme

NewTheme instance

func (*Theme) Block Uses

func (t *Theme) Block(format string, a ...interface{})

Block like Prompt, but will wrap a empty line

func (*Theme) Prompt Uses

func (t *Theme) Prompt(format string, a ...interface{})

Prompt use name as title, and apply style for message

func (*Theme) Save Uses

func (t *Theme) Save()

Save to themes map

func (*Theme) Tips Uses

func (t *Theme) Tips(format string, a ...interface{})

Tips use name as title, only apply style for name

Directories

PathSynopsis
_examples
_examples/ref

Package color imports 7 packages (graph) and is imported by 131 packages. Updated 2020-04-05. Refresh now. Tools for package owners.