🎨 Terminal color rendering tool library, support 8/16 colors, 256 colors, RGB color rendering output, support Print/Sprintf methods, compatible with Windows. GO CLI 控制台颜色渲染工具库,支持16色,256色,RGB色彩渲染输出,使用类似于 Print/Sprintf,兼容并支持 Windows 环境的色彩渲染

Overview

CLI Color

GitHub go.mod Go version Actions Status Codacy Badge GoDoc GitHub tag (latest SemVer) Build Status Coverage Status Go Report Card

A command-line color library with true color support, universal API methods and Windows support.

中文说明

Basic color preview:

basic-color

Now, 256 colors and RGB colors have also been supported to work in Windows CMD and PowerShell:

color-on-cmd-pwsh

Features

  • Simple to use, zero dependencies
  • Supports rich color output: 16-color (4-bit), 256-color (8-bit), true color (24-bit, RGB)
    • 16-color output is the most commonly used and most widely supported, working on any Windows version
    • Since v1.2.4 the 256-color (8-bit), true color (24-bit) support windows CMD and PowerShell
    • See this gist for information on true color support
  • Generic API methods: Print, Printf, Println, Sprint, Sprintf
  • Supports HTML tag-style color rendering, such as <green>message</>. Support working on windows cmd powerShell
  • Basic colors: Bold, Black, White, Gray, Red, Green, Yellow, Blue, Magenta, Cyan
  • Additional styles: Info, Note, Light, Error, Danger, Notice, Success, Comment, Primary, Warning, Question, Secondary

GoDoc

Install

go get github.com/gookit/color

NOTICE

If you want print custom colors message on windows, should use color.PrintX instead of fmt.PrintX

str := color.Red.Sprint("an colored message string")

// Color will not be output under Windows
fmt.Println(str)

// Color will be output under Windows
color.Println(str)

color.PrintX is universal, you can use it directly instead of fmt.PrintX

Quick start

package main

import (
	"fmt"

	"github.com/gookit/color"
)

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

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

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

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

	// internal theme/style:
	color.Info.Tips("message")
	color.Info.Prompt("message")
	color.Info.Println("message")
	color.Warn.Println("message")
	color.Error.Println("message")

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

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

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

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

Run demo: go run ./_examples/demo.go

colored-out

Custom Build Color

// Only use foreground color
color.FgCyan.Printf("Simple to use %s\n", "color")
// Only use background color
color.BgRed.Printf("Simple to use %s\n", "color")

// Full custom: foreground, background, option
myStyle := color.New(color.FgWhite, color.BgBlack, color.OpBold)
myStyle.Println("custom color style")

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

custom set console settings:

// set console color
color.Set(color.FgCyan)

// print message
fmt.Print("message")

// reset console settings
color.Reset()

Basic Color

Supported on any Windows version.

  • color.Bold
  • color.Black
  • color.White
  • color.Gray
  • color.Red
  • color.Green
  • color.Yellow
  • color.Blue
  • color.Magenta
  • color.Cyan
color.Bold.Println("bold message")
color.Yellow.Println("yellow message")

Run demo: go run ./_examples/basiccolor.go

basic-color

Additional styles

Supported on any Windows version.

  • color.Info
  • color.Note
  • color.Warn
  • color.Light
  • color.Error
  • color.Danger
  • color.Debug
  • color.Notice
  • color.Success
  • color.Comment
  • color.Primary
  • color.Question
  • color.Secondary

Basic Style

print message use defined style:

color.Info.Println("Info message")
color.Note.Println("Note message")
color.Notice.Println("Notice message")
color.Error.Println("Error message")
color.Danger.Println("Danger message")
color.Warn.Println("Warn message")
color.Debug.Println("Debug message")
color.Primary.Println("Primary message")
color.Question.Println("Question message")
color.Secondary.Println("Secondary message")

Run demo: go run ./_examples/theme_basic.go

theme-basic

Tips Style

color.Info.Tips("Info tips message")
color.Note.Tips("Note tips message")
color.Notice.Tips("Notice tips message")
color.Error.Tips("Error tips message")
color.Danger.Tips("Danger tips message")
color.Warn.Tips("Warn tips message")
color.Debug.Tips("Debug tips message")
color.Primary.Tips("Primary tips message")
color.Question.Tips("Question tips message")
color.Secondary.Tips("Secondary tips message")

Run demo: go run ./_examples/theme_tips.go

theme-tips

