Skip to content

Commit

Permalink
[+]新增Count函数,统计颜色控制字符数量~
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed Sep 30, 2022
1 parent c57ee89 commit 781b940
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/color/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func Random(s string) string {
return convANSI(s, rand.Intn(len(colorMap))+30, 0, []int{})
}

func Count(s string) int {
return len(s) - len(Clear(s))
}

//"\x1b[%sm%s\x1b[0m"
func Clear(s string) string {
var rBuf []byte
Expand Down

0 comments on commit 781b940

Please sign in to comment.