From fc1fae7f3e7c8c20f4bb81dbcb64da82b7d7a95e Mon Sep 17 00:00:00 2001 From: DerZyklop Date: Sat, 27 Jul 2019 14:13:03 +0200 Subject: [PATCH 1/4] added --inverted (see denilsonsa#21) --- prettyping | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/prettyping b/prettyping index 8a22efd..808a7b1 100755 --- a/prettyping +++ b/prettyping @@ -54,6 +54,7 @@ prettyping parameters: --[no]unicode Enable/disable unicode characters. (default: enabled) --[no]legend Enable/disable the latency legend. (default: enabled) --[no]terminal Force the output designed to a terminal. (default: auto) + --inverted Invert the output. Only works well in combination with --nomulticolor (default: disabled) --last Use the last "n" pings at the statistics line. (default: 60) --columns Override auto-detection of terminal dimensions. --lines Override auto-detection of terminal dimensions. @@ -81,6 +82,7 @@ parse_arguments() { USE_MULTICOLOR=1 USE_UNICODE=1 USE_LEGEND=1 + INVERTED_OUTPUT=0 if [ -t 1 ]; then IS_TERMINAL=1 @@ -144,6 +146,7 @@ parse_arguments() { -nounicode | --nounicode ) USE_UNICODE=0 ;; -legend | --legend ) USE_LEGEND=1 ;; -nolegend | --nolegend ) USE_LEGEND=0 ;; + -inverted | --inverted ) INVERTED_OUTPUT=1 ;; -terminal | --terminal ) IS_TERMINAL=1 ;; -noterminal | --noterminal ) IS_TERMINAL=0 ;; @@ -165,6 +168,12 @@ parse_arguments() { shift done + if [ ${USE_MULTICOLOR} -eq 1 ]; then + COLOR='\033[0;31m' + NC='\033[0m' # No Color + printf "\n${COLOR}NOTE: --inverted does not play well without --nomulticolor${NC}\nMore Info: https://github.com/denilsonsa/prettyping/issues/21\n\n" + fi + if [[ "${RTT_MIN}" -gt 0 && "${RTT_MAX}" -gt 0 && "${RTT_MIN}" -ge "${RTT_MAX}" ]] ; then echo "${MYNAME}: Invalid --rttmin and -rttmax values." exit 1 @@ -455,13 +464,26 @@ function print_response_legend(i, n, w) { # block_index is just a local variable. function print_received_response(rtt, block_index) { - if ( rtt < BLOCK_RTT_MIN ) { - block_index = 0 - } else if ( rtt >= BLOCK_RTT_MAX ) { - block_index = BLOCK_LEN - 1 + + if ( '"${INVERTED_OUTPUT}"' ) { + if ( rtt < BLOCK_RTT_MIN ) { + block_index = int(BLOCK_LEN - 2) + } else if ( rtt >= BLOCK_RTT_MAX ) { + block_index = 0 + } else { + # block_index = 1 + int((BLOCK_LEN - 2) - ((rtt - BLOCK_RTT_MIN) * (BLOCK_LEN - 2) / (BLOCK_RTT_RANGE))) + block_index = int((BLOCK_LEN - 2) - ((rtt - BLOCK_RTT_MIN) * (BLOCK_LEN - 2) / (BLOCK_RTT_RANGE))) + } } else { - block_index = 1 + int((rtt - BLOCK_RTT_MIN) * (BLOCK_LEN - 2) / BLOCK_RTT_RANGE) + if ( rtt < BLOCK_RTT_MIN ) { + block_index = 0 + } else if ( rtt >= BLOCK_RTT_MAX ) { + block_index = BLOCK_LEN - 1 + } else { + block_index = 1 + int((rtt - BLOCK_RTT_MIN) * (BLOCK_LEN - 2) / BLOCK_RTT_RANGE) + } } + printf( BLOCK[block_index] ) CURR_COL++ } From 97651cf7cee635fa576cc8eda27db2d15b9a5044 Mon Sep 17 00:00:00 2001 From: DerZyklop Date: Sun, 28 Jul 2019 13:42:42 +0200 Subject: [PATCH 2/4] fixed --inverted warning condition --- prettyping | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prettyping b/prettyping index 808a7b1..54c7174 100755 --- a/prettyping +++ b/prettyping @@ -168,7 +168,7 @@ parse_arguments() { shift done - if [ ${USE_MULTICOLOR} -eq 1 ]; then + if [ ${USE_MULTICOLOR} -eq 1 -a ${INVERTED_OUTPUT} -eq 1 ]; then COLOR='\033[0;31m' NC='\033[0m' # No Color printf "\n${COLOR}NOTE: --inverted does not play well without --nomulticolor${NC}\nMore Info: https://github.com/denilsonsa/prettyping/issues/21\n\n" From 864223bbbf1eb9e120e88fd9f757ba903e6a412c Mon Sep 17 00:00:00 2001 From: DerZyklop Date: Sun, 28 Jul 2019 15:47:48 +0200 Subject: [PATCH 3/4] fixed some spacing issues in the help output --- prettyping | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prettyping b/prettyping index 54c7174..8352885 100755 --- a/prettyping +++ b/prettyping @@ -54,7 +54,7 @@ prettyping parameters: --[no]unicode Enable/disable unicode characters. (default: enabled) --[no]legend Enable/disable the latency legend. (default: enabled) --[no]terminal Force the output designed to a terminal. (default: auto) - --inverted Invert the output. Only works well in combination with --nomulticolor (default: disabled) + --inverted Invert the output. Only works well in combination with --nomulticolor (default: disabled) --last Use the last "n" pings at the statistics line. (default: 60) --columns Override auto-detection of terminal dimensions. --lines Override auto-detection of terminal dimensions. From 6e2470897ff120b335ae3739b4e52f852cf18f79 Mon Sep 17 00:00:00 2001 From: DerZyklop Date: Sun, 28 Jul 2019 15:52:14 +0200 Subject: [PATCH 4/4] Make inverted warning more consistent with the other warnings --- prettyping | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prettyping b/prettyping index 8352885..145d638 100755 --- a/prettyping +++ b/prettyping @@ -171,7 +171,9 @@ parse_arguments() { if [ ${USE_MULTICOLOR} -eq 1 -a ${INVERTED_OUTPUT} -eq 1 ]; then COLOR='\033[0;31m' NC='\033[0m' # No Color - printf "\n${COLOR}NOTE: --inverted does not play well without --nomulticolor${NC}\nMore Info: https://github.com/denilsonsa/prettyping/issues/21\n\n" + echo "${MYNAME}: --inverted does not play well without --nomulticolor" + echo "More Info: https://github.com/denilsonsa/prettyping/issues/21" + exit 1 fi if [[ "${RTT_MIN}" -gt 0 && "${RTT_MAX}" -gt 0 && "${RTT_MIN}" -ge "${RTT_MAX}" ]] ; then