Skip to content

Commit

Permalink
filter: remove Refreshing state... lines from the output (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-knurek authored Sep 23, 2020
1 parent 32cb7ae commit 3318721
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func iterateInput(input io.Reader) {
func processLine(raw string, out io.Writer) {
var toPrint interface{}
cleaned := cleanRawInput(raw)
if len(cleaned) < 1 && len(raw) > 0 {
// filtered text shouldn't print a new line
return
}

trimmed := strings.TrimSpace(cleaned)
if len(trimmed) < 1 {
Expand Down Expand Up @@ -71,5 +75,11 @@ func processLine(raw string, out io.Writer) {
func cleanRawInput(raw string) string {
ansi := "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
re := regexp.MustCompile(ansi)
return re.ReplaceAllString(raw, "")
nocolor := re.ReplaceAllString(raw, "")

refreshing := "Refreshing state... "
if strings.Contains(nocolor, refreshing) {
return ""
}
return nocolor
}
6 changes: 6 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func Test_processLine(t *testing.T) {
want: `+ id = "some string"
`,
},
{
name: "filter refreshing state",
text: "module.apps.kubernetes_config_map.config-map: Refreshing state... [id=id1]",
out: &bytes.Buffer{},
want: "", //no new line
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 3318721

Please sign in to comment.