git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Herland <johan@herland.net>
To: Lars Hjemli <hjemli@gmail.com>
Cc: git@vger.kernel.org, johan@herland.net
Subject: [CGit RFC/PATCH 5/5] ui-log: Colorize commit graph
Date: Tue, 13 Jul 2010 23:40:21 +0200	[thread overview]
Message-ID: <1279057221-28036-6-git-send-email-johan@herland.net> (raw)
In-Reply-To: <1279056219-27096-1-git-send-email-johan@herland.net>

Use the existing coloring logic in Git's graph code to color the lines
between commits in the commit graph.

Whereas Git normally uses ANSI color escapes to produce colors, we here
use graph_set_column_colors() to replace those with "HTML color escapes"
which embed the graph lines in <span> tags that apply the desired color
using CSS.

Signed-off-by: Johan Herland <johan@herland.net>
---
 cgit.css |   24 ++++++++++++++++++++++++
 ui-log.c |   29 ++++++++++++++++++++++++-----
 2 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/cgit.css b/cgit.css
index 65da960..e8be2b1 100644
--- a/cgit.css
+++ b/cgit.css
@@ -158,6 +158,30 @@ table.list td.commitgraph {
 	white-space: pre;
 }
 
+table.list td.commitgraph .column1 {
+	color: #a00;
+}
+
+table.list td.commitgraph .column2 {
+	color: #0a0;
+}
+
+table.list td.commitgraph .column3 {
+	color: #aa0;
+}
+
+table.list td.commitgraph .column4 {
+	color: #00a;
+}
+
+table.list td.commitgraph .column5 {
+	color: #a0a;
+}
+
+table.list td.commitgraph .column6 {
+	color: #0aa;
+}
+
 table.list td.logsubject {
 	font-family: monospace;
 	font-weight: bold;
diff --git a/ui-log.c b/ui-log.c
index 3cfe3f9..2fc8c7b 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -12,6 +12,21 @@
 
 int files, add_lines, rem_lines;
 
+/*
+ * The list of available column colors in the commit graph.
+ */
+static const char *column_colors_html[] = {
+	"<span class='column1'>",
+	"<span class='column2'>",
+	"<span class='column3'>",
+	"<span class='column4'>",
+	"<span class='column5'>",
+	"<span class='column6'>",
+	"</span>",
+};
+
+#define COLUMN_COLORS_HTML_MAX (ARRAY_SIZE(column_colors_html) - 1)
+
 void count_lines(char *line, int size)
 {
 	if (size <= 0)
@@ -123,14 +138,14 @@ void print_commit(struct commit *commit, struct rev_info *revs)
 		while (!graph_next_line(revs->graph, &msgbuf)) {
 			/* Create graph line + empty table row */
 			html("<tr class='nohover'><td class='commitgraph'>");
-			html_txt(msgbuf.buf);
+			html(msgbuf.buf);
 			htmlf("</td><td colspan='%d' /></tr>\n", cols);
 			strbuf_setlen(&msgbuf, 0);
 		}
 		/* Create graph line + commit info table row */
 		htmlf("<tr%s>", ctx.qry.showmsg ? " class='logheader'" : "");
 		html("<td class='commitgraph'>");
-		html_txt(msgbuf.buf);
+		html(msgbuf.buf);
 		html("</td>");
 	        strbuf_release(&msgbuf);
 	}
@@ -162,7 +177,7 @@ void print_commit(struct commit *commit, struct rev_info *revs)
 				html("\n");
 			strbuf_setlen(&msgbuf, 0);
 			graph_next_line(revs->graph, &msgbuf);
-			html_txt(msgbuf.buf);
+			html(msgbuf.buf);
 			lines--;
 		}
 
@@ -205,7 +220,7 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
 {
 	struct rev_info rev;
 	struct commit *commit;
-	const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL};
+	const char *argv[] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
 	int argc = 2;
 	int i, columns = 3;
 
@@ -221,8 +236,12 @@ void cgit_print_log(const char *tip, int ofs, int cnt, char *grep, char *pattern
 		if (!strcmp(grep, "range"))
 			argv[1] = pattern;
 	}
-	if (ctx.repo->enable_commit_graph)
+	if (ctx.repo->enable_commit_graph) {
 		argv[argc++] = "--graph";
+		argv[argc++] = "--color";
+		graph_set_column_colors(column_colors_html,
+					COLUMN_COLORS_HTML_MAX);
+	}
 
 	if (path) {
 		argv[argc++] = "--";
-- 
1.7.0.4

      parent reply	other threads:[~2010-07-13 21:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-13 21:23 [PATCH 0/2] Preparing the graph API for external users Johan Herland
2010-07-13 21:23 ` [PATCH 1/2] Make graph_next_line() available in the graph.h API Johan Herland
2010-07-13 21:23 ` [PATCH 2/2] Enable custom schemes for column colors in the graph API Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 0/5] Commit graph on CGit's 'log' view Johan Herland
2010-07-13 22:57   ` Lars Hjemli
2010-07-14  5:59     ` Johan Herland
2010-07-18 13:26       ` Lars Hjemli
2010-07-13 21:40 ` [CGit RFC/PATCH 1/5] ui-stats: Remove unnecessary #include Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 2/5] ui-log: Move 'Age' column to the right of 'Author', like in gitk Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 3/5] ui-log: Refactor display of commit messages Johan Herland
2010-07-13 21:40 ` [CGit RFC/PATCH 4/5] ui-log: Implement support for commit graphs Johan Herland
2010-07-13 21:40 ` Johan Herland [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279057221-28036-6-git-send-email-johan@herland.net \
    --to=johan@herland.net \
    --cc=git@vger.kernel.org \
    --cc=hjemli@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).