diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3d005be..050245f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,10 @@ name: action-tests on: + pull_request: + paths: + - 'go.mod' + - '**.go' + - '**.yml' push: paths: - '**.go' @@ -14,7 +19,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - go_version: [1.16, 1.17, 1.18, 1.19] + go_version: [1.16, 1.17, 1.18, 1.19, '1.20'] os: [ubuntu-latest, windows-latest, macOS-latest] steps: diff --git a/README.md b/README.md index 718b11b..77d50ca 100644 --- a/README.md +++ b/README.md @@ -570,6 +570,7 @@ Check out these projects, which use https://github.com/gookit/color : - [xo/terminfo](https://github.com/xo/terminfo) - [beego/bee](https://github.com/beego/bee) - [issue9/term](https://github.com/issue9/term) + - [muesli/termenv](https://github.com/muesli/termenv) - [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) - [Standard ANSI color map](https://conemu.github.io/en/AnsiEscapeCodes.html#Standard_ANSI_color_map) - [Terminal Colors](https://gist.github.com/XVilka/8346728) diff --git a/README.zh-CN.md b/README.zh-CN.md index 1b14405..192a89c 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -578,6 +578,7 @@ const ( ## ๅ‚่€ƒ้กน็›ฎ - [inhere/console](https://github.com/inhere/php-console) + - [muesli/termenv](https://github.com/muesli/termenv) - [xo/terminfo](https://github.com/xo/terminfo) - [beego/bee](https://github.com/beego/bee) - [issue9/term](https://github.com/issue9/term) diff --git a/any.go b/any.go new file mode 100644 index 0000000..8bf31c1 --- /dev/null +++ b/any.go @@ -0,0 +1,6 @@ +//go:build !go1.18 +// +build !go1.18 + +package color + +type any = interface{} diff --git a/colorp/any.go b/colorp/any.go new file mode 100644 index 0000000..92f6384 --- /dev/null +++ b/colorp/any.go @@ -0,0 +1,6 @@ +//go:build !go1.18 +// +build !go1.18 + +package colorp + +type any = interface{} diff --git a/colorp/colorp.go b/colorp/colorp.go new file mode 100644 index 0000000..472947e --- /dev/null +++ b/colorp/colorp.go @@ -0,0 +1,111 @@ +// Package colorp provide some functions for quick print colored text. +package colorp + +import "github.com/gookit/color" + +/************************************************************* + * quick use color print message + *************************************************************/ + +// Redp print message with Red color +func Redp(a ...any) { color.Red.Print(a...) } + +// Redf print message with Red color +func Redf(format string, a ...any) { color.Red.Printf(format, a...) } + +// Redln print message line with Red color +func Redln(a ...any) { color.Red.Println(a...) } + +// Bluep print message with Blue color +func Bluep(a ...any) { color.Blue.Print(a...) } + +// Bluef print message with Blue color +func Bluef(format string, a ...any) { color.Blue.Printf(format, a...) } + +// Blueln print message line with Blue color +func Blueln(a ...any) { color.Blue.Println(a...) } + +// Cyanp print message with Cyan color +func Cyanp(a ...any) { color.Cyan.Print(a...) } + +// Cyanf print message with Cyan color +func Cyanf(format string, a ...any) { color.Cyan.Printf(format, a...) } + +// Cyanln print message line with Cyan color +func Cyanln(a ...any) { color.Cyan.Println(a...) } + +// Grayp print message with Gray color +func Grayp(a ...any) { color.Gray.Print(a...) } + +// Grayf print message with Gray color +func Grayf(format string, a ...any) { color.Gray.Printf(format, a...) } + +// Grayln print message line with Gray color +func Grayln(a ...any) { color.Gray.Println(a...) } + +// Greenp print message with Green color +func Greenp(a ...any) { color.Green.Print(a...) } + +// Greenf print message with Green color +func Greenf(format string, a ...any) { color.Green.Printf(format, a...) } + +// Greenln print message line with Green color +func Greenln(a ...any) { color.Green.Println(a...) } + +// Yellowp print message with Yellow color +func Yellowp(a ...any) { color.Yellow.Print(a...) } + +// Yellowf print message with Yellow color +func Yellowf(format string, a ...any) { color.Yellow.Printf(format, a...) } + +// Yellowln print message line with Yellow color +func Yellowln(a ...any) { color.Yellow.Println(a...) } + +// Magentap print message with Magenta color +func Magentap(a ...any) { color.Magenta.Print(a...) } + +// Magentaf print message with Magenta color +func Magentaf(format string, a ...any) { color.Magenta.Printf(format, a...) } + +// Magentaln print message line with Magenta color +func Magentaln(a ...any) { color.Magenta.Println(a...) } + +/************************************************************* + * quick use style print message + *************************************************************/ + +// Infop print message with Info color +func Infop(a ...any) { color.Info.Print(a...) } + +// Infof print message with Info style +func Infof(format string, a ...any) { color.Info.Printf(format, a...) } + +// Infoln print message with Info style +func Infoln(a ...any) { color.Info.Println(a...) } + +// Successp print message with success color +func Successp(a ...any) { color.Success.Print(a...) } + +// Successf print message with success style +func Successf(format string, a ...any) { color.Success.Printf(format, a...) } + +// Successln print message with success style +func Successln(a ...any) { color.Success.Println(a...) } + +// Errorp print message with Error color +func Errorp(a ...any) { color.Error.Print(a...) } + +// Errorf print message with Error style +func Errorf(format string, a ...any) { color.Error.Printf(format, a...) } + +// Errorln print message with Error style +func Errorln(a ...any) { color.Error.Println(a...) } + +// Warnp print message with Warn color +func Warnp(a ...any) { color.Warn.Print(a...) } + +// Warnf print message with Warn style +func Warnf(format string, a ...any) { color.Warn.Printf(format, a...) } + +// Warnln print message with Warn style +func Warnln(a ...any) { color.Warn.Println(a...) } diff --git a/go.mod b/go.mod index e911ba1..67dcd2e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/gookit/color -go 1.16 +go 1.18 require ( github.com/stretchr/testify v1.8.0 diff --git a/issues_test.go b/issues_test.go index 74d78e2..1469b60 100644 --- a/issues_test.go +++ b/issues_test.go @@ -1,9 +1,11 @@ -package color +package color_test import ( "fmt" "strings" "testing" + + "github.com/gookit/color" ) // https://github.com/gookit/color/issues/51 @@ -20,7 +22,30 @@ func TestIssues_51(t *testing.T) { } title := string(titleRs) - fmt.Printf("topBar:\n%q\n%q\n", topBar, ClearCode(topBar)) - fmt.Printf("title:\n%q\n%q\n", title, ClearCode(title)) - fmt.Printf("Split:\n%#v\n", strings.Split(ClearCode(topBar), ClearCode(title))) + fmt.Printf("topBar:\n%q\n%q\n", topBar, color.ClearCode(topBar)) + fmt.Printf("title:\n%q\n%q\n", title, color.ClearCode(title)) + fmt.Printf("Split:\n%#v\n", strings.Split(color.ClearCode(topBar), color.ClearCode(title))) +} + +// https://github.com/gookit/color/issues/52 +func TestIssues_52(t *testing.T) { + test1 := `FAILS: +one two +foo two +` + + test2 := `WORKS: +one two +foo two +` + + test3 := `WORKS: +one two three +foo two four +` + + // colorp.Info + color.Print(test1) + color.Print(test2) + color.Print(test3) } diff --git a/printer.go b/printer.go index 326aabc..d601726 100644 --- a/printer.go +++ b/printer.go @@ -19,8 +19,9 @@ type PrinterFace interface { // Printer a generic color message printer. // // Usage: -// p := &Printer{Code: "32;45;3"} -// p.Print("message") +// +// p := &Printer{Code: "32;45;3"} +// p.Print("message") type Printer struct { // NoColor disable color. NoColor bool @@ -91,6 +92,16 @@ func (s *SimplePrinter) Println(v ...interface{}) { Println(v...) } +// Successf message +func (s *SimplePrinter) Successf(format string, a ...interface{}) { + Success.Printf(format, a...) +} + +// Successln message +func (s *SimplePrinter) Successln(a ...interface{}) { + Success.Println(a...) +} + // Infof message func (s *SimplePrinter) Infof(format string, a ...interface{}) { Info.Printf(format, a...)