-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
55 lines (48 loc) · 1.23 KB
/
message.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
package tcl
import (
"strings"
c "github.com/fatih/color"
)
// Message let's you print a title along with a message to the console.
// With the color parameter, you can specify the background color of the title.
// This is useful if you want to underline a result of a action that was taken,
// for example a green message after a successful action.
// The possible and allowed colors are:
// - black
// - blue
// - cyan
// - green
// - magenta
// - red
// - white
// - yellow
// If you don't specify a valid color, a white message will be printed.
func Message(title string, message string, color string) {
titleColor := c.New(c.FgBlack)
messageColor := c.New(c.Italic)
switch strings.ToLower(color) {
case "black":
titleColor.Add(c.BgBlack, c.FgWhite)
case "blue":
titleColor.Add(c.BgBlue)
case "cyan":
titleColor.Add(c.BgCyan)
case "green":
titleColor.Add(c.BgGreen)
case "magenta":
titleColor.Add(c.BgMagenta)
case "red":
titleColor.Add(c.BgRed)
case "white":
titleColor.Add(c.BgWhite)
case "yellow":
titleColor.Add(c.BgYellow)
default:
titleColor.Add(c.BgWhite)
}
NewLines(1)
indent(0)
titleColor.Printf(" %s ", strings.ToUpper(title))
messageColor.Printf(" > %s\n", message)
NewLines(1)
}