Skip to content

Commit 6037df8

Browse files
committed
✨ feat: add new pkg colorp for quickly print message
- add ci tests on go1.10
1 parent fff8921 commit 6037df8

File tree

9 files changed

+174
-8
lines changed

9 files changed

+174
-8
lines changed

.github/workflows/go.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: action-tests
22
on:
3+
pull_request:
4+
paths:
5+
- 'go.mod'
6+
- '**.go'
7+
- '**.yml'
38
push:
49
paths:
510
- '**.go'
@@ -14,7 +19,7 @@ jobs:
1419
runs-on: ${{ matrix.os }}
1520
strategy:
1621
matrix:
17-
go_version: [1.16, 1.17, 1.18, 1.19]
22+
go_version: [1.16, 1.17, 1.18, 1.19, '1.20']
1823
os: [ubuntu-latest, windows-latest, macOS-latest]
1924

2025
steps:

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ Check out these projects, which use https://github.com/gookit/color :
570570
- [xo/terminfo](https://github.com/xo/terminfo)
571571
- [beego/bee](https://github.com/beego/bee)
572572
- [issue9/term](https://github.com/issue9/term)
573+
- [muesli/termenv](https://github.com/muesli/termenv)
573574
- [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code)
574575
- [Standard ANSI color map](https://conemu.github.io/en/AnsiEscapeCodes.html#Standard_ANSI_color_map)
575576
- [Terminal Colors](https://gist.github.com/XVilka/8346728)

README.zh-CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ const (
578578
## 参考项目
579579

580580
- [inhere/console](https://github.com/inhere/php-console)
581+
- [muesli/termenv](https://github.com/muesli/termenv)
581582
- [xo/terminfo](https://github.com/xo/terminfo)
582583
- [beego/bee](https://github.com/beego/bee)
583584
- [issue9/term](https://github.com/issue9/term)

any.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//go:build !go1.18
2+
// +build !go1.18
3+
4+
package color
5+
6+
type any = interface{}

colorp/any.go

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//go:build !go1.18
2+
// +build !go1.18
3+
4+
package colorp
5+
6+
type any = interface{}

colorp/colorp.go

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Package colorp provide some functions for quick print colored text.
2+
package colorp
3+
4+
import "github.com/gookit/color"
5+
6+
/*************************************************************
7+
* quick use color print message
8+
*************************************************************/
9+
10+
// Redp print message with Red color
11+
func Redp(a ...any) { color.Red.Print(a...) }
12+
13+
// Redf print message with Red color
14+
func Redf(format string, a ...any) { color.Red.Printf(format, a...) }
15+
16+
// Redln print message line with Red color
17+
func Redln(a ...any) { color.Red.Println(a...) }
18+
19+
// Bluep print message with Blue color
20+
func Bluep(a ...any) { color.Blue.Print(a...) }
21+
22+
// Bluef print message with Blue color
23+
func Bluef(format string, a ...any) { color.Blue.Printf(format, a...) }
24+
25+
// Blueln print message line with Blue color
26+
func Blueln(a ...any) { color.Blue.Println(a...) }
27+
28+
// Cyanp print message with Cyan color
29+
func Cyanp(a ...any) { color.Cyan.Print(a...) }
30+
31+
// Cyanf print message with Cyan color
32+
func Cyanf(format string, a ...any) { color.Cyan.Printf(format, a...) }
33+
34+
// Cyanln print message line with Cyan color
35+
func Cyanln(a ...any) { color.Cyan.Println(a...) }
36+
37+
// Grayp print message with Gray color
38+
func Grayp(a ...any) { color.Gray.Print(a...) }
39+
40+
// Grayf print message with Gray color
41+
func Grayf(format string, a ...any) { color.Gray.Printf(format, a...) }
42+
43+
// Grayln print message line with Gray color
44+
func Grayln(a ...any) { color.Gray.Println(a...) }
45+
46+
// Greenp print message with Green color
47+
func Greenp(a ...any) { color.Green.Print(a...) }
48+
49+
// Greenf print message with Green color
50+
func Greenf(format string, a ...any) { color.Green.Printf(format, a...) }
51+
52+
// Greenln print message line with Green color
53+
func Greenln(a ...any) { color.Green.Println(a...) }
54+
55+
// Yellowp print message with Yellow color
56+
func Yellowp(a ...any) { color.Yellow.Print(a...) }
57+
58+
// Yellowf print message with Yellow color
59+
func Yellowf(format string, a ...any) { color.Yellow.Printf(format, a...) }
60+
61+
// Yellowln print message line with Yellow color
62+
func Yellowln(a ...any) { color.Yellow.Println(a...) }
63+
64+
// Magentap print message with Magenta color
65+
func Magentap(a ...any) { color.Magenta.Print(a...) }
66+
67+
// Magentaf print message with Magenta color
68+
func Magentaf(format string, a ...any) { color.Magenta.Printf(format, a...) }
69+
70+
// Magentaln print message line with Magenta color
71+
func Magentaln(a ...any) { color.Magenta.Println(a...) }
72+
73+
/*************************************************************
74+
* quick use style print message
75+
*************************************************************/
76+
77+
// Infop print message with Info color
78+
func Infop(a ...any) { color.Info.Print(a...) }
79+
80+
// Infof print message with Info style
81+
func Infof(format string, a ...any) { color.Info.Printf(format, a...) }
82+
83+
// Infoln print message with Info style
84+
func Infoln(a ...any) { color.Info.Println(a...) }
85+
86+
// Successp print message with success color
87+
func Successp(a ...any) { color.Success.Print(a...) }
88+
89+
// Successf print message with success style
90+
func Successf(format string, a ...any) { color.Success.Printf(format, a...) }
91+
92+
// Successln print message with success style
93+
func Successln(a ...any) { color.Success.Println(a...) }
94+
95+
// Errorp print message with Error color
96+
func Errorp(a ...any) { color.Error.Print(a...) }
97+
98+
// Errorf print message with Error style
99+
func Errorf(format string, a ...any) { color.Error.Printf(format, a...) }
100+
101+
// Errorln print message with Error style
102+
func Errorln(a ...any) { color.Error.Println(a...) }
103+
104+
// Warnp print message with Warn color
105+
func Warnp(a ...any) { color.Warn.Print(a...) }
106+
107+
// Warnf print message with Warn style
108+
func Warnf(format string, a ...any) { color.Warn.Printf(format, a...) }
109+
110+
// Warnln print message with Warn style
111+
func Warnln(a ...any) { color.Warn.Println(a...) }

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/gookit/color
22

3-
go 1.16
3+
go 1.18
44

55
require (
66
github.com/stretchr/testify v1.8.0

issues_test.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
package color
1+
package color_test
22

33
import (
44
"fmt"
55
"strings"
66
"testing"
7+
8+
"github.com/gookit/color"
79
)
810

911
// https://github.com/gookit/color/issues/51
@@ -20,7 +22,30 @@ func TestIssues_51(t *testing.T) {
2022
}
2123
title := string(titleRs)
2224

23-
fmt.Printf("topBar:\n%q\n%q\n", topBar, ClearCode(topBar))
24-
fmt.Printf("title:\n%q\n%q\n", title, ClearCode(title))
25-
fmt.Printf("Split:\n%#v\n", strings.Split(ClearCode(topBar), ClearCode(title)))
25+
fmt.Printf("topBar:\n%q\n%q\n", topBar, color.ClearCode(topBar))
26+
fmt.Printf("title:\n%q\n%q\n", title, color.ClearCode(title))
27+
fmt.Printf("Split:\n%#v\n", strings.Split(color.ClearCode(topBar), color.ClearCode(title)))
28+
}
29+
30+
// https://github.com/gookit/color/issues/52
31+
func TestIssues_52(t *testing.T) {
32+
test1 := `FAILS:
33+
one <bg=lightGreen;fg=black>two</> <three>
34+
foo <bg=lightGreen;fg=black>two</> <four>
35+
`
36+
37+
test2 := `WORKS:
38+
one <bg=lightGreen;fg=black>two <three></>
39+
foo <bg=lightGreen;fg=black>two <four></>
40+
`
41+
42+
test3 := `WORKS:
43+
one <bg=lightGreen;fg=black>two</> three
44+
foo <bg=lightGreen;fg=black>two</> four
45+
`
46+
47+
// colorp.Info
48+
color.Print(test1)
49+
color.Print(test2)
50+
color.Print(test3)
2651
}

printer.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ type PrinterFace interface {
1919
// Printer a generic color message printer.
2020
//
2121
// Usage:
22-
// p := &Printer{Code: "32;45;3"}
23-
// p.Print("message")
22+
//
23+
// p := &Printer{Code: "32;45;3"}
24+
// p.Print("message")
2425
type Printer struct {
2526
// NoColor disable color.
2627
NoColor bool
@@ -91,6 +92,16 @@ func (s *SimplePrinter) Println(v ...interface{}) {
9192
Println(v...)
9293
}
9394

95+
// Successf message
96+
func (s *SimplePrinter) Successf(format string, a ...interface{}) {
97+
Success.Printf(format, a...)
98+
}
99+
100+
// Successln message
101+
func (s *SimplePrinter) Successln(a ...interface{}) {
102+
Success.Println(a...)
103+
}
104+
94105
// Infof message
95106
func (s *SimplePrinter) Infof(format string, a ...interface{}) {
96107
Info.Printf(format, a...)

0 commit comments

Comments
 (0)