pkg/jsonmessage: Encode ANSI ESC directly as \x1b rather than via fmt as %c

This seems clearer to me and avoids a miniscule amount of string formatting.

I have deliberately not changed the tests here to avoid the possibility of
changing both wrongly.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
Upstream-commit: 3c233b13a01b9f44e31a158768a06b97a775f095
Component: engine
This commit is contained in:
Ian Campbell
2016-11-11 11:42:38 +00:00
parent d23f15cd3f
commit 4e45b185f6
@@ -127,13 +127,13 @@ func clearLine(out io.Writer, ti termInfo) {
if attr, err := ti.Parse("el1"); err == nil {
fmt.Fprintf(out, "%s", attr)
} else {
fmt.Fprintf(out, "%c[1K", 27)
fmt.Fprintf(out, "\x1b[1K")
}
// Then clear line from cursor to end
if attr, err := ti.Parse("el"); err == nil {
fmt.Fprintf(out, "%s", attr)
} else {
fmt.Fprintf(out, "%c[K", 27)
fmt.Fprintf(out, "\x1b[K")
}
}
@@ -144,7 +144,7 @@ func cursorUp(out io.Writer, ti termInfo, l int) {
if attr, err := ti.Parse("cuu", l); err == nil {
fmt.Fprintf(out, "%s", attr)
} else {
fmt.Fprintf(out, "%c[%dA", 27, l)
fmt.Fprintf(out, "\x1b[%dA", l)
}
}
@@ -155,7 +155,7 @@ func cursorDown(out io.Writer, ti termInfo, l int) {
if attr, err := ti.Parse("cud", l); err == nil {
fmt.Fprintf(out, "%s", attr)
} else {
fmt.Fprintf(out, "%c[%dB", 27, l)
fmt.Fprintf(out, "\x1b[%dB", l)
}
}