|
@@ -1,8 +1,8 @@
|
|
package door
|
|
package door
|
|
|
|
|
|
import (
|
|
import (
|
|
- "fmt"
|
|
|
|
"log"
|
|
"log"
|
|
|
|
+ "strconv"
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -13,14 +13,30 @@ import (
|
|
// output.
|
|
// output.
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
|
|
-func Color(arg ...int) string {
|
|
|
|
- var result string = "\x1b["
|
|
|
|
- for i := range arg {
|
|
|
|
- result += fmt.Sprintf("%d;", arg[i])
|
|
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ func Color(arg ...int) string {
|
|
|
|
+ var result string = "\x1b["
|
|
|
|
+ for i := range arg {
|
|
|
|
+ result += fmt.Sprintf("%d;", arg[i])
|
|
|
|
+ }
|
|
|
|
+ result = result[:len(result)-1]
|
|
|
|
+ result += "m"
|
|
|
|
+ return result
|
|
|
|
+ }
|
|
|
|
+*/
|
|
|
|
+
|
|
|
|
+func Color(arg []int) string {
|
|
|
|
+ var result strings.Builder
|
|
|
|
+ result.WriteString("\x1b[")
|
|
|
|
+ for idx, i := range arg {
|
|
|
|
+ if idx != 0 {
|
|
|
|
+ result.WriteString(";")
|
|
|
|
+ }
|
|
|
|
+ result.WriteString(strconv.Itoa(i))
|
|
}
|
|
}
|
|
- result = result[:len(result)-1]
|
|
|
|
- result += "m"
|
|
|
|
- return result
|
|
|
|
|
|
+ result.WriteString("m")
|
|
|
|
+ return result.String()
|
|
}
|
|
}
|
|
|
|
|
|
// BUG(bugz) INVERSE does not work.
|
|
// BUG(bugz) INVERSE does not work.
|
|
@@ -38,7 +54,8 @@ func Color(arg ...int) string {
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
|
|
// https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
|
|
func ColorText(color string) string {
|
|
func ColorText(color string) string {
|
|
// split on spaces, uppercase, match first 3 letter
|
|
// split on spaces, uppercase, match first 3 letter
|
|
- var result []int
|
|
|
|
|
|
+ var res [5]int
|
|
|
|
+ var result []int = res[0:0]
|
|
var bg bool
|
|
var bg bool
|
|
|
|
|
|
result = append(result, 0)
|
|
result = append(result, 0)
|
|
@@ -124,5 +141,5 @@ func ColorText(color string) string {
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
- return Color(result...)
|
|
|
|
|
|
+ return Color(result)
|
|
}
|
|
}
|