diff options
-rw-r--r-- | src/printer.go | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/src/printer.go b/src/printer.go index 103ff00..5720897 100644 --- a/src/printer.go +++ b/src/printer.go @@ -8,6 +8,7 @@ import ( // printResponse reads a response from the printChannel, formats it and prints it func printResponses(channels channels) { var i int + for { // read a response from the printChannel for further usage response := <-channels.printChannel @@ -17,110 +18,94 @@ func printResponses(channels channels) { var postfix string var prefix string - // define what color should be used to print the individual status - // codes - var statusCode string - - var color string + // hidden defines if the value should be displayed (normally a 200 + // status code) or hidden (gets printed, but the next entry overwrites the + // line + var hidden bool // hide some of the requests, filter using the status code for _, codeToHide := range hide.HideCode { if response.StatusCode == codeToHide { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } else { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } } for _, linesToHide := range hide.HideLine { if response.ResponseLines == linesToHide { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } else { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } } for _, wordsToHide := range hide.HideWord { if response.ResponseWords == wordsToHide { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } else { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } } for _, charsToHide := range hide.HideChar { if response.ResponseChars == charsToHide { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } else { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } } // show some of the requests, filter using the status code for _, codeToShow := range show.ShowCode { if response.StatusCode == codeToShow { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } else { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } } for _, linesToShow := range show.ShowLine { if response.ResponseLines == linesToShow { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } else { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } } for _, wordsToShow := range show.ShowWord { if response.ResponseWords == wordsToShow { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } else { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } } for _, charsToShow := range show.ShowChar { if response.ResponseChars == charsToShow { - prefix = "\r\033[K" - postfix = "\n" - color = "green" + hidden = false } else { - prefix = "" - postfix = "\033[K\r" - color = "red" + hidden = true } } + // color to display the status code in (either green or red) + var color string + + // set the prefix, postfix and color according to the hidden state + if hidden == true { + prefix = "" + postfix = "\033[K\r" + color = "red" + } else { + prefix = "\r\033[K" + postfix = "\n" + color = "green" + } + + // statusCode string (with ansi escape codes) + var statusCode string + // color if color == "red" { statusCode = red(fmt.Sprintf("%d", response.StatusCode)) |