From fb169b0a102d2726772128a38c541f50a0840aea Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 7 Jul 2018 12:41:15 +0200 Subject: [PATCH] add format management for command-line commands --- clifmt/colors.go | 13 +++++++++++++ clifmt/symbols.go | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 clifmt/colors.go create mode 100644 clifmt/symbols.go diff --git a/clifmt/colors.go b/clifmt/colors.go new file mode 100644 index 0000000..fc4847d --- /dev/null +++ b/clifmt/colors.go @@ -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) +} diff --git a/clifmt/symbols.go b/clifmt/symbols.go new file mode 100644 index 0000000..24b56f2 --- /dev/null +++ b/clifmt/symbols.go @@ -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]) +}