Skip to content

Commit

Permalink
update readme and fix tests error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 9, 2021
1 parent b72663c commit 0b651c3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Now, 256 colors and RGB colors have also been supported to work in Windows CMD a
- See [this gist](https://gist.github.com/XVilka/8346728) 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` terminal
- In addition to using built-in tags, it also supports custom color attributes
- Custom color attributes support the use of 16 color names, 256 color values, rgb color values and hex color values
- Support working on Windows `cmd` and `powerShell` terminal
- 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`
- Support by set `NO_COLOR` for disable color or use `FORCE_COLOR` for force open color render.
Expand Down
16 changes: 12 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ Golang下的命令行色彩使用库, 拥有丰富的色彩渲染输出,通用

## 功能特色

- 使用简单方便,无其他依赖
- 使用简单方便
- 支持丰富的颜色输出, 16色(4bit),256色(8bit),RGB色彩(24bit, RGB)
- 16色(4bit)是最常用和支持最广的,支持Windows `cmd.exe`
-`v1.2.4`**256色(8bit),RGB色彩(24bit)均支持Windows CMD和PowerShell终端**
- 请查看 [this gist](https://gist.github.com/XVilka/8346728) 了解支持RGB色彩的终端
- 通用的API方法`Print` `Printf` `Println` `Sprint` `Sprintf`
- 同时支持html标签式的颜色渲染.
- 实现通用的API方法`Print` `Printf` `Println` `Sprint` `Sprintf`
- 同时支持html标签式的颜色渲染,除了使用内置标签,同时支持自定义颜色属性
- 例如: `this an <green>message</>` 标签内部的文本将会渲染为绿色字体
- 自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值
- 基础色彩: `Bold` `Black` `White` `Gray` `Red` `Green` `Yellow` `Blue` `Magenta` `Cyan`
- 扩展风格: `Info` `Note` `Light` `Error` `Danger` `Notice` `Success` `Comment` `Primary` `Warning` `Question` `Secondary`
- 支持通过设置环境变量 `NO_COLOR` 来禁用色彩,或者使用 `FORCE_COLOR` 来强制使用色彩渲染.
Expand Down Expand Up @@ -91,8 +92,10 @@ func main() {
color.Warn.Println("message")
color.Error.Println("message")

// 使用颜色标签
// 使用内置颜色标签
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>\n")
// 自定义标签: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值
color.Println("<fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>")

// apply a style tag
color.Tag("info").Println("info style text")
Expand Down Expand Up @@ -234,6 +237,8 @@ Run demo: `go run ./_examples/theme_block.go`
使用内置的颜色标签,可以非常方便简单的构建自己需要的任何格式

> 同时支持自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值
```go
// 使用内置的 color tag
color.Print("<suc>he</><comment>llo</>, <cyan>wel</><red>come</>")
Expand All @@ -243,6 +248,9 @@ color.Println("<warning>hello</>")

// 自定义颜色属性
color.Print("<fg=yellow;bg=black;op=underscore;>hello, welcome</>\n")

// 自定义颜色属性: 支持使用16色彩名称,256色彩值,rgb色彩值以及hex色彩值
color.Println("<fg=11aa23>he</><bg=120,35,156>llo</>, <fg=167;bg=232>wel</><fg=red>come</>")
```

- 使用 `color.Tag`
Expand Down
8 changes: 4 additions & 4 deletions color_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ func NewTagParser() *TagParser {
return &TagParser{}
}

func (tp *TagParser) Disable() *TagParser {
tp.disable = true
return tp
}
// func (tp *TagParser) Disable() *TagParser {
// tp.disable = true
// return tp
// }

// ParseByEnv parse given string. will check package setting.
func (tp *TagParser) ParseByEnv(str string) string {
Expand Down
14 changes: 8 additions & 6 deletions color_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,21 @@ def <info>info text
is.Equal("", s)
}

func TestTagParser_Parse_c256(t *testing.T) {
}

func TestTagParser_Parse_hex_rgb(t *testing.T) {
func TestTagParser_Parse_hex_rgb_c256(t *testing.T) {
is := assert.New(t)
p := NewTagParser()

// "e7b2a1"
s := "custom tag: <fg=e7b2a1>hello, welcome</>"
r := p.Parse(s)
is.NotContains(r, "<")
is.NotContains(r, ">")
is.Equal(">", t)
is.Equal("custom tag: \x1B[38;2;231;178;161mhello, welcome\x1B[0m", r)

s = "custom tag: <fg=e7b2a1;bg=176;op=bold>hello, welcome</>"
r = p.Parse(s)
is.NotContains(r, "<")
is.NotContains(r, ">")
is.Equal("custom tag: \x1b[38;2;231;178;161;48;5;176;1mhello, welcome\x1b[0m", r)
}

func TestParseCodeFromAttr_basic(t *testing.T) {
Expand Down

0 comments on commit 0b651c3

Please sign in to comment.