Anonymous avatar Anonymous committed b63b951

more restrictive color usage, add self and notices to color_cache, hack so leading whitespace shows (I really need to write this in not bash)

Comments (0)

Files changed (1)

extras/cw_color.sh

 # NOTE: make sure you have a 256 color terminal, or change these options
 # to find out which colors are readable...
 # for i in {0..255}; do echo $(tput setaf $i) $i foobar baz qux; done
-colors=({9..11} 13 {29..51} {62..87} 99 {105..123} {130..159} {165..231})
+colors=({29..51} {62..87} 99 {105..123} {129..159} {165..231})
 declare -A color_cache
 
 reset="$(tput sgr0)"
 	shift 2
 done
 
+color_cache["-!-"]="$notice_fmt"
+color_cache["${NICK%_}"]="$my_line_fmt"
+
 set_format() {
-	if [ "$*" = "-!-" ]; then
-		format="$notice_fmt"
-	elif [ "${*%_}" = "$NICK" ]; then
-		format="$my_line_fmt"
-	elif [ -n "${color_cache["$*"]}" ]; then
-		format=${color_cache["$*"]}
+	if [ -n "${color_cache["${*%_}"]}" ]; then
+		format=${color_cache["${*%_}"]}
 	else
 		chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
 		chksm=$((chksm % ${#colors[@]}))
 }
 
 cw "${IN:?no -i infile specified}" "${OUT:?no -o outfile specified}" |
-while read -r date time nick msg; do
+while read -r date time nick_msg; do
+	nick=${nick_msg%% *}
+	nick=${nick%>}
 	nick=${nick#<}
-	nick=${nick%>}
+	msg=${nick_msg#* }
 
 	if [ "$date" = "SIZE" ]; then
 		cols=$nick
 	nick=$(printf "%s%${PAD}s%s |%s" "$format" "$nick" "$reset" "$format")
 
 	first=1
+	oIFS="$IFS"
+	IFS="\n"
 	echo "$msg" | fmt -w $((cols - head_len - 1)) -s |
 	while read -r line; do
 		line=${line//$NICK/$reset$my_nick_fmt$NICK$reset$format}
 			printf "%${head_len}s| %s\n" "" "$format$line$reset"
 		fi
 	done
+	IFS="$oIFS"
 done
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.