Skip to content

Commit

Permalink
Support exclamation mark in topics, too
Browse files Browse the repository at this point in the history
Reason: Topics from meshtastic devices contain an exclamation mark
  • Loading branch information
sheilbronn committed Jan 7, 2024
1 parent 685d5d2 commit 185318f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mqtt-grep-color
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function subsm(s1, s2) {
message=gensub( s1, s3, "g", message)
}
/^[.)(a-z\/A-Z0-9$&%;_+-]{1,255} / { # topics are assumed to have a maximum length of 255, reduces amount of garbage (255 is max on OpenWrt)
/^[.)(a-z\/A-Z0-9$&%;_+!-]{1,255} / { # topics are assumed to have a maximum length of 255, reduces amount of garbage (255 is max on OpenWrt)
g="g"
if ( isJSON && collectedMessage && noColor ) {
# print "*****" ; fflush() ; print collectedMessage # jqcmd # | getline beauty ; print beauty ; system("sleep 1") ;
Expand All @@ -193,25 +193,27 @@ function subsm(s1, s2) {
# fflush() ;
}
isJSON=0
match($0, /^[.)(a-z\/A-Z0-9$&%;_+-]+/)
match($0, /^[.)(a-z\/A-Z0-9$&%;_+!-]+/) # Attention: regexp must be the same as above!
topiclength=RLENGTH
# if ( (imagedatatype != "") && ( topiclength<5 || firstslashpos>topiclength || topiclength==length($0)+1) ) {
topic=sprintf("%-*.*s", minTopicChars, topiclength, $0) # extract the topic, padding it with spaces up to minTopicChars for easier reading
firstslashpos=index(topic, "/")
if (match(topic, /[^[:print:]]/)>0 || (imagedatatype != "" && firstslashpos==0 && topiclength<6) ) {
message=substr($0, topiclength+2, 40) "..."
topic="..skipping..." topic
isToSkip=1
collectedMessage=""
} else {
message=substr($0, topiclength+2, 9999)
imagedatatype=match(message, "^" pngprefix ) ? "PNG" : ( match(message, "^" jpgprefix ) ? "JPEG" : "" )
isJSON=( index(message,"{") == 1 || index(message,"[") == 1) # FIXME: check for "]" at message end, too
isToSkip=0
collectedMessage=message
}
# clean message (=remove non-printables) before printing:
gsub( /[^[:print:]]/ , "", topic )
gsub( /[^[:print:]]/ , "", message )
if ( verbose ) { print "DEBUGMSG(" isJSON "," optimizeJSON "): " message } ## FIXME
if ( verbose ) { print "DEBUGMSG(" isJSON "," isToSkip "," optimizeJSON "): " message } ## FIXME
if ( optimizeJSON ) {
if ( isJSON ) {
Expand Down

0 comments on commit 185318f

Please sign in to comment.