-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
124 lines (109 loc) · 2.73 KB
/
output.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* Copyright (c) 2023 Brandon Jordan
*/
package ttuy
import (
"fmt"
"os"
)
func printError(label string, message string) {
label = Style(fmt.Sprintf(" \u2613 %s ", label), BrightRedBg, BlackText, Bold)
message = Style(" "+message, BrightRedText, Bold)
fmt.Println(label + message)
os.Exit(1)
}
// Fail prints message styled as an error then exits
func Fail(message string) {
printError("Error", message)
}
// Failf prints message formatted and styled as an error then exits
func Failf(message string, v ...any) {
printError("Error", fmt.Sprintf(message, v...))
}
// FailErr handles err and prints label with err as a string styled then exits
func FailErr(label string, err error) {
if err != nil {
printError(label, fmt.Sprintf("%s", err))
}
}
// Warn prints message styled as a warning
func Warn(message string) {
var label = Style(" \u2691 Warning ", YellowBg, BlackText, Bold)
message = Style(" "+message, YellowText, Bold)
fmt.Println(label + message)
}
// Warnf prints message formatted and styled as a warning
func Warnf(message string, v ...any) {
message = fmt.Sprintf(message, v...)
Warn(message)
}
// Info prints message highlighted
func Info(message string) {
message = Style(message, BlueText, Bold)
fmt.Println(message)
}
// Infof prints message formatted and highlighted
func Infof(message string, v ...any) {
message = fmt.Sprintf(message, v...)
Info(message)
}
// Success prints message styled as a success
func Success(message string) {
var label = Style(" \u2714 ", GreenBg, BlackText, Bold)
message = Style(" "+message, GreenText, Bold)
fmt.Println(label + message)
}
// Successf prints message styled and formatted as a success
func Successf(message string, v ...any) {
Success(fmt.Sprintf(message, v...))
}
// BigBanner returns a box around `message` made of # signs.
// ###########
// # EXAMPLE #
// ###########
func BigBanner(message string) (banner string) {
terminalCols()
banner = "\n"
var spaces = (cols - (len(message) + 2)) / 2
for i := 0; i < cols; i++ {
banner += "#"
}
banner += "\n#"
for i := 0; i < cols-2; i++ {
banner += " "
}
banner += "#\n#"
for i := 0; i < spaces; i++ {
banner += " "
}
banner += message
for i := 0; i < spaces; i++ {
banner += " "
}
banner += " #\n#"
for i := 0; i < cols-2; i++ {
banner += " "
}
banner += "#\n"
for i := 0; i < cols; i++ {
banner += "#"
}
banner += "\n\n"
return
}
// Banner returns a banner around `message` made of # signs.
// ######## EXAMPLE ########
func Banner(message string) (banner string) {
terminalCols()
banner = "\n"
var spaces = (cols - (len(message) + 2)) / 2
for i := 0; i < spaces; i++ {
banner += "#"
}
banner += " " + message + " "
for i := 0; i < spaces-1; i++ {
banner += "#"
}
banner += "#\n\n"
return
}