Subject: [PATCH 2/6] Factor out color settings to cg-Xlib

From: Dan Holmsand <[email-masked]>
Date: Thu, 09 Jun 2005 13:17:00 +0200

[PATCH 2/6] Factor out color settings to cg-Xlib

setup_colors sets color variables from COGITO_COLORS, and
adds a sed script for diff colorization to color_rules.

Note that this changes the default colors a little from the
ones in cg-diff: in particular there's no bold any more. Bold
isn't really necessary if the "less search" thing in the new
cg-diff/cg-log is used (and bold is really ugly in
gnome-terminal :-) ).

Signed-off-by: Dan Holmsand <[email-masked]>
---

 cg-Xlib |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -136,6 +136,29 @@ print_help () {
 	exit
 }
 
+setup_colors() {
+	local C="header=32:author=36:signoff=33:committer=35:files=34"
+	C="$C:commit=34:date=32:trim=35"
+	C="$C:diffhdr=34:diffhdradd=32:diffadd=32:diffhdrmod=35"
+	C="$C:diffmod=35:diffhdrrem=31:diffrem=31:diffhunk=36"
+	C="$C:diffctx=34:diffcctx=33:default=0"
+	[ -n "$COGITO_COLORS" ] && C="$C:$COGITO_COLORS"
+
+	C=${C//=/=\'$'\e'[}
+	C=col${C//:/m\'; col}m\'
+	#coldefault=$(tput op)
+	eval $C
+
+	color_rules="
+s,^+++.*,$coldiffhdradd&$coldefault,
+s,^---.*,$coldiffhdrrem&$coldefault,
+s,^[+].*,$coldiffadd&$coldefault,
+s,^[-].*,$coldiffrem&$coldefault,
+s,^\\(@@.*@@\\)\\(.*\\),$coldiffhunk\\1$coldiffctx\\2$coldefault,
+s,^=*$',$coldiffhdr&$coldefault,
+s,^\\(Index:\\|===\\|diff\\) .*,$coldiffhdr&$coldefault,"
+}
+
 for option in "$@"; do
 	if [ "$option" = "-h" -o "$option" = "--help" ]; then
 		print_help ${_cg_cmd##cg-}