From 38d206007e7df9d240b67fc3bc8b73509b8a7c29 Mon Sep 17 00:00:00 2001 From: Chuck Kato Date: Mon, 11 Nov 2019 18:27:39 -0800 Subject: [PATCH] Keep the latest matched color in the streaming mode --- slacktee.sh | 12 +++++++++++- test/test.sh | 7 +++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/slacktee.sh b/slacktee.sh index 1ac707a..58f0260 100755 --- a/slacktee.sh +++ b/slacktee.sh @@ -325,6 +325,13 @@ function process_line() fi fi elif [[ $mode == "streaming" ]]; then + # Keep the latest matched pattern and use it for sending message + # "$attachment" is the default value + if [[ -z $last_found_pattern_color || $found_pattern_color != "$attachment" ]]; then + last_found_pattern_color=$found_pattern_color + fi + found_pattern_color=$last_found_pattern_color + if [[ -z "$text" ]]; then text="$line" else @@ -787,8 +794,11 @@ function main() if [[ "$mode" == "buffering" ]]; then send_message "$text" elif [[ "$mode" == "streaming" ]]; then + # Unset last updated time for flashing buffer unset streaming_last_update - send_message "$text" + # Use the latest matched color + found_pattern_color=$last_found_pattern_color + send_message "$text" elif [[ "$mode" == "file" ]]; then if [[ -s "$filename" ]]; then channels_param="" diff --git a/test/test.sh b/test/test.sh index 15459d7..c4da161 100755 --- a/test/test.sh +++ b/test/test.sh @@ -189,13 +189,16 @@ cat $DATA | $SLACKTEE '--no-output' '-t' 'Suppress the standard output (--no-out # Test 22: Streaming mode - test payload is properly escaped echo "hello ampersand &, equals =, quote ', and double quote \", please don't break my payload." | $SLACKTEE --streaming --streaming-batch-time 2 -# Test 23: Newlines show correctly +# Test 23: Streaming mode - use the latest color +(echo "normal"; sleep 1; echo "caution"; sleep 1; echo "failure"; sleep 1; echo "normal"; sleep 1; echo "alright") | $SLACKTEE --streaming -o "warning" "caution" -o "danger" "failure" -o "good" "alright" + +# Test 24: Newlines show correctly echo -e "--streaming line one\n\nline three" | $SLACKTEE --streaming echo -e "--streaming -p line one\n\nline three" | $SLACKTEE --streaming -p echo -e "line one\n\nline three" | $SLACKTEE echo -e "-p line one\n\nline three" | $SLACKTEE -p -# Test 24: Long messages +# Test 25: Long messages long_message=$(printf '.%.0s' {1..5000}) echo $long_message | $SLACKTEE -p # should be split up over two messages # these do not work correctly. Fixing seems complicated, and it's an edge case, so let's just document it here