add format management for command-line commands

This commit is contained in:
Adrien Marquès 2018-07-07 12:41:15 +02:00
parent f0aa6d2c5c
commit fb169b0a10
2 changed files with 33 additions and 0 deletions

13
clifmt/colors.go Normal file
View File

@ -0,0 +1,13 @@
package clifmt
import (
"fmt"
)
func Color(color byte, s string, bold ...bool) string {
b := "0"
if len(bold) > 0 && bold[0] {
b = "1"
}
return fmt.Sprintf("\033[%s;%dm%s\033[0m", b, color, s)
}

20
clifmt/symbols.go Normal file
View File

@ -0,0 +1,20 @@
package clifmt
import (
"fmt"
)
func Warn(s ...string) string {
if len(s) == 0 {
return Color(31, "/!\\")
}
return fmt.Sprintf("%s %s", Warn(), s[0])
}
func Info(s ...string) string {
if len(s) == 0 {
return Color(34, "(!)")
}
return fmt.Sprintf("%s %s", Info(), s[0])
}