about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-11-03 02:05:35 +0100
committerEmile <hanemile@protonmail.com>2019-11-03 02:05:35 +0100
commit5331e3c515fe94ee93a733a7a7552a632beab409 (patch)
tree5dc563fb7698c85aeaa0cfc21d1d764b24c57e74 /src
parentc53109c41ca53e8d43c802c6af971a09d129a192 (diff)
filtering show
Diffstat (limited to 'src')
-rw-r--r--src/printer.go72
1 files changed, 67 insertions, 5 deletions
diff --git a/src/printer.go b/src/printer.go
index f02957b..103ff00 100644
--- a/src/printer.go
+++ b/src/printer.go
@@ -23,17 +23,16 @@ func printResponses(channels channels) {
 
 		var color string
 
-		// default values: clear the line, print, newline, green
-		prefix = "\r\033[K"
-		postfix = "\n"
-		color = "green"
-
 		// 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"
+			} else {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
 			}
 		}
 
@@ -42,6 +41,10 @@ func printResponses(channels channels) {
 				prefix = ""
 				postfix = "\033[K\r"
 				color = "red"
+			} else {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
 			}
 		}
 
@@ -50,6 +53,10 @@ func printResponses(channels channels) {
 				prefix = ""
 				postfix = "\033[K\r"
 				color = "red"
+			} else {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
 			}
 		}
 
@@ -58,6 +65,59 @@ func printResponses(channels channels) {
 				prefix = ""
 				postfix = "\033[K\r"
 				color = "red"
+			} else {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
+			}
+		}
+
+		// 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"
+			} else {
+				prefix = ""
+				postfix = "\033[K\r"
+				color = "red"
+			}
+		}
+
+		for _, linesToShow := range show.ShowLine {
+			if response.ResponseLines == linesToShow {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
+			} else {
+				prefix = ""
+				postfix = "\033[K\r"
+				color = "red"
+			}
+		}
+
+		for _, wordsToShow := range show.ShowWord {
+			if response.ResponseWords == wordsToShow {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
+			} else {
+				prefix = ""
+				postfix = "\033[K\r"
+				color = "red"
+			}
+		}
+
+		for _, charsToShow := range show.ShowChar {
+			if response.ResponseChars == charsToShow {
+				prefix = "\r\033[K"
+				postfix = "\n"
+				color = "green"
+			} else {
+				prefix = ""
+				postfix = "\033[K\r"
+				color = "red"
 			}
 		}
 
@@ -66,6 +126,8 @@ func printResponses(channels channels) {
 			statusCode = red(fmt.Sprintf("%d", response.StatusCode))
 		} else if color == "green" {
 			statusCode = green(fmt.Sprintf("%d", response.StatusCode))
+		} else {
+			statusCode = cyan(fmt.Sprintf("%d", response.StatusCode))
 		}
 
 		// print the requests