Skip to content

Commit

Permalink
Merge pull request #63 from coursehero/62-keep-latest-color-in-streaming
Browse files Browse the repository at this point in the history
Keep the latest matched color in the streaming mode
  • Loading branch information
vipulgagrani committed Nov 12, 2019
2 parents 817ee81 + 38d2060 commit cc54554
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 11 additions & 1 deletion slacktee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=""
Expand Down
7 changes: 5 additions & 2 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cc54554

Please sign in to comment.