Skip to content

Commit c0a8b52

Browse files
committed
{type}:chore: replace all interface{} type to any
1 parent b564cab commit c0a8b52

12 files changed

+294
-234
lines changed

_examples/ref/idea.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func NewLog(fields map[string]string) *Logger {
2121
}
2222

2323
// Info log message
24-
func (l *Logger) Info(args ...interface{}) {
24+
func (l *Logger) Info(args ...any) {
2525

2626
}
2727

2828
// Log message
29-
func (l *Logger) Log(args ...interface{}) {
29+
func (l *Logger) Log(args ...any) {
3030

3131
}

color.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func InnerErrs() []error {
183183
// Usage:
184184
//
185185
// msg := RenderCode("3;32;45", "some", "message")
186-
func RenderCode(code string, args ...interface{}) string {
186+
func RenderCode(code string, args ...any) string {
187187
var message string
188188
if ln := len(args); ln == 0 {
189189
return ""
@@ -205,7 +205,7 @@ func RenderCode(code string, args ...interface{}) string {
205205

206206
// RenderWithSpaces Render code with spaces.
207207
// If the number of args is > 1, a space will be added between the args
208-
func RenderWithSpaces(code string, args ...interface{}) string {
208+
func RenderWithSpaces(code string, args ...any) string {
209209
msg := formatArgsForPrintln(args)
210210
if len(code) == 0 {
211211
return msg

color_16.go

+31-24
Original file line numberDiff line numberDiff line change
@@ -188,57 +188,65 @@ func (c Color) Text(message string) string { return RenderString(c.String(), mes
188188
// Render messages by color setting
189189
//
190190
// Usage:
191-
// green := color.FgGreen.Render
192-
// fmt.Println(green("message"))
193-
func (c Color) Render(a ...interface{}) string { return RenderCode(c.String(), a...) }
191+
//
192+
// green := color.FgGreen.Render
193+
// fmt.Println(green("message"))
194+
func (c Color) Render(a ...any) string { return RenderCode(c.String(), a...) }
194195

195196
// Renderln messages by color setting.
196197
// like Println, will add spaces for each argument
197198
//
198199
// Usage:
199-
// green := color.FgGreen.Renderln
200-
// fmt.Println(green("message"))
201-
func (c Color) Renderln(a ...interface{}) string { return RenderWithSpaces(c.String(), a...) }
200+
//
201+
// green := color.FgGreen.Renderln
202+
// fmt.Println(green("message"))
203+
func (c Color) Renderln(a ...any) string { return RenderWithSpaces(c.String(), a...) }
202204

203205
// Sprint render messages by color setting. is alias of the Render()
204-
func (c Color) Sprint(a ...interface{}) string { return RenderCode(c.String(), a...) }
206+
func (c Color) Sprint(a ...any) string { return RenderCode(c.String(), a...) }
205207

206208
// Sprintf format and render message.
207209
//
208210
// Usage:
209-
// green := color.Green.Sprintf
210-
// colored := green("message")
211-
func (c Color) Sprintf(format string, args ...interface{}) string {
211+
//
212+
// green := color.Green.Sprintf
213+
// colored := green("message")
214+
func (c Color) Sprintf(format string, args ...any) string {
212215
return RenderString(c.String(), fmt.Sprintf(format, args...))
213216
}
214217

215218
// Print messages.
216219
//
217220
// Usage:
218-
// color.Green.Print("message")
221+
//
222+
// color.Green.Print("message")
223+
//
219224
// OR:
220-
// green := color.FgGreen.Print
221-
// green("message")
222-
func (c Color) Print(args ...interface{}) {
225+
//
226+
// green := color.FgGreen.Print
227+
// green("message")
228+
func (c Color) Print(args ...any) {
223229
doPrintV2(c.Code(), fmt.Sprint(args...))
224230
}
225231

226232
// Printf format and print messages.
227233
//
228234
// Usage:
229-
// color.Cyan.Printf("string %s", "arg0")
230-
func (c Color) Printf(format string, a ...interface{}) {
235+
//
236+
// color.Cyan.Printf("string %s", "arg0")
237+
func (c Color) Printf(format string, a ...any) {
231238
doPrintV2(c.Code(), fmt.Sprintf(format, a...))
232239
}
233240

234241
// Println messages with new line
235-
func (c Color) Println(a ...interface{}) { doPrintlnV2(c.String(), a) }
242+
func (c Color) Println(a ...any) { doPrintlnV2(c.String(), a) }
236243

237244
// Light current color. eg: 36(FgCyan) -> 96(FgLightCyan).
238245
//
239246
// Usage:
240-
// lightCyan := Cyan.Light()
241-
// lightCyan.Print("message")
247+
//
248+
// lightCyan := Cyan.Light()
249+
// lightCyan.Print("message")
242250
func (c Color) Light() Color {
243251
val := int(c)
244252
if val >= 30 && val <= 47 {
@@ -252,8 +260,9 @@ func (c Color) Light() Color {
252260
// Darken current color. eg. 96(FgLightCyan) -> 36(FgCyan)
253261
//
254262
// Usage:
255-
// cyan := LightCyan.Darken()
256-
// cyan.Print("message")
263+
//
264+
// cyan := LightCyan.Darken()
265+
// cyan.Print("message")
257266
func (c Color) Darken() Color {
258267
val := int(c)
259268
if val >= 90 && val <= 107 {
@@ -461,9 +470,7 @@ func Fg2Bg(val uint8) uint8 {
461470
}
462471

463472
// Basic2nameMap data
464-
func Basic2nameMap() map[uint8]string {
465-
return basic2nameMap
466-
}
473+
func Basic2nameMap() map[uint8]string { return basic2nameMap }
467474

468475
// func initName2basicMap() map[string]uint8 {
469476
// n2b := make(map[string]uint8, len(basic2nameMap))

color_256.go

+29-23
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ from wikipedia, 256 color:
1919
// tpl for 8 bit 256 color(`2^8`)
2020
//
2121
// format:
22-
// ESC[ … 38;5;<n> … m // 选择前景色
23-
// ESC[ … 48;5;<n> … m // 选择背景色
22+
//
23+
// ESC[ … 38;5;<n> … m // 选择前景色
24+
// ESC[ … 48;5;<n> … m // 选择背景色
2425
//
2526
// example:
26-
// fg "\x1b[38;5;242m"
27-
// bg "\x1b[48;5;208m"
28-
// both "\x1b[38;5;242;48;5;208m"
27+
//
28+
// fg "\x1b[38;5;242m"
29+
// bg "\x1b[48;5;208m"
30+
// both "\x1b[38;5;242;48;5;208m"
2931
//
3032
// links:
31-
// https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位
33+
//
34+
// https://zh.wikipedia.org/wiki/ANSI%E8%BD%AC%E4%B9%89%E5%BA%8F%E5%88%97#8位
3235
const (
3336
TplFg256 = "38;5;%d"
3437
TplBg256 = "48;5;%d"
@@ -45,12 +48,14 @@ const (
4548
// 颜色值使用10进制和16进制都可 0x98 = 152
4649
//
4750
// The color consists of two uint8:
48-
// 0: color value
49-
// 1: color type; Fg=0, Bg=1, >1: unset value
51+
//
52+
// 0: color value
53+
// 1: color type; Fg=0, Bg=1, >1: unset value
5054
//
5155
// example:
52-
// fg color: [152, 0]
53-
// bg color: [152, 1]
56+
//
57+
// fg color: [152, 0]
58+
// bg color: [152, 1]
5459
//
5560
// NOTICE: now support 256 color on windows CMD, PowerShell
5661
// lint warn - Name starts with package name
@@ -87,27 +92,27 @@ func (c Color256) Reset() error {
8792
}
8893

8994
// Print print message
90-
func (c Color256) Print(a ...interface{}) {
95+
func (c Color256) Print(a ...any) {
9196
doPrintV2(c.String(), fmt.Sprint(a...))
9297
}
9398

9499
// Printf format and print message
95-
func (c Color256) Printf(format string, a ...interface{}) {
100+
func (c Color256) Printf(format string, a ...any) {
96101
doPrintV2(c.String(), fmt.Sprintf(format, a...))
97102
}
98103

99104
// Println print message with newline
100-
func (c Color256) Println(a ...interface{}) {
105+
func (c Color256) Println(a ...any) {
101106
doPrintlnV2(c.String(), a)
102107
}
103108

104109
// Sprint returns rendered message
105-
func (c Color256) Sprint(a ...interface{}) string {
110+
func (c Color256) Sprint(a ...any) string {
106111
return RenderCode(c.String(), a...)
107112
}
108113

109114
// Sprintf returns format and rendered message
110-
func (c Color256) Sprintf(format string, a ...interface{}) string {
115+
func (c Color256) Sprintf(format string, a ...any) string {
111116
return RenderString(c.String(), fmt.Sprintf(format, a...))
112117
}
113118

@@ -206,9 +211,10 @@ type Style256 struct {
206211
// S256 create a color256 style
207212
//
208213
// Usage:
209-
// s := color.S256()
210-
// s := color.S256(132) // fg
211-
// s := color.S256(132, 203) // fg and bg
214+
//
215+
// s := color.S256()
216+
// s := color.S256(132) // fg
217+
// s := color.S256(132, 203) // fg and bg
212218
func S256(fgAndBg ...uint8) *Style256 {
213219
s := &Style256{}
214220
vl := len(fgAndBg)
@@ -256,27 +262,27 @@ func (s *Style256) AddOpts(opts ...Color) *Style256 {
256262
}
257263

258264
// Print message
259-
func (s *Style256) Print(a ...interface{}) {
265+
func (s *Style256) Print(a ...any) {
260266
doPrintV2(s.String(), fmt.Sprint(a...))
261267
}
262268

263269
// Printf format and print message
264-
func (s *Style256) Printf(format string, a ...interface{}) {
270+
func (s *Style256) Printf(format string, a ...any) {
265271
doPrintV2(s.String(), fmt.Sprintf(format, a...))
266272
}
267273

268274
// Println print message with newline
269-
func (s *Style256) Println(a ...interface{}) {
275+
func (s *Style256) Println(a ...any) {
270276
doPrintlnV2(s.String(), a)
271277
}
272278

273279
// Sprint returns rendered message
274-
func (s *Style256) Sprint(a ...interface{}) string {
280+
func (s *Style256) Sprint(a ...any) string {
275281
return RenderCode(s.Code(), a...)
276282
}
277283

278284
// Sprintf returns format and rendered message
279-
func (s *Style256) Sprintf(format string, a ...interface{}) string {
285+
func (s *Style256) Sprintf(format string, a ...any) string {
280286
return RenderString(s.Code(), fmt.Sprintf(format, a...))
281287
}
282288

0 commit comments

Comments
 (0)