Commits

Evan Gates  committed 79c4845

don't do fancy wrapping in cw_color.sh, let the terminal do that for us, that means no more ^L to redraw. also colors for all the nicks

  • Participants
  • Parent commits 255e465

Comments (0)

Files changed (1)

File extras/cw_color.sh

 #!/bin/sh
-# Make sure to change NICK to your correct nick and feel free to change the formatting to your liking
-#
+
+PAD=10
+NICK=emg
 
 reset="$(tput sgr0)"
-
 bold="$(tput bold)"
-dim="$(tput dim)"
-under="$(tput smul)"
-ununder="$(tput rmul)"
-blink="$(tput blink)"
-rev="$(tput rev)"
-invis="$(tput invis)"
-
 black="$(tput setaf 0)"
 red="$(tput setaf 1)"
-green="$(tput setaf 2)"
-yellow="$(tput setaf 3)"
-blue="$(tput setaf 4)"
 magenta="$(tput setaf 5)"
-cyan="$(tput setaf 6)"
-white="$(tput setaf 7)"
 
-bg_black="$(tput setab 0)"
-bg_red="$(tput setab 1)"
-bg_green="$(tput setab 2)"
-bg_yellow="$(tput setab 3)"
-bg_blue="$(tput setab 4)"
-bg_magenta="$(tput setab 5)"
-bg_cyan="$(tput setab 6)"
-bg_white="$(tput setab 7)"
-
-date_fmt="$bold$black"
-serv_fmt="$bold$black"
-nick_fmt="$cyan"
-act_fmt="$magenta"
-me_fmt="$red"
-
-NICK="$USER"
+me_fmt="${red}\a"
 
 while [ $# -gt 0 ]; do
 	case $1 in
 		-i) IN="$2"
-			;;
+		   	;;
 		-o) OUT="$2"
 			;;
 		-n) NICK="${2:-$NICK}"
 			;;
 		*)  echo "bad argument $1"
 			exit 2
+			;;
 	esac
 	shift 2
 done
 
-cw "$IN" "$OUT" | awk -v cols="$(tput cols)" -v me="$NICK" -v date_fmt="$date_fmt" -v srv_fmt="$serv_fmt" -v nick_fmt="$nick_fmt" -v me_fmt="$me_fmt" -v act_fmt="$act_fmt" -v reset_fmt="$reset" '{
-FS = "[ ]";
-if ($0 ~ /^[0-9]*;[0-9]*$/) {
-	cols = substr($0, index($0, ";") + 1)
-	next;
-}
-if ($0 ~ /^\033\[/) {
-	print($0);
-	next;
+print_nick () {
+	chksm="$(echo "$*" | cksum | sed "s/^0\+//; s/ .*$//")"
+	chksm=$((chksm % 173 + 58))
+	printf "%s%${PAD}s%s |" "$(tput setaf $chksm)" "$*" "$reset"
 }
 
-sub("<", "", $3);
-sub(">", "", $3);
-$3 = sprintf("%12s", $3);
-
-act  = 0;
-srv  = 0;
-line = $0;
-
-mesg = substr($0, length($1 $2 $3) + 4);
-
-if (match(mesg, "\001ACTION ") == 1) {
-	act = 1;
-	gsub("\001", "", mesg);
-	sub("ACTION", "", mesg);
-} else if (match($3, "-!-") > 0) {
-	srv = 1;
+print_info() {
+	echo -n "${bold}${black}$*${reset}"
 }
 
-while (line != "") {
-	if (line == $0) {
-		if (act == 1)
-			line = sprintf("%s %s%s", $2, $3, mesg);
-		else if (srv == 1)
-			line = sprintf("%s    %s %s", $2, $3, mesg);
-		else
-			line = sprintf("%s %s | %s", $2, $3, mesg);
-		marg = index(line, mesg);
-		str  = substr(line, 1, cols);
-		line = substr(line, cols + 1);
-		first = 1;
-	} else {
-		if (act == 1)
-			str = sprintf("%*s %s%s", marg - 1, "", act_fmt, substr(line, 1, cols - marg + 1));
-		else if (srv == 1)
-			str = sprintf("%*s%s!  %s", marg - 4, "", srv_fmt, substr(line, 1, cols - marg + 1));
-		else
-			str = sprintf("%*s | %s", marg - 4, "", substr(line, 1, cols - marg + 1));
-		line = substr(line, cols - marg + 2);
-		first = 0;
-	}
+cw "${IN:?no -i infile specified}" "${OUT:?no -o outfile specified}" |
+while read date time nick msg; do
+	nick=${nick#<}
+	nick=${nick%>}
 
-	if (act == 1) {
-		nick = sprintf("%s%s", act_fmt, $3);
-		me_col = sprintf("%s%s%s%s", reset_fmt, me_fmt, me, act_fmt);
-	} else if (srv == 1) {
-		nick = sprintf("%s%s", srv_fmt, $3);
-		me_col = sprintf("%s%s%s%s", reset_fmt, me_fmt, me, srv_fmt);
-	} else {
-		nick = sprintf("%s%s%s", nick_fmt, $3, reset_fmt);
-		me_col = sprintf("\a%s%s%s", me_fmt, me, reset_fmt);
-	}
-	time = sprintf("%s%s%s", date_fmt, $2, reset_fmt);
-	sub($2, time, str);
-	gsub(/\[/, "\\[", $3);
-	gsub(/\]/, "\\]", $3);
-	gsub(/\|/, "\\|", $3);
-	gsub(/\^/, "\\^", $3);
-	if (first)
-	    sub($3, nick, str);
-	gsub(me, me_col, str);
-	printf("%s%s\n", str, reset_fmt);
-	fflush();
-}
+	time=$(print_info "$time")
 
-}'
+	if [ "$nick" = "-!-" ]; then
+		nick=$(printf "%s%$((PAD + 3))s" "${bold}${black}" "$nick")
+	else
+		nick=$(print_nick "$nick")
+	fi
+
+	echo "$time" "$nick" "${msg}${reset}"
+done | sed "s/$NICK/$me_fmt&$reset/g; s/| ACTION \(.*\)/${magenta}*${reset} \1/"