mirror of
https://github.com/docker/compose.git
synced 2025-07-28 08:04:09 +02:00
Efficiency of ansiColorCode function
Signed-off-by: keitosuwahara <keitosuwahara0816@gmail.com>
This commit is contained in:
parent
95660c5e5a
commit
fb5a8644c3
@ -19,6 +19,7 @@ package formatter
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
@ -91,11 +92,15 @@ func ansiColor(code, s string, formatOpts ...string) string {
|
|||||||
|
|
||||||
// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
|
// Everything about ansiColorCode color https://hyperskill.org/learn/step/18193
|
||||||
func ansiColorCode(code string, formatOpts ...string) string {
|
func ansiColorCode(code string, formatOpts ...string) string {
|
||||||
res := "\033["
|
var sb strings.Builder
|
||||||
|
sb.WriteString("\033[")
|
||||||
for _, c := range formatOpts {
|
for _, c := range formatOpts {
|
||||||
res = fmt.Sprintf("%s%s;", res, c)
|
sb.WriteString(c)
|
||||||
|
sb.WriteString(";")
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%sm", res, code)
|
sb.WriteString(code)
|
||||||
|
sb.WriteString("m")
|
||||||
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeColorFunc(code string) colorFunc {
|
func makeColorFunc(code string) colorFunc {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user