Prompt Style

color.Info.Prompt("Info prompt message")
color.Note.Prompt("Note prompt message")
color.Notice.Prompt("Notice prompt message")
color.Error.Prompt("Error prompt message")
color.Danger.Prompt("Danger prompt message")
color.Warn.Prompt("Warn prompt message")
color.Debug.Prompt("Debug prompt message")
color.Primary.Prompt("Primary prompt message")
color.Question.Prompt("Question prompt message")
color.Secondary.Prompt("Secondary prompt message")

Run demo: go run ./_examples/theme_prompt.go

theme-prompt

Block Style

color.Info.Block("Info block message")
color.Note.Block("Note block message")
color.Notice.Block("Notice block message")
color.Error.Block("Error block message")
color.Danger.Block("Danger block message")
color.Warn.Block("Warn block message")
color.Debug.Block("Debug block message")
color.Primary.Block("Primary block message")
color.Question.Block("Question block message")
color.Secondary.Block("Secondary block message")

Run demo: go run ./_examples/theme_block.go

theme-block

HTML-like tag usage

Supported on Windows cmd.exe PowerShell .

// use style tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>")
color.Println("<suc>hello</>")
color.Println("<error>hello</>")
color.Println("<warning>hello</>")

// custom color attributes
color.Print("<fg=yellow;bg=black;op=underscore;>hello, welcome</>\n")
  • color.Tag
// set a style tag
color.Tag("info").Print("info style text")
color.Tag("info").Printf("%s style text", "info")
color.Tag("info").Println("info style text")

Run demo: go run ./_examples/colortag.go

color-tags

256-color usage

256 colors support Windows CMD, PowerShell environment after v1.2.4

Set the foreground or background color

  • color.C256(val uint8, isBg ...bool) Color256
c := color.C256(132) // fg color
c.Println("message")
c.Printf("format %s", "message")

c := color.C256(132, true) // bg color
c.Println("message")
c.Printf("format %s", "message")

Use a 256-color style

Can be used to set foreground and background colors at the same time.

  • S256(fgAndBg ...uint8) *Style256
s := color.S256(32, 203)
s.Println("message")
s.Printf("format %s", "message")

with options:

s := color.S256(32, 203)
s.SetOpts(color.Opts{color.OpBold})

s.Println("style with options")
s.Printf("style with %s\n", "options")

Run demo: go run ./_examples/color256.go

color-tags

Use RGB color

RGB colors support Windows CMD, PowerShell environment after v1.2.4

Preview:

Run demo: Run demo: go run ./_examples/color_rgb.go

color-rgb

example:

color.RGB(30, 144, 255).Println("message. use RGB number")

color.HEX("#1976D2").Println("blue-darken")
color.HEX("#D50000", true).Println("red-accent. use HEX style")

color.RGBStyleFromString("213,0,0").Println("red-accent. use RGB number")
color.HEXStyle("eee", "D50000").Println("deep-purple color")

Set the foreground or background color

  • color.RGB(r, g, b uint8, isBg ...bool) RGBColor
c := color.RGB(30,144,255) // fg color
c.Println("message")
c.Printf("format %s", "message")

c := color.RGB(30,144,255, true) // bg color
c.Println("message")
c.Printf("format %s", "message")

Create a style from an hexadecimal color string:

  • color.HEX(hex string, isBg ...bool) RGBColor
c := color.HEX("ccc") // can also: "cccccc" "#cccccc"
c.Println("message")
c.Printf("format %s", "message")

c = color.HEX("aabbcc", true) // as bg color
c.Println("message")
c.Printf("format %s", "message")

Use an RGB color style

Can be used to set the foreground and background colors at the same time.

  • color.NewRGBStyle(fg RGBColor, bg ...RGBColor) *RGBStyle
s := color.NewRGBStyle(RGB(20, 144, 234), RGB(234, 78, 23))
s.Println("message")
s.Printf("format %s", "message")

Create a style from an hexadecimal color string:

  • color.HEXStyle(fg string, bg ...string) *RGBStyle
s := color.HEXStyle("11aa23", "eee")
s.Println("message")
s.Printf("format %s", "message")

with options:

s := color.HEXStyle("11aa23", "eee")
s.SetOpts(color.Opts{color.OpBold})

s.Println("style with options")
s.Printf("style with %s\n", "options")

Func refer

