From 8be34101c627352733713dbb1d4856767d523f97 Mon Sep 17 00:00:00 2001 From: Gustavo Paiva Date: Mon, 7 Oct 2019 23:01:05 -0300 Subject: [PATCH] escape text to not misinterpret it with colors. --- internal/views/yaml.go | 4 +++- internal/views/yaml_test.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/views/yaml.go b/internal/views/yaml.go index 7c3167f6..0795d5bf 100644 --- a/internal/views/yaml.go +++ b/internal/views/yaml.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "github.com/derailed/tview" + "github.com/derailed/k9s/internal/config" "github.com/rs/zerolog/log" ) @@ -24,7 +26,7 @@ const ( ) func colorizeYAML(style config.Yaml, raw string) string { - lines := strings.Split(raw, "\n") + lines := strings.Split(tview.Escape(raw), "\n") fullFmt := strings.Replace(yamlFullFmt, "[key", "["+style.KeyColor, 1) fullFmt = strings.Replace(fullFmt, "[colon", "["+style.ColonColor, 1) diff --git a/internal/views/yaml_test.go b/internal/views/yaml_test.go index 340b32aa..860fed2b 100644 --- a/internal/views/yaml_test.go +++ b/internal/views/yaml_test.go @@ -43,6 +43,10 @@ func TestYaml(t *testing.T) { "certmanager.k8s.io/cluster-issuer: nameOfClusterIssuer", "[steelblue::b]certmanager.k8s.io/cluster-issuer[white::-]: [papayawhip::]nameOfClusterIssuer", }, + { + "Message: Pod The node was low on resource: [DiskPressure].", + "[steelblue::b]Message[white::-]: [papayawhip::]Pod The node was low on resource: [DiskPressure[].", + }, } s, _ := config.NewStyles("skins/stock.yml")