Skip to content

Commit cc54554

Browse files
authored
Merge pull request #63 from coursehero/62-keep-latest-color-in-streaming
Keep the latest matched color in the streaming mode
2 parents 817ee81 + 38d2060 commit cc54554

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

slacktee.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,13 @@ function process_line()
325325
fi
326326
fi
327327
elif [[ $mode == "streaming" ]]; then
328+
# Keep the latest matched pattern and use it for sending message
329+
# "$attachment" is the default value
330+
if [[ -z $last_found_pattern_color || $found_pattern_color != "$attachment" ]]; then
331+
last_found_pattern_color=$found_pattern_color
332+
fi
333+
found_pattern_color=$last_found_pattern_color
334+
328335
if [[ -z "$text" ]]; then
329336
text="$line"
330337
else
@@ -787,8 +794,11 @@ function main()
787794
if [[ "$mode" == "buffering" ]]; then
788795
send_message "$text"
789796
elif [[ "$mode" == "streaming" ]]; then
797+
# Unset last updated time for flashing buffer
790798
unset streaming_last_update
791-
send_message "$text"
799+
# Use the latest matched color
800+
found_pattern_color=$last_found_pattern_color
801+
send_message "$text"
792802
elif [[ "$mode" == "file" ]]; then
793803
if [[ -s "$filename" ]]; then
794804
channels_param=""

test/test.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,16 @@ cat $DATA | $SLACKTEE '--no-output' '-t' 'Suppress the standard output (--no-out
189189
# Test 22: Streaming mode - test payload is properly escaped
190190
echo "hello ampersand &, equals =, quote ', and double quote \", please don't break my payload." | $SLACKTEE --streaming --streaming-batch-time 2
191191

192-
# Test 23: Newlines show correctly
192+
# Test 23: Streaming mode - use the latest color
193+
(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"
194+
195+
# Test 24: Newlines show correctly
193196
echo -e "--streaming line one\n\nline three" | $SLACKTEE --streaming
194197
echo -e "--streaming -p line one\n\nline three" | $SLACKTEE --streaming -p
195198
echo -e "line one\n\nline three" | $SLACKTEE
196199
echo -e "-p line one\n\nline three" | $SLACKTEE -p
197200

198-
# Test 24: Long messages
201+
# Test 25: Long messages
199202
long_message=$(printf '.%.0s' {1..5000})
200203
echo $long_message | $SLACKTEE -p # should be split up over two messages
201204
# these do not work correctly. Fixing seems complicated, and it's an edge case, so let's just document it here

0 commit comments

Comments
 (0)