there are some useful functions reference

  • Disable() disable color render
  • SetOutput(io.Writer) custom set the colored text output writer
  • ForceOpenColor() force open color render
  • Colors2code(colors ...Color) string Convert colors to code. return like "32;45;3"
  • ClearCode(str string) string Use for clear color codes
  • ClearTag(s string) string clear all color html-tag for a string
  • IsConsole(w io.Writer) Determine whether w is one of stderr, stdout, stdin
  • HexToRgb(hex string) (rgb []int) Convert hex color string to RGB numbers
  • RgbToHex(rgb []int) string Convert RGB to hex code

Gookit packages

  • gookit/ini Go config management, use INI files
  • gookit/rux Simple and fast request router for golang HTTP
  • gookit/gcli build CLI application, tool library, running CLI commands
  • gookit/slog Concise and extensible go log library
  • gookit/event Lightweight event manager and dispatcher implements by Go
  • gookit/cache Generic cache use and cache manager for golang. support File, Memory, Redis, Memcached.
  • gookit/config Go config management. support JSON, YAML, TOML, INI, HCL, ENV and Flags
  • gookit/color A command-line color library with true color support, universal API methods and Windows support
  • gookit/filter Provide filtering, sanitizing, and conversion of golang data
  • gookit/validate Use for data validation and filtering. support Map, Struct, Form data
  • gookit/goutil Some utils for the Go: string, array/slice, map, format, cli, env, filesystem, test and more
  • More, please see https://github.com/gookit

See also

License

MIT

Comments
  • colors don't work on windows with git for windows while using vscode

    colors don't work on windows with git for windows while using vscode

    System (please complete the following information):

    • OS: Windows 10
    • GO Version: 1.1.5
    • Pkg Version: Latest

    Describe the bug

    A clear and concise description of what the bug is.

    To Reproduce

    Use my module and run go test -v .

    Expected behavior

    A clear and concise description of what you expected to happen.

    Same output as Windows Terminal

    image

    Screenshots

    What I get:

    image

    Additional context

    The screenshot is from VsCode but the same problem doesn't happen in Git Bash.

    bug help wanted 
    opened by Delta456 35
  • Color not working on Manjaro

    Color not working on Manjaro

    Here the output from the demo, I was expecting your nice colors: unfortunately it's all white.

    image

    What do you think the problem is ? Did you encounter such problem ?

    • NeoFetch output if needed:
    OS: Manjaro Linux x86_64 
    Kernel: 4.19.81-1-MANJARO
    Shell: bash 5.0.11 
    Resolution: 1920x1080 
    WM: i3 
    Theme: Adwaita [GTK3] 
    Icons: Adwaita [GTK3] 
    Terminal: urxvt 
    Terminal Font: DejaVu Sans Mono
    

    Thank you for your time,

    bug 
    opened by SidoShiro 14
  • No color after v1.4.0 upgrade

    No color after v1.4.0 upgrade

    System:

    • OS: linux
    • GO Version: 1.16
    • Pkg Version: 1.4.0
    TERM=xterm
    

    Describe the bug

    After upgrading to 1.4.0, no more color in output, without error.

    To Reproduce

    Upgrade to v1.4.0.

    green := color.FgGreen.Render
    fmt.Println(">>> Blah :", green("blahblah"))
    

    Expected behavior

    The color must be printed as expected.

    bug 
    opened by babykart 10
  • Use terminfo instead of hardcoding a list of terminals

    Use terminfo instead of hardcoding a list of terminals

    Hey!

    You should use terminfo instead of relying on the terminal name in TERM. This can provide you the number of colors supported. Otherwise, you are missing a lot of terminals supporting colors, like rxvt or screen. In Go, it seems https://github.com/xo/terminfo can do that. It also seems to handle some edge cases for terminals not using the correct TERM. It also handles the special case of true color which was not available through terminfo until recently and is able to fallback to COLORTERM (but it should be using Tc if available).

    enhancement question 
    opened by vincentbernat 9
  • Color on Windows in cygwin, powershell, cmd

    Color on Windows in cygwin, powershell, cmd

    This tool looks really promising! So thanks in advance.

    I'm running into some issues with your isSupportColor method on Windows, which affects RenderCode.

    1. Pure git-bash:
      • $MSYSTEM = MINGW64
      • $TERM = xterm
      • 256 coloration seems to work
    2. ConsoleZ git-bash (started via C:\Program Files\Git\bin\sh.exe --login -i)
      • $MSYSTEM = MINGW64
      • $TERM = cygwin
      • coloration is disabled
      • 16-color coloration is possible via github.com/fatih/color - Output
    3. CMD:
      • %CMDEXTVERSION% = 2
      • coloration is disabled
      • 16-color coloration is possible via github.com/fatih/color - Output
    4. Powershell:
      • Version: 5.1.16299.1146
      • coloration is disabled
      • 16-color coloration is possible via github.com/fatih/color - Output

    My method for testing includes creating a color.C256 object and using it's Sprint method to output the string to write to a github.com/fatih/color - Output Writer.

    Thanks!

    question 
    opened by tomcruise81 6
  • feature: add hsl to and from methods

    feature: add hsl to and from methods

    Hi! I think it will be good to also add methods to take hsl as input and convert it by different variants.

    For reference, you can refer to this code.

    I need this feature as I will be adding HSL format as input option for my box-cli-maker.

    enhancement 
    opened by Delta456 4
  • panic when running on windows with multiple go routines

    panic when running on windows with multiple go routines

    Running this with multiple go routines causes this crash (on windows):

    runtime: bad pointer in frame github.com/gookit/color.EnableVirtualTerminalProcessing at 0xc000581838: 0x58
    fatal error: invalid pointer found on stack
    
    runtime stack:
    runtime.throw(0xc6d2fe, 0x1e)
            C:/Program Files/go/src/runtime/panic.go:1116 +0x79 fp=0xb2f1bff4d0 sp=0xb2f1bff4a0 pc=0x659799
    runtime.adjustpointers(0xc000581838, 0xb2f1bff5c0, 0xb2f1bff948, 0xfbcc00, 0x100e2a0)
            C:/Program Files/go/src/runtime/stack.go:605 +0x1e8 fp=0xb2f1bff520 sp=0xb2f1bff4d0 pc=0x66e888
    runtime.adjustframe(0xb2f1bff858, 0xb2f1bff948, 0x100e2a0)
            C:/Program Files/go/src/runtime/stack.go:647 +0x36b fp=0xb2f1bff5f0 sp=0xb2f1bff520 pc=0x66ec0b
    runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc000084d80, 0x0, 0x0, 0x7fffffff, 0xc89118, 0xb2f1bff948, 0x0, ...)
            C:/Program Files/go/src/runtime/traceback.go:334 +0x11b5 fp=0xb2f1bff8c0 sp=0xb2f1bff5f0 pc=0x67acd5
    runtime.copystack(0xc000084d80, 0x2000)
            C:/Program Files/go/src/runtime/stack.go:910 +0x2a7 fp=0xb2f1bffa78 sp=0xb2f1bff8c0 pc=0x66f387
    runtime.shrinkstack(0xc000084d80)
            C:/Program Files/go/src/runtime/stack.go:1178 +0x149 fp=0xb2f1bffaa0 sp=0xb2f1bffa78 pc=0x670429
    runtime.scanstack(0xc000084d80, 0xc00002de98)
            C:/Program Files/go/src/runtime/mgcmark.go:815 +0x56e fp=0xb2f1bffca8 sp=0xb2f1bffaa0 pc=0x640e4e
    runtime.markroot.func1()
            C:/Program Files/go/src/runtime/mgcmark.go:245 +0xce fp=0xb2f1bffcf8 sp=0xb2f1bffca8 pc=0x681cee
    runtime.markroot(0xc00002de98, 0x14)
            C:/Program Files/go/src/runtime/mgcmark.go:218 +0x310 fp=0xb2f1bffd80 sp=0xb2f1bffcf8 pc=0x63f910
    runtime.gcDrain(0xc00002de98, 0x7)
            C:/Program Files/go/src/runtime/mgcmark.go:1109 +0x138 fp=0xb2f1bffdd8 sp=0xb2f1bffd80 pc=0x641578
    runtime.gcBgMarkWorker.func2()
            C:/Program Files/go/src/runtime/mgc.go:1981 +0x176 fp=0xb2f1bffe18 sp=0xb2f1bffdd8 pc=0x681bd6
    runtime.systemstack(0x0)
            C:/Program Files/go/src/runtime/asm_amd64.s:370 +0x6b fp=0xb2f1bffe20 sp=0xb2f1bffe18 pc=0x68a6ab
    runtime.mstart()
            C:/Program Files/go/src/runtime/proc.go:1116 fp=0xb2f1bffe28 sp=0xb2f1bffe20 pc=0x65e920
    
    bug 
    opened by techmanmike 4
  • Question: How to escape color tags

    Question: How to escape color tags

    I'm using the HTML like tags feature to pretty print some JSON, but I'm concerned that occasionally the JSON data might have tags like that would start getting rendered as a color. I did a search and replace and didn't see anything, so was wondering if there was a way to escape or encode tags to make it so that color tags aren't injected?

    question 
    opened by SJrX 3
  • Truecolor being detected but no colour output

    Truecolor being detected but no colour output

    IsSupportTrueColor
    (bool) true
    IsSupport256Color
    (bool) false
    IsSupportColor
    (bool) false
    
    env | grep TERM
    COLORTERM=truecolor
    TERM=alacritty
    

    github.com/gookit/color v1.2.7

    bug 
    opened by s3than 3
  • Bump github.com/stretchr/testify from 1.3.0 to 1.6.1

    Bump github.com/stretchr/testify from 1.3.0 to 1.6.1

    Bumps github.com/stretchr/testify from 1.3.0 to 1.6.1.

    Release notes

    Sourced from github.com/stretchr/testify's releases.

    Fixes breaking change with HTTPBodyContains

    A breaking change was accidentally released in v1.6.0 which breaks the API for the HTTPBodyContains and HTTPBodyNotContains, this release reverts that change.

    v1.6.0

    Latest release of testify. This includes many fixes and enhancements. Please view the v1.6.0 milestone for a list of changes.

    HOTFIX: Revert suite interface type

    This is a hotfix which reverts the suite package's interface type to use testing.T

    v1.5.0

    Latest, non-breaking changes merged into master. Please peruse the git log for a detailed changelist

    v1.4.0

    The 1.4.0 release includes new matchers and bug fixes. See the v.1.4.0 milestone for a complete list of closed issues associated with this release.

    Commits
    • f654a91 Update Go versions in Travis
    • 3184a9e This reverts commit 0a813b5898c0ee8d00b4f13fae21ea5df8b35e74.
    • e2b269e This reverts commit 2adb7b54b75da2c74e9342ed115957fe0b07e0b4.
    • 6353e56 This reverts commit 9d083cac4a26c76f8d92dff41d459f3f2fc0b911.
    • 6561324 This reverts commit 484fff1ace1f0acb84676a548b53477685c16414.
    • 46420cf This reverts commit 1a43b8334acb9df58064b765cd16675cc7c2c8b3.
    • 303198d Revert "allow body for HTTPBodyContains and HTTPBodyNotContains for
    • e7cc868 Update TravisCI config
    • 004e3cb commit generated files
    • ac1463f Implement NotEqualValues
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Note: This repo was added to Dependabot recently, so you'll receive a maximum of 5 PRs for your first few update runs. Once an update run creates fewer than 5 PRs we'll remove that limit.

    You can always request more updates by clicking Bump now in your Dependabot dashboard.

    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
    • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

    Additionally, you can set the following in your Dependabot dashboard:

    • Update frequency (including time of day and day of week)
    • Pull request limits (per update run and/or open at any time)
    • Out-of-range updates (receive only lockfile updates, if desired)
    • Security updates (receive only security updates, if desired)
    dependencies 
    opened by dependabot-preview[bot] 3
  • Add support for tmux-256color

    Add support for tmux-256color

    The recommended way of enabling color support in tmux is to set the terminal to screen-256color or tmux-256color: https://github.com/tmux/tmux/wiki/FAQ

    opened by georgijd 3
  • build(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1

    build(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1

    Bumps github.com/stretchr/testify from 1.8.0 to 1.8.1.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies go 
    opened by dependabot[bot] 0
  • tag-style color rendering fails if lines contain tag like content

    tag-style color rendering fails if lines contain tag like content

    System (please complete the following information):

    • OS: linux
    • GO Version: 1.18.1
    • Pkg Version: 1.5.2

    ENV info on the terminal (by command env | grep -i TERM):

    COLORTERM=truecolor
    TERM_PROGRAM_VERSION=3.2a
    TERM=tmux-256color
    TERM_PROGRAM=tmux
    

    Describe the bug

    I am using tag-style color rendeing to colorize tabular data. If multiple lines contain something like this: <none> then only the first colorziation works, subsequent ones are not replaced but printed as is.

    To Reproduce

    package main
    
    import (
    	"github.com/gookit/color"
    )
    
    func main() {
    	test1 := `FAILS:
    one <bg=lightGreen;fg=black>two</> <three>
    foo <bg=lightGreen;fg=black>two</> <four>
    
    `
    
    	test2 := `WORKS:
    one <bg=lightGreen;fg=black>two <three></>
    foo <bg=lightGreen;fg=black>two <four></>
    
    `
    
    	test3 := `WORKS:
    one <bg=lightGreen;fg=black>two</> three
    foo <bg=lightGreen;fg=black>two</> four
    `
    
    	color.Print(test1)
    	color.Print(test2)
    	color.Print(test3)
    }
    

    Expected behavior

    The colorziation should work independently from other non color-tag content.

    Screenshots

    See screenshot attached.

    colorfails

    ** Edited to add **

    The problem occurs ONLY if the "tagged" content appears outside the colorization. If it's inside, it works. Sample code and screenshot updated.

    question 
    opened by TLINDEN 5
  • `ClearCode` doesn't work as intended on Mac OS

    `ClearCode` doesn't work as intended on Mac OS

    I am using your library in box-cli-maker and use color.ClearCode to clear colors from the string but it doesn't work on Mac OS's iterm terminal though works on other OSes Terminal.

    Read this issue for the detailed information https://github.com/Delta456/box-cli-maker/issues/29

    bug 
    opened by Delta456 0
Releases(v1.5.2)
  • v1.5.2(Aug 29, 2022)

    Change Log

    Refactor

    • refactor: update and refactor the color tag parse logic https://github.com/gookit/color/commit/efc6d3fe9d5faad9281767b3980114eb98ae0d17

    Fixed

    • fix: RGBFromString() maybe input overflow int value https://github.com/gookit/color/commit/bf93227272fb8d21b8ef98962606e5873e7d1b49

    Update

    • up: update some comments and add more unit tests https://github.com/gookit/color/commit/daca06fde9311a07d9658135599e814d93bcd368

    Other

    • build(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.3 https://github.com/gookit/color/commit/ab29a70449f8a5d690672f2446a22c00b0ab3b0b
    • build(deps): bump github.com/stretchr/testify from 1.7.3 to 1.7.4 https://github.com/gookit/color/commit/8e41e715ddc7bb1d098960ba0978c43ee11e0dd6
    • build(deps): bump github.com/stretchr/testify from 1.7.4 to 1.7.5 https://github.com/gookit/color/commit/895e882a27b90f9a6e42b3d959b891dc45340a63
    • chore: add color level alias of the terminfo.ColorLevel https://github.com/gookit/color/commit/2f5b36dff8aa50297cd52a4db3c486aefeec780f
    • chore: update some func comments, fix some code style https://github.com/gookit/color/commit/f30c87365ad1b577a55f7b920c8e307e8b23647e
    • chore: update the limit go version and update release gh action https://github.com/gookit/color/commit/e12eb6f3a7dadabfa456343bb1df52cb89e98faf
    • chore: update the readme add more HTML like tags usage https://github.com/gookit/color/commit/d305f5f8b46f52835c931943952d9d5b219dcd43
    • chore: add more docs for detect color level on readme https://github.com/gookit/color/commit/0ec8e783c81a447597d4337e07aba34ccfc2cf80
    • build(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0 https://github.com/gookit/color/commit/1823e0cfdef89b1d184efbb1ebfa16e9d5a987bd
    • chore: update some comments code styles https://github.com/gookit/color/commit/d0fe5131ad7d641b0e6b73e3e579fa0755ff10a6

    Full Changelog: https://github.com/gookit/color/compare/v1.5.1...v1.5.2

    Source code(tar.gz)
    Source code(zip)
  • v1.5.1(Jun 10, 2022)

    Change Log

    Feature

    • feat: add more quick start func for use color https://github.com/gookit/color/commit/85b9eb087b9bce948e36f509f8f5741d53847d38

    Update

    • up: update action, will auto generate changelog on release https://github.com/gookit/color/commit/fb141c4f10691c2934b3a43855d7bd10c6a9d889
    • up: update some for build full color string https://github.com/gookit/color/commit/d5924d1101229c714b390f2acd9a812aa02b1e7f
    • chore: update the basic color preview image https://github.com/gookit/color/commit/95811af7736caa753d7de55a7876661b6e2e63ba
    • chore: update pkg limit go version to 1.14+ https://github.com/gookit/color/commit/bef594f34ff7a5f0fcb50005939b4e170d969bfb

    Other

    • doc: add docsify for project https://github.com/gookit/color/commit/ce925d0246985f3e0ab02be37522c92870b82aee
    • doc: add more gookit project https://github.com/gookit/color/commit/ef04058f8dc349d65796f4a57763be000d1b1323
    • build(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.1 https://github.com/gookit/color/commit/3ec6601cbc3cc3ffa93d757376da2a6da58758be
    • build(deps): bump github.com/stretchr/testify from 1.7.1 to 1.7.2 https://github.com/gookit/color/commit/2d784a37639a1115ba827468a0511ddbb2382680
    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Oct 18, 2021)

    Change Log

    Update

    • update: add case for tests WSL env https://github.com/gookit/color/commit/44058898ccb9660cd713cee033472eb2d8603580
    • Add bg colors to basic to hex convertor https://github.com/gookit/color/commit/ac28629353f8d8558feb83bead17d478daf4e5e1
    • add new project on readme https://github.com/gookit/color/commit/254c63f8abccd86c0201c814590c7afcbad8e76a
    • up: add more unit tests https://github.com/gookit/color/commit/5f87df48555ce0dac5a2981638dc3e9d43b1e969
    • enhance: support use color name create some common rgb color https://github.com/gookit/color/commit/e48d1e5803a8f30335c91fb6a3c9cdb565d79977
    • breaking: will not support go < 1.13 https://github.com/gookit/color/commit/b29d2b20b8e2f830de919ba29795b87677c36e50

    Feature

    • feat: support create Rgb color from Hsl value, issue #40 https://github.com/gookit/color/commit/dfe4c47c2703da71535ceda22798bd2da869c012
    • feat: add more convert methods on Color https://github.com/gookit/color/commit/3986cfdc2218045802bec480b0c36b6e6ed5bdc3

    Other

    • readme: update readme add more projects https://github.com/gookit/color/commit/ce88fcee7c22dc3dc59e6d5e64558ca03e09ce48
    • readme: update readme https://github.com/gookit/color/commit/79357dc20edd6a400b1620d99f8302d781f74364
    • chore: add an example demo for use color https://github.com/gookit/color/commit/c8097c233b23c3cc1102dfe0e28b247f2c8eee06
    • Bump github.com/stretchr/testify from 1.3.0 to 1.7.0 https://github.com/gookit/color/commit/468b81a7f6a8257456704b11294cfa272f0b1779
    • style: add some comments https://github.com/gookit/color/commit/d1c276a856b99bd7279ba94e23aa2d3d46f9fa85
    • sytle: update readme https://github.com/gookit/color/commit/c7dc09464b28518c2ae383fa16b989e7c0169599
    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Apr 10, 2021)

  • v1.4.1(Apr 7, 2021)

  • v1.4.0(Apr 6, 2021)

  • v1.3.8(Feb 28, 2021)

  • v1.3.7(Feb 5, 2021)

  • v1.3.6(Dec 26, 2020)

  • v1.3.5(Dec 10, 2020)

  • v1.3.4(Dec 10, 2020)

  • v1.3.3(Dec 3, 2020)

  • v1.3.2(Nov 2, 2020)

  • v1.3.0(Sep 13, 2020)

  • v1.2.9(Sep 2, 2020)

  • v1.2.8(Aug 25, 2020)

  • v1.2.7(Jul 23, 2020)

  • v1.2.6(Jul 10, 2020)

    • update style render, support true color on windows
    • add some tool methods for convert rgb, hex code
    • update some preview images
    • update readme
    Source code(tar.gz)
    Source code(zip)
  • v1.2.5(Apr 26, 2020)

  • v1.2.4(Apr 5, 2020)

  • v1.2.3(Mar 3, 2020)

  • v1.2.0(Sep 1, 2019)

  • v1.1.11(Aug 30, 2019)

    • modify some logic on windows print
    • multi arg don't add space, only add spaces on use Println func
    • feat: now, color html tag support working on windows cmd and powerShell
    • update some color print logic
    Source code(tar.gz)
    Source code(zip)
  • v1.1.10(Aug 16, 2019)

  • v1.1.7(Apr 30, 2019)

  • v1.1.5(Oct 14, 2018)

  • v1.1.4(Oct 11, 2018)

  • v1.1.3(Aug 23, 2018)

  • v1.1.0(Aug 19, 2018)

Owner
Gookit
Useful libs for the Go(router, DI, log, config, cache, event, validate, filter, CLI, i18n, respond-data, view-render)
Gookit
Console Text Colors - The non-invasive cross-platform terminal color library does not need to modify the Print method

ctc - Console Text Colors The non-invasive cross-platform terminal color library does not need to modify the Print method Virtual unix-like environmen

null 41 Nov 9, 2022
✨ #PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more 🚀 It's completely configurable and 100% cross-platform compatible.

?? PTerm | Pretty Terminal Printer A golang module to print pretty text Show Demo Code PTerm.sh | Installation | Documentation | Quick Start | Example

null 3.1k Nov 25, 2022
uilive is a go library for updating terminal output in realtime

uilive uilive is a go library for updating terminal output in realtime. It provides a buffered io.Writer that is flushed at a timed interval. uilive p

Greg Osuri 1.5k Nov 20, 2022
Terminal string styling for go done right, with full and painless Windows 10 support.

GChalk GChalk is a library heavily inspired by chalk, the popular Node.js terminal color library, and using go ports of supports-color and ansi-styles

Jason Walton 317 Nov 8, 2022
Intuitive package for prettifying terminal/console output. http://godoc.org/github.com/ttacon/chalk

chalk Chalk is a go package for styling console/terminal output. Check out godoc for some example usage: http://godoc.org/github.com/ttacon/chalk The

Trey Tacon 413 Nov 20, 2022
Small library for simple and convenient formatted stylized output to the console.

cfmt cfmt is a small library for simple and convenient formatted stylized output to the console, providing an interface that is exactly the same as th

Makhnev Petr 52 Oct 28, 2022
:art: Contextual fmt inspired by bootstrap color classes

Cfmt Contextual fmt It provides contextual formatting functions that have nearly identical usage of the fmt package. The ideas were borrowed from boot

MinJae Kwon 90 Oct 27, 2022
Change the color of console text.

go-colortext package This is a package to change the color of the text and background in the console, working both under Windows and other systems. Un

Yi Deng 215 Oct 26, 2022
Yet Another CLi Spinner; providing over 70 easy to use and customizable terminal spinners for multiple OSes

Yet Another CLi Spinner (for Go) Package yacspin provides yet another CLi spinner for Go, taking inspiration (and some utility code) from the https://

Tim Heckman 385 Nov 18, 2022
Vale-compatible implementations of many popular "readability" metrics.

Readability This repository contains a Vale-compatible implementation of many popular "readability" metrics. Getting Started ❗ Readability requires Va

errata.ai 8 Aug 31, 2022
A go library to render progress bars in terminal applications

uiprogress A Go library to render progress bars in terminal applications. It provides a set of flexible features with a customizable API. Progress bar

Greg Osuri 2k Nov 20, 2022
A go library to improve readability in terminal apps using tabular data

uitable uitable is a go library for representing data as tables for terminal applications. It provides primitives for sizing and wrapping columns to i

Greg Osuri 681 Nov 20, 2022
go-colorable - Colorable writer for windows.

go-colorable Colorable writer for windows. For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But

mattn 659 Nov 24, 2022
An ANSI colour terminal package for Go

colourize An ANSI colour terminal package for Go. Supports all ANSI colours and emphasis. Not compatible with Windows systems. Installation go get gi

Trey Bastian 26 Sep 26, 2022
Simple tables in terminal with Go

Simple tables in terminal with Go This package allows to generate and display ascii tables in the terminal, f.e.: +----+------------------+-----------

Alexey Popov 399 Nov 20, 2022
Terminal based dashboard.

Termdash is a cross-platform customizable terminal based dashboard. The feature set is inspired by the gizak/termui project, which in turn was inspire

Jakub Sobon 2.2k Nov 27, 2022
Golang terminal dashboard

termui termui is a cross-platform and fully-customizable terminal dashboard and widget library built on top of termbox-go. It is inspired by blessed-c

Zack Guo 12.2k Nov 24, 2022
multi progress bar for Go cli applications

Multi Progress Bar mpb is a Go lib for rendering progress bars in terminal applications. Features Multiple Bars: Multiple progress bars are supported

Vladimir Bauer 1.9k Nov 23, 2022
A CLI to adjust display brightness using xrandr. Made because Ubuntu desktop was baking my eyeballs in low light.

bright This is a simple program to set monitor brightness using xrandr. I made this because Ubuntu does not come with a built-in way to change monitor

Micah Parks 0 Jan 15, 2022