Commits

Anonymous committed 828493a

update cw_color.sh quite a bit, lots of colors, sadly quite slow, what to do about that?

Comments (0)

Files changed (1)

-#!/bin/sh
+#!/bin/bash
 
-PAD=10
+PAD=12
 NICK=emg
 
+colors=(21 {26..51} {57..87} {93..123} {128..159} {164..231})
+
 reset="$(tput sgr0)"
 bold="$(tput bold)"
 black="$(tput setaf 0)"
-red="$(tput setaf 1)"
+red="$(tput setaf 196)"
 magenta="$(tput setaf 5)"
 
 me_fmt="${red}\a"
 
+format=""
+cols=""
+
 while [ $# -gt 0 ]; do
 	case $1 in
 		-i) IN="$2"
 	shift 2
 done
 
-print_nick () {
+set_format() {
 	chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
-	chksm=$((chksm % 173 + 58))
-	printf "%s%${PAD}s%s |" "$(tput setaf $chksm)" "$*" "$reset"
+	chksm=$((chksm % ${#colors[@]}))
+	format="$(tput setaf ${colors[$chksm]})"
 }
 
-print_info() {
-	echo -n "${bold}${black}$*${reset}"
-}
 
 cw "${IN:?no -i infile specified}" "${OUT:?no -o outfile specified}" |
 while read date time nick msg; do
 	nick=${nick#<}
 	nick=${nick%>}
 
-	time=$(print_info "$time")
+	if [ ${#nick} -lt $PAD ]; then
+		head_len=$(($PAD + ${#time} + 2))
+	else
+		head_len=$((${#nick} + ${#time} + 2))
+	fi
+
+	if [ "$date" = "SIZE" ]; then
+		cols=$nick
+		continue
+	fi
+
+	time="${bold}${black}${time}${reset}"
 
 	if [ "$nick" = "-!-" ]; then
-		nick=$(printf "%s%$((PAD + 3))s" "${bold}${black}" "$nick")
+		format="${bold}${black}"
+		nick=$(printf "%s%$((PAD + 3))s" "$format" "$nick")
 	else
-		nick=$(print_nick "$nick")
+		set_format "$nick"
+		nick=$(printf "%s%${PAD}s%s |%s" "$format" "$nick" "$reset" "$format")
 	fi
 
-	echo "$time" "$nick" "${msg}${reset}"
-done | sed "/|/s/$NICK/$me_fmt&$reset/g; /ACTION/s/| ACTION \(.*\)/${magenta}***${reset} \1/"
+	first=1
+	echo $msg | fmt -$((cols - head_len - 1)) -s |
+	while read line; do
+		if [ -n "$first" ]; then
+			printf "%s %s %s\n" "$time" "$nick" "$line$reset"
+			first=""
+		else
+			printf "%${head_len}s| %s\n" "" "$format$line$reset"
+		fi
+	done | sed "/$NICK/s/$NICK/${reset}${me_fmt}&${format}/g; /ACTION/s/|.*ACTION \(.*\)/${reset}***${format} \1/"
+done