-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
96 lines (82 loc) · 2.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package cfmt
import (
"fmt"
"io"
"os"
"github.com/i582/cfmt/internal"
)
// RegisterStyle registers a new custom style.
//
// It will look like this:
//
// cfmt.RegisterStyle("code", func(s string) string {
// return cfmt.Sprintf("{{%s}}::red|underline", s)
// })
//
// The first argument is the name by which this style will be used,
// and the second is the styling function itself.
func RegisterStyle(name string, fn func(string) string) {
internal.CustomMap[name] = func(f func(text string) string) func(text string) string {
return func(text string) string {
t := f(text)
t = fn(t)
return t
}
}
}
// Sprint is the same as fmt.
func Sprint(a ...interface{}) string {
text := fmt.Sprint(a...)
parsed := internal.Parse(text)
return parsed
}
// Fprint is the same as fmt.
func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
text := Sprint(a...)
return fmt.Fprint(w, text)
}
// Print is the same as fmt.
func Print(a ...interface{}) (n int, err error) {
return Fprint(os.Stdout, a...)
}
// Sprintln is the same as fmt.
func Sprintln(a ...interface{}) string {
return Sprint(a...) + "\n"
}
// Fprintln is the same as fmt.
func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
text := Sprintln(a...)
return fmt.Fprint(w, text)
}
// Println is the same as fmt.
func Println(a ...interface{}) (n int, err error) {
return Fprintln(os.Stdout, a...)
}
// Sprintf is the same as fmt.
func Sprintf(format string, a ...interface{}) string {
text := fmt.Sprintf(format, a...)
parsed := internal.Parse(text)
return parsed
}
// Fprintf is the same as fmt.
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
text := Sprintf(format, a...)
return fmt.Fprint(w, text)
}
// Printf is the same as fmt.
func Printf(format string, a ...interface{}) (n int, err error) {
text := Sprintf(format, a...)
return fmt.Print(text)
}
// Fatalf is the same as fmt.
func Fatalf(format string, a ...interface{}) {
text := Sprintf(format, a...)
fmt.Print(text)
os.Exit(1)
}
// Fatal is the same as fmt.
func Fatal(a ...interface{}) {
text := Sprint(a...)
fmt.Print(text)
os.Exit(1)
}