List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH 0/4] Add ui-blame syntax highlighting
@ 2017-10-18  4:17 whydoubt
  2017-10-18  4:17 ` [PATCH 1/4] ui-blame: Distinguish hashes column from lines column whydoubt
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: whydoubt @ 2017-10-18  4:17 UTC (permalink / raw)


I reorganized the ordering of the table so that the lines of the file
are contained within a single cell, and the base layer of that cell
contains the alternating colors.  I then pass the full contents of the
file through the source filter.

Jeff Smith (4):
  ui-blame: Distinguish hashes column from lines column
  ui-blame: Break out emit_blame_entry into component methods
  ui-blame: Make each column into a single table cell
  ui-blame: Allow syntax highlighting

 cgit.css                       |  30 +++++++++++-
 filters/syntax-highlighting.py |   2 +-
 ui-blame.c                     | 109 ++++++++++++++++++++++++++++++++---------
 3 files changed, 115 insertions(+), 26 deletions(-)

-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/4] ui-blame: Distinguish hashes column from lines column
  2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
@ 2017-10-18  4:17 ` whydoubt
  2017-10-21 14:33   ` john
  2017-10-18  4:17 ` [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods whydoubt
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-18  4:17 UTC (permalink / raw)


Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 cgit.css   | 1 +
 ui-blame.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/cgit.css b/cgit.css
index 836f8ae..893ebeb 100644
--- a/cgit.css
+++ b/cgit.css
@@ -300,6 +300,7 @@ div#cgit table.blob {
 	border-top: solid 1px black;
 }
 
+div#cgit table.blob td.hashes,
 div#cgit table.blob td.lines {
 	margin: 0; padding: 0 0 0 0.5em;
 	vertical-align: top;
diff --git a/ui-blame.c b/ui-blame.c
index 62cf431..a5ac590 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -51,7 +51,7 @@ static void emit_blame_entry(struct blame_scoreboard *sb,
 
 	char *detail = emit_suspect_detail(suspect);
 
-	html("<tr><td class='sha1 lines'>");
+	html("<tr><td class='sha1 hashes'>");
 	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
 			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
 	html("</td>\n");
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods
  2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
  2017-10-18  4:17 ` [PATCH 1/4] ui-blame: Distinguish hashes column from lines column whydoubt
@ 2017-10-18  4:17 ` whydoubt
  2017-10-21 14:33   ` john
  2017-10-18  4:17 ` [PATCH 3/4] ui-blame: Make each column into a single table cell whydoubt
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-18  4:17 UTC (permalink / raw)


Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 ui-blame.c | 44 ++++++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/ui-blame.c b/ui-blame.c
index a5ac590..9b84147 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -41,36 +41,52 @@ static char *emit_suspect_detail(struct blame_origin *suspect)
 	return strbuf_detach(&detail, NULL);
 }
 
-static void emit_blame_entry(struct blame_scoreboard *sb,
-			     struct blame_entry *ent)
+static void emit_blame_entry_hash(struct blame_entry *ent)
 {
 	struct blame_origin *suspect = ent->suspect;
 	struct object_id *oid = &suspect->commit->object.oid;
+
+	char *detail = emit_suspect_detail(suspect);
+	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
+			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
+	free(detail);
+}
+
+static void emit_blame_entry_linenumber(struct blame_entry *ent)
+{
 	const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
+
+	unsigned long lineno = ent->lno;
+	while (lineno < ent->lno + ent->num_lines)
+		htmlf(numberfmt, ++lineno);
+}
+
+static void emit_blame_entry_line(struct blame_scoreboard *sb,
+				  struct blame_entry *ent)
+{
 	const char *cp, *cpend;
 
-	char *detail = emit_suspect_detail(suspect);
+	cp = blame_nth_line(sb, ent->lno);
+	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+
+	html_ntxt(cp, cpend - cp);
+}
 
+static void emit_blame_entry(struct blame_scoreboard *sb,
+			     struct blame_entry *ent)
+{
 	html("<tr><td class='sha1 hashes'>");
-	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
-			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
+	emit_blame_entry_hash(ent);
 	html("</td>\n");
 
-	free(detail);
-
 	if (ctx.cfg.enable_tree_linenumbers) {
-		unsigned long lineno = ent->lno;
 		html("<td class='linenumbers'><pre>");
-		while (lineno < ent->lno + ent->num_lines)
-			htmlf(numberfmt, ++lineno);
+		emit_blame_entry_linenumber(ent);
 		html("</pre></td>\n");
 	}
 
-	cp = blame_nth_line(sb, ent->lno);
-	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
-
 	html("<td class='lines'><pre><code>");
-	html_ntxt(cp, cpend - cp);
+	emit_blame_entry_line(sb, ent);
 	html("</code></pre></td></tr>\n");
 }
 
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/4] ui-blame: Make each column into a single table cell
  2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
  2017-10-18  4:17 ` [PATCH 1/4] ui-blame: Distinguish hashes column from lines column whydoubt
  2017-10-18  4:17 ` [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods whydoubt
@ 2017-10-18  4:17 ` whydoubt
  2017-10-21 14:34   ` john
  2017-10-18  4:17 ` [PATCH 4/4] ui-blame: Allow syntax highlighting whydoubt
  2018-01-19 10:41 ` [PATCH 0/4] Add ui-blame " Jason
  4 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-18  4:17 UTC (permalink / raw)


Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 cgit.css   | 19 +++++++++++++++++--
 ui-blame.c | 58 +++++++++++++++++++++++++++++++++++++---------------------
 2 files changed, 54 insertions(+), 23 deletions(-)

diff --git a/cgit.css b/cgit.css
index 893ebeb..20b7e86 100644
--- a/cgit.css
+++ b/cgit.css
@@ -330,11 +330,26 @@ div#cgit table.ssdiff td.lineno a:hover {
 	color: black;
 }
 
-div#cgit table.blame tr:nth-child(even) {
+div#cgit table.blame td.hashes,
+div#cgit table.blame td.lines,
+div#cgit table.blame td.linenumbers {
+	padding: 0;
+}
+
+div#cgit table.blame td.hashes div.alt,
+div#cgit table.blame td.lines div.alt {
+	padding: 0 0.5em 0 0.5em;
+}
+
+div#cgit table.blame td.linenumbers div.alt {
+	padding: 0 0.5em 0 0;
+}
+
+div#cgit table.blame div.alt:nth-child(even) {
 	background: #eee;
 }
 
-div#cgit table.blame tr:nth-child(odd) {
+div#cgit table.blame div.alt:nth-child(odd) {
 	background: white;
 }
 
diff --git a/ui-blame.c b/ui-blame.c
index 9b84147..f506616 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -45,11 +45,17 @@ static void emit_blame_entry_hash(struct blame_entry *ent)
 {
 	struct blame_origin *suspect = ent->suspect;
 	struct object_id *oid = &suspect->commit->object.oid;
+	unsigned long line = 0;
 
 	char *detail = emit_suspect_detail(suspect);
+	html("<span class='sha1'>");
 	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
 			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
+	html("</span>");
 	free(detail);
+
+	while (line++ < ent->num_lines)
+		html("\n");
 }
 
 static void emit_blame_entry_linenumber(struct blame_entry *ent)
@@ -72,24 +78,6 @@ static void emit_blame_entry_line(struct blame_scoreboard *sb,
 	html_ntxt(cp, cpend - cp);
 }
 
-static void emit_blame_entry(struct blame_scoreboard *sb,
-			     struct blame_entry *ent)
-{
-	html("<tr><td class='sha1 hashes'>");
-	emit_blame_entry_hash(ent);
-	html("</td>\n");
-
-	if (ctx.cfg.enable_tree_linenumbers) {
-		html("<td class='linenumbers'><pre>");
-		emit_blame_entry_linenumber(ent);
-		html("</pre></td>\n");
-	}
-
-	html("<td class='lines'><pre><code>");
-	emit_blame_entry_line(sb, ent);
-	html("</code></pre></td></tr>\n");
-}
-
 struct walk_tree_context {
 	char *curr_rev;
 	int match_baselen;
@@ -147,16 +135,44 @@ static void print_object(const unsigned char *sha1, const char *path,
 		return;
 	}
 
-	html("<table class='blame blob'>");
+	html("<table class='blame blob'>\n<tr>\n");
+
+	/* Commit hashes */
+	html("<td class='hashes'>");
+	for (ent = sb.ent; ent; ent = ent->next) {
+		html("<div class='alt'><pre>");
+		emit_blame_entry_hash(ent);
+		html("</pre></div>");
+	}
+	html("</td>\n");
+
+	/* Line numbers */
+	if (ctx.cfg.enable_tree_linenumbers) {
+		html("<td class='linenumbers'>");
+		for (ent = sb.ent; ent; ent = ent->next) {
+			html("<div class='alt'><pre>");
+			emit_blame_entry_linenumber(ent);
+			html("</pre></div>");
+		}
+		html("</td>\n");
+	}
+
+	/* Lines */
+	html("<td class='lines'>");
 	for (ent = sb.ent; ent; ) {
 		struct blame_entry *e = ent->next;
-		emit_blame_entry(&sb, ent);
+		html("<div class='alt'><pre><code>");
+		emit_blame_entry_line(&sb, ent);
+		html("</code></pre></div>");
 		free(ent);
 		ent = e;
 	}
-	html("</table>\n");
+	html("</td>\n");
+
 	free((void *)sb.final_buf);
 
+	html("</tr>\n</table>\n");
+
 	cgit_print_layout_end();
 }
 
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4] ui-blame: Allow syntax highlighting
  2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
                   ` (2 preceding siblings ...)
  2017-10-18  4:17 ` [PATCH 3/4] ui-blame: Make each column into a single table cell whydoubt
@ 2017-10-18  4:17 ` whydoubt
  2017-10-21 14:43   ` john
  2018-01-19 10:41 ` [PATCH 0/4] Add ui-blame " Jason
  4 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-18  4:17 UTC (permalink / raw)


Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 cgit.css                       | 10 ++++++++
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c                     | 55 +++++++++++++++++++++++++++++++++---------
 3 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
 	background: white;
 }
 
+div#cgit table.blame td.lines > div {
+	position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+	padding: 0 0 0 0.5em;
+	position: absolute;
+	top: 0;
+}
+
 div#cgit table.bin-blob {
 	margin-top: 0.5em;
 	border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
 	lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..574c3ee 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,21 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent)
 		htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
-				  struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+					     struct blame_entry *ent)
 {
-	const char *cp, *cpend;
+	unsigned long line;
+	size_t len, maxlen = 2;
 
-	cp = blame_nth_line(sb, ent->lno);
-	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+	for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+		html("\n");
+		len = blame_nth_line(sb, line + 1) - blame_nth_line(sb, line);
+		if (len > maxlen)
+			maxlen = len;
+	}
 
-	html_ntxt(cp, cpend - cp);
+	for (len = 0; len < maxlen - 1; len++)
+		html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +94,7 @@ static void print_object(const unsigned char *sha1, const char *path,
 			 const char *basename, const char *rev)
 {
 	enum object_type type;
+	char *buf;
 	unsigned long size;
 	struct argv_array rev_argv = ARGV_ARRAY_INIT;
 	struct rev_info revs;
@@ -102,6 +109,13 @@ static void print_object(const unsigned char *sha1, const char *path,
 		return;
 	}
 
+	buf = read_sha1_file(sha1, &type, &size);
+	if (!buf) {
+		cgit_print_error_page(500, "Internal server error",
+			"Error reading object %s", sha1_to_hex(sha1));
+		return;
+	}
+
 	argv_array_push(&rev_argv, "blame");
 	argv_array_push(&rev_argv, rev);
 	init_revisions(&revs, NULL);
@@ -157,20 +171,37 @@ static void print_object(const unsigned char *sha1, const char *path,
 		html("</td>\n");
 	}
 
-	/* Lines */
-	html("<td class='lines'>");
+	html("<td class='lines'><div>");
+
+	/* Colored bars behind lines */
+	html("<div>");
 	for (ent = sb.ent; ent; ) {
 		struct blame_entry *e = ent->next;
-		html("<div class='alt'><pre><code>");
-		emit_blame_entry_line(&sb, ent);
-		html("</code></pre></div>");
+		html("<div class='alt'><pre>");
+		emit_blame_entry_line_background(&sb, ent);
+		html("</pre></div>");
 		free(ent);
 		ent = e;
 	}
-	html("</td>\n");
+	html("</div>");
 
 	free((void *)sb.final_buf);
 
+	/* Lines */
+	html("<pre><code>");
+	if (ctx.repo->source_filter) {
+		char *filter_arg = xstrdup(basename);
+		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		html_raw(buf, size);
+		cgit_close_filter(ctx.repo->source_filter);
+		free(filter_arg);
+	} else {
+		html_txt(buf);
+	}
+	html("</code></pre>");
+
+	html("</div></td>\n");
+
 	html("</tr>\n</table>\n");
 
 	cgit_print_layout_end();
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/4] ui-blame: Distinguish hashes column from lines column
  2017-10-18  4:17 ` [PATCH 1/4] ui-blame: Distinguish hashes column from lines column whydoubt
@ 2017-10-21 14:33   ` john
  0 siblings, 0 replies; 17+ messages in thread
From: john @ 2017-10-21 14:33 UTC (permalink / raw)


On Tue, Oct 17, 2017 at 11:17:32PM -0500, Jeff Smith wrote:
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>

Reviewed-by: John Keeping <john at keeping.me.uk>

> ---
>  cgit.css   | 1 +
>  ui-blame.c | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/cgit.css b/cgit.css
> index 836f8ae..893ebeb 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -300,6 +300,7 @@ div#cgit table.blob {
>  	border-top: solid 1px black;
>  }
>  
> +div#cgit table.blob td.hashes,
>  div#cgit table.blob td.lines {
>  	margin: 0; padding: 0 0 0 0.5em;
>  	vertical-align: top;
> diff --git a/ui-blame.c b/ui-blame.c
> index 62cf431..a5ac590 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -51,7 +51,7 @@ static void emit_blame_entry(struct blame_scoreboard *sb,
>  
>  	char *detail = emit_suspect_detail(suspect);
>  
> -	html("<tr><td class='sha1 lines'>");
> +	html("<tr><td class='sha1 hashes'>");
>  	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
>  			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
>  	html("</td>\n");


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods
  2017-10-18  4:17 ` [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods whydoubt
@ 2017-10-21 14:33   ` john
  0 siblings, 0 replies; 17+ messages in thread
From: john @ 2017-10-21 14:33 UTC (permalink / raw)


On Tue, Oct 17, 2017 at 11:17:33PM -0500, Jeff Smith wrote:
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>

Reviewed-by: John Keeping <john at keeping.me.uk>

> ---
>  ui-blame.c | 44 ++++++++++++++++++++++++++++++--------------
>  1 file changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/ui-blame.c b/ui-blame.c
> index a5ac590..9b84147 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -41,36 +41,52 @@ static char *emit_suspect_detail(struct blame_origin *suspect)
>  	return strbuf_detach(&detail, NULL);
>  }
>  
> -static void emit_blame_entry(struct blame_scoreboard *sb,
> -			     struct blame_entry *ent)
> +static void emit_blame_entry_hash(struct blame_entry *ent)
>  {
>  	struct blame_origin *suspect = ent->suspect;
>  	struct object_id *oid = &suspect->commit->object.oid;
> +
> +	char *detail = emit_suspect_detail(suspect);
> +	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
> +			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
> +	free(detail);
> +}
> +
> +static void emit_blame_entry_linenumber(struct blame_entry *ent)
> +{
>  	const char *numberfmt = "<a id='n%1$d' href='#n%1$d'>%1$d</a>\n";
> +
> +	unsigned long lineno = ent->lno;
> +	while (lineno < ent->lno + ent->num_lines)
> +		htmlf(numberfmt, ++lineno);
> +}
> +
> +static void emit_blame_entry_line(struct blame_scoreboard *sb,
> +				  struct blame_entry *ent)
> +{
>  	const char *cp, *cpend;
>  
> -	char *detail = emit_suspect_detail(suspect);
> +	cp = blame_nth_line(sb, ent->lno);
> +	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> +
> +	html_ntxt(cp, cpend - cp);
> +}
>  
> +static void emit_blame_entry(struct blame_scoreboard *sb,
> +			     struct blame_entry *ent)
> +{
>  	html("<tr><td class='sha1 hashes'>");
> -	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
> -			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
> +	emit_blame_entry_hash(ent);
>  	html("</td>\n");
>  
> -	free(detail);
> -
>  	if (ctx.cfg.enable_tree_linenumbers) {
> -		unsigned long lineno = ent->lno;
>  		html("<td class='linenumbers'><pre>");
> -		while (lineno < ent->lno + ent->num_lines)
> -			htmlf(numberfmt, ++lineno);
> +		emit_blame_entry_linenumber(ent);
>  		html("</pre></td>\n");
>  	}
>  
> -	cp = blame_nth_line(sb, ent->lno);
> -	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> -
>  	html("<td class='lines'><pre><code>");
> -	html_ntxt(cp, cpend - cp);
> +	emit_blame_entry_line(sb, ent);
>  	html("</code></pre></td></tr>\n");
>  }
>  


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 3/4] ui-blame: Make each column into a single table cell
  2017-10-18  4:17 ` [PATCH 3/4] ui-blame: Make each column into a single table cell whydoubt
@ 2017-10-21 14:34   ` john
  0 siblings, 0 replies; 17+ messages in thread
From: john @ 2017-10-21 14:34 UTC (permalink / raw)


On Tue, Oct 17, 2017 at 11:17:34PM -0500, Jeff Smith wrote:
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>

Reviewed-by: John Keeping <john at keeping.me.uk>

> ---
>  cgit.css   | 19 +++++++++++++++++--
>  ui-blame.c | 58 +++++++++++++++++++++++++++++++++++++---------------------
>  2 files changed, 54 insertions(+), 23 deletions(-)
> 
> diff --git a/cgit.css b/cgit.css
> index 893ebeb..20b7e86 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -330,11 +330,26 @@ div#cgit table.ssdiff td.lineno a:hover {
>  	color: black;
>  }
>  
> -div#cgit table.blame tr:nth-child(even) {
> +div#cgit table.blame td.hashes,
> +div#cgit table.blame td.lines,
> +div#cgit table.blame td.linenumbers {
> +	padding: 0;
> +}
> +
> +div#cgit table.blame td.hashes div.alt,
> +div#cgit table.blame td.lines div.alt {
> +	padding: 0 0.5em 0 0.5em;
> +}
> +
> +div#cgit table.blame td.linenumbers div.alt {
> +	padding: 0 0.5em 0 0;
> +}
> +
> +div#cgit table.blame div.alt:nth-child(even) {
>  	background: #eee;
>  }
>  
> -div#cgit table.blame tr:nth-child(odd) {
> +div#cgit table.blame div.alt:nth-child(odd) {
>  	background: white;
>  }
>  
> diff --git a/ui-blame.c b/ui-blame.c
> index 9b84147..f506616 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -45,11 +45,17 @@ static void emit_blame_entry_hash(struct blame_entry *ent)
>  {
>  	struct blame_origin *suspect = ent->suspect;
>  	struct object_id *oid = &suspect->commit->object.oid;
> +	unsigned long line = 0;
>  
>  	char *detail = emit_suspect_detail(suspect);
> +	html("<span class='sha1'>");
>  	cgit_commit_link(find_unique_abbrev(oid->hash, DEFAULT_ABBREV), detail,
>  			 NULL, ctx.qry.head, oid_to_hex(oid), suspect->path);
> +	html("</span>");
>  	free(detail);
> +
> +	while (line++ < ent->num_lines)
> +		html("\n");
>  }
>  
>  static void emit_blame_entry_linenumber(struct blame_entry *ent)
> @@ -72,24 +78,6 @@ static void emit_blame_entry_line(struct blame_scoreboard *sb,
>  	html_ntxt(cp, cpend - cp);
>  }
>  
> -static void emit_blame_entry(struct blame_scoreboard *sb,
> -			     struct blame_entry *ent)
> -{
> -	html("<tr><td class='sha1 hashes'>");
> -	emit_blame_entry_hash(ent);
> -	html("</td>\n");
> -
> -	if (ctx.cfg.enable_tree_linenumbers) {
> -		html("<td class='linenumbers'><pre>");
> -		emit_blame_entry_linenumber(ent);
> -		html("</pre></td>\n");
> -	}
> -
> -	html("<td class='lines'><pre><code>");
> -	emit_blame_entry_line(sb, ent);
> -	html("</code></pre></td></tr>\n");
> -}
> -
>  struct walk_tree_context {
>  	char *curr_rev;
>  	int match_baselen;
> @@ -147,16 +135,44 @@ static void print_object(const unsigned char *sha1, const char *path,
>  		return;
>  	}
>  
> -	html("<table class='blame blob'>");
> +	html("<table class='blame blob'>\n<tr>\n");
> +
> +	/* Commit hashes */
> +	html("<td class='hashes'>");
> +	for (ent = sb.ent; ent; ent = ent->next) {
> +		html("<div class='alt'><pre>");
> +		emit_blame_entry_hash(ent);
> +		html("</pre></div>");
> +	}
> +	html("</td>\n");
> +
> +	/* Line numbers */
> +	if (ctx.cfg.enable_tree_linenumbers) {
> +		html("<td class='linenumbers'>");
> +		for (ent = sb.ent; ent; ent = ent->next) {
> +			html("<div class='alt'><pre>");
> +			emit_blame_entry_linenumber(ent);
> +			html("</pre></div>");
> +		}
> +		html("</td>\n");
> +	}
> +
> +	/* Lines */
> +	html("<td class='lines'>");
>  	for (ent = sb.ent; ent; ) {
>  		struct blame_entry *e = ent->next;
> -		emit_blame_entry(&sb, ent);
> +		html("<div class='alt'><pre><code>");
> +		emit_blame_entry_line(&sb, ent);
> +		html("</code></pre></div>");
>  		free(ent);
>  		ent = e;
>  	}
> -	html("</table>\n");
> +	html("</td>\n");
> +
>  	free((void *)sb.final_buf);
>  
> +	html("</tr>\n</table>\n");
> +
>  	cgit_print_layout_end();
>  }
>  


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4] ui-blame: Allow syntax highlighting
  2017-10-18  4:17 ` [PATCH 4/4] ui-blame: Allow syntax highlighting whydoubt
@ 2017-10-21 14:43   ` john
  2017-10-21 21:53     ` whydoubt
  0 siblings, 1 reply; 17+ messages in thread
From: john @ 2017-10-21 14:43 UTC (permalink / raw)


On Tue, Oct 17, 2017 at 11:17:35PM -0500, Jeff Smith wrote:
> Place file contents into a single block so that syntax highlighting can
> be applied in the usual fashion.  Place the alternating color bars
> behind the file contents.  Force the default syntax highlighting
> background to transparent.
> 
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>

Other than a couple of minor comments below, this looks reasonable to
me.

It does suffer the same drawback as the normal tree view with source
highlighting in that a little care is needed to avoid the line numbers
and content getting out of step (try adding "font-size: larger" to one
of the syntax highlighting CSS rules!), but since we already accept that
there I think we can accept it here as well.

> ---
>  cgit.css                       | 10 ++++++++
>  filters/syntax-highlighting.py |  2 +-
>  ui-blame.c                     | 55 +++++++++++++++++++++++++++++++++---------
>  3 files changed, 54 insertions(+), 13 deletions(-)
> 
> diff --git a/cgit.css b/cgit.css
> index 20b7e86..217a05a 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
>  	background: white;
>  }
>  
> +div#cgit table.blame td.lines > div {
> +	position: relative;
> +}
> +
> +div#cgit table.blame td.lines > div > pre {
> +	padding: 0 0 0 0.5em;
> +	position: absolute;
> +	top: 0;
> +}
> +
>  div#cgit table.bin-blob {
>  	margin-top: 0.5em;
>  	border: solid 1px black;
> diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
> index 5888b50..e912594 100755
> --- a/filters/syntax-highlighting.py
> +++ b/filters/syntax-highlighting.py
> @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace
>  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
>  data = sys.stdin.read()
>  filename = sys.argv[1]
> -formatter = HtmlFormatter(style='pastie')
> +formatter = HtmlFormatter(style='pastie', nobackground=True)
>  
>  try:
>  	lexer = guess_lexer_for_filename(filename, data)
> diff --git a/ui-blame.c b/ui-blame.c
> index f506616..574c3ee 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -67,15 +67,21 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent)
>  		htmlf(numberfmt, ++lineno);
>  }
>  
> -static void emit_blame_entry_line(struct blame_scoreboard *sb,
> -				  struct blame_entry *ent)
> +static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
> +					     struct blame_entry *ent)
>  {
> -	const char *cp, *cpend;
> +	unsigned long line;
> +	size_t len, maxlen = 2;
>  
> -	cp = blame_nth_line(sb, ent->lno);
> -	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> +	for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
> +		html("\n");
> +		len = blame_nth_line(sb, line + 1) - blame_nth_line(sb, line);

This doesn't account for tabs, which is noticable in long lines (I
happened to test with cgit.c where line 615 is quite a bit longer than
average).

It is fixed by using:

	const char *start = blame_nth_line(sb, line);
	const char *end = blame_nth_line(sb, line + 1);

	html("\n");
	len = end - start;
	while (start < end)
		if (*(start++) == '\t')
			len += 7;

> +		if (len > maxlen)
> +			maxlen = len;
> +	}
>  
> -	html_ntxt(cp, cpend - cp);
> +	for (len = 0; len < maxlen - 1; len++)
> +		html(" ");

Should this use &nbsp; or is a plain space guaranteed to be okay here?

>  }
>  
>  struct walk_tree_context {
> @@ -88,6 +94,7 @@ static void print_object(const unsigned char *sha1, const char *path,
>  			 const char *basename, const char *rev)
>  {
>  	enum object_type type;
> +	char *buf;
>  	unsigned long size;
>  	struct argv_array rev_argv = ARGV_ARRAY_INIT;
>  	struct rev_info revs;
> @@ -102,6 +109,13 @@ static void print_object(const unsigned char *sha1, const char *path,
>  		return;
>  	}
>  
> +	buf = read_sha1_file(sha1, &type, &size);
> +	if (!buf) {
> +		cgit_print_error_page(500, "Internal server error",
> +			"Error reading object %s", sha1_to_hex(sha1));
> +		return;
> +	}
> +
>  	argv_array_push(&rev_argv, "blame");
>  	argv_array_push(&rev_argv, rev);
>  	init_revisions(&revs, NULL);
> @@ -157,20 +171,37 @@ static void print_object(const unsigned char *sha1, const char *path,
>  		html("</td>\n");
>  	}
>  
> -	/* Lines */
> -	html("<td class='lines'>");
> +	html("<td class='lines'><div>");
> +
> +	/* Colored bars behind lines */
> +	html("<div>");
>  	for (ent = sb.ent; ent; ) {
>  		struct blame_entry *e = ent->next;
> -		html("<div class='alt'><pre><code>");
> -		emit_blame_entry_line(&sb, ent);
> -		html("</code></pre></div>");
> +		html("<div class='alt'><pre>");
> +		emit_blame_entry_line_background(&sb, ent);
> +		html("</pre></div>");
>  		free(ent);
>  		ent = e;
>  	}
> -	html("</td>\n");
> +	html("</div>");
>  
>  	free((void *)sb.final_buf);
>  
> +	/* Lines */
> +	html("<pre><code>");
> +	if (ctx.repo->source_filter) {
> +		char *filter_arg = xstrdup(basename);
> +		cgit_open_filter(ctx.repo->source_filter, filter_arg);
> +		html_raw(buf, size);
> +		cgit_close_filter(ctx.repo->source_filter);
> +		free(filter_arg);
> +	} else {
> +		html_txt(buf);
> +	}
> +	html("</code></pre>");
> +
> +	html("</div></td>\n");
> +
>  	html("</tr>\n</table>\n");
>  
>  	cgit_print_layout_end();


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4] ui-blame: Allow syntax highlighting
  2017-10-21 14:43   ` john
@ 2017-10-21 21:53     ` whydoubt
  2017-10-24 14:30       ` Jason
  0 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-21 21:53 UTC (permalink / raw)


On Sat, Oct 21, 2017 at 9:43 AM, John Keeping <john at keeping.me.uk> wrote:
>
> This doesn't account for tabs, which is noticable in long lines (I
> happened to test with cgit.c where line 615 is quite a bit longer than
> average).
>
> It is fixed by using:
>
>         const char *start = blame_nth_line(sb, line);
>         const char *end = blame_nth_line(sb, line + 1);
>
>         html("\n");
>         len = end - start;
>         while (start < end)
>                 if (*(start++) == '\t')
>                         len += 7;
>

Nice catch.  Since '\t' is 'advance to next tab-stop' not 'advance # spaces',
that calculation could give a len larger than necessary.  I will add the code
to handle tabs properly.

>> +             if (len > maxlen)
>> +                     maxlen = len;
>> +     }
>>
>> -     html_ntxt(cp, cpend - cp);
>> +     for (len = 0; len < maxlen - 1; len++)
>> +             html(" ");
>
> Should this use &nbsp; or is a plain space guaranteed to be okay here?

This is inside of a 'pre' block, so spaces will do the right thing.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4] ui-blame: Allow syntax highlighting
  2017-10-21 21:53     ` whydoubt
@ 2017-10-24 14:30       ` Jason
  2017-10-29  2:23         ` [PATCH 4/4 v2] " whydoubt
  0 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2017-10-24 14:30 UTC (permalink / raw)


Just waiting on resubmission of this 4/4, then. I'll put 1-3 in a branch.

Jason


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4 v2] ui-blame: Allow syntax highlighting
  2017-10-24 14:30       ` Jason
@ 2017-10-29  2:23         ` whydoubt
  2017-10-29  2:26           ` whydoubt
  0 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-29  2:23 UTC (permalink / raw)


Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---
 cgit.css                       | 10 +++++++
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c                     | 63 ++++++++++++++++++++++++++++++++++--------
 3 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
 	background: white;
 }
 
+div#cgit table.blame td.lines > div {
+	position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+	padding: 0 0 0 0.5em;
+	position: absolute;
+	top: 0;
+}
+
 div#cgit table.bin-blob {
 	margin-top: 0.5em;
 	border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
 	lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..bb6261f 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent)
 		htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
-				  struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+					     struct blame_entry *ent)
 {
-	const char *cp, *cpend;
+	unsigned long line;
+	size_t len, maxlen = 2;
+	const char* pos, endpos;
 
-	cp = blame_nth_line(sb, ent->lno);
-	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+	for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+		html("\n");
+		pos = blame_nth_line(sb, line);
+		endpos = blame_nth_line(sb, line + 1);
+		len = 0;
+		while (pos < endpos) {
+			len++;
+			if (*pos++ == '\t')
+				len = (len + 7) & ~7;
+		}
+		if (len > maxlen)
+			maxlen = len;
+	}
 
-	html_ntxt(cp, cpend - cp);
+	for (len = 0; len < maxlen - 1; len++)
+		html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const char *path,
 			 const char *basename, const char *rev)
 {
 	enum object_type type;
+	char *buf;
 	unsigned long size;
 	struct argv_array rev_argv = ARGV_ARRAY_INIT;
 	struct rev_info revs;
@@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const char *path,
 		return;
 	}
 
+	buf = read_sha1_file(sha1, &type, &size);
+	if (!buf) {
+		cgit_print_error_page(500, "Internal server error",
+			"Error reading object %s", sha1_to_hex(sha1));
+		return;
+	}
+
 	argv_array_push(&rev_argv, "blame");
 	argv_array_push(&rev_argv, rev);
 	init_revisions(&revs, NULL);
@@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const char *path,
 		html("</td>\n");
 	}
 
-	/* Lines */
-	html("<td class='lines'>");
+	html("<td class='lines'><div>");
+
+	/* Colored bars behind lines */
+	html("<div>");
 	for (ent = sb.ent; ent; ) {
 		struct blame_entry *e = ent->next;
-		html("<div class='alt'><pre><code>");
-		emit_blame_entry_line(&sb, ent);
-		html("</code></pre></div>");
+		html("<div class='alt'><pre>");
+		emit_blame_entry_line_background(&sb, ent);
+		html("</pre></div>");
 		free(ent);
 		ent = e;
 	}
-	html("</td>\n");
+	html("</div>");
 
 	free((void *)sb.final_buf);
 
+	/* Lines */
+	html("<pre><code>");
+	if (ctx.repo->source_filter) {
+		char *filter_arg = xstrdup(basename);
+		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		html_raw(buf, size);
+		cgit_close_filter(ctx.repo->source_filter);
+		free(filter_arg);
+	} else {
+		html_txt(buf);
+	}
+	html("</code></pre>");
+
+	html("</div></td>\n");
+
 	html("</tr>\n</table>\n");
 
 	cgit_print_layout_end();
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4 v2] ui-blame: Allow syntax highlighting
  2017-10-29  2:23         ` [PATCH 4/4 v2] " whydoubt
@ 2017-10-29  2:26           ` whydoubt
  2017-10-29  2:43             ` [PATCH 4/4 v3] " whydoubt
  0 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-29  2:26 UTC (permalink / raw)


Sorry, ignore that one.  Wasn't meant to be sent quite yet.

On Sat, Oct 28, 2017 at 9:23 PM, Jeff Smith <whydoubt at gmail.com> wrote:
> Place file contents into a single block so that syntax highlighting can
> be applied in the usual fashion.  Place the alternating color bars
> behind the file contents.  Force the default syntax highlighting
> background to transparent.
>
> Signed-off-by: Jeff Smith <whydoubt at gmail.com>
> ---
>  cgit.css                       | 10 +++++++
>  filters/syntax-highlighting.py |  2 +-
>  ui-blame.c                     | 63 ++++++++++++++++++++++++++++++++++--------
>  3 files changed, 62 insertions(+), 13 deletions(-)
>
> diff --git a/cgit.css b/cgit.css
> index 20b7e86..217a05a 100644
> --- a/cgit.css
> +++ b/cgit.css
> @@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
>         background: white;
>  }
>
> +div#cgit table.blame td.lines > div {
> +       position: relative;
> +}
> +
> +div#cgit table.blame td.lines > div > pre {
> +       padding: 0 0 0 0.5em;
> +       position: absolute;
> +       top: 0;
> +}
> +
>  div#cgit table.bin-blob {
>         margin-top: 0.5em;
>         border: solid 1px black;
> diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
> index 5888b50..e912594 100755
> --- a/filters/syntax-highlighting.py
> +++ b/filters/syntax-highlighting.py
> @@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace
>  sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
>  data = sys.stdin.read()
>  filename = sys.argv[1]
> -formatter = HtmlFormatter(style='pastie')
> +formatter = HtmlFormatter(style='pastie', nobackground=True)
>
>  try:
>         lexer = guess_lexer_for_filename(filename, data)
> diff --git a/ui-blame.c b/ui-blame.c
> index f506616..bb6261f 100644
> --- a/ui-blame.c
> +++ b/ui-blame.c
> @@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent)
>                 htmlf(numberfmt, ++lineno);
>  }
>
> -static void emit_blame_entry_line(struct blame_scoreboard *sb,
> -                                 struct blame_entry *ent)
> +static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
> +                                            struct blame_entry *ent)
>  {
> -       const char *cp, *cpend;
> +       unsigned long line;
> +       size_t len, maxlen = 2;
> +       const char* pos, endpos;
>
> -       cp = blame_nth_line(sb, ent->lno);
> -       cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
> +       for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
> +               html("\n");
> +               pos = blame_nth_line(sb, line);
> +               endpos = blame_nth_line(sb, line + 1);
> +               len = 0;
> +               while (pos < endpos) {
> +                       len++;
> +                       if (*pos++ == '\t')
> +                               len = (len + 7) & ~7;
> +               }
> +               if (len > maxlen)
> +                       maxlen = len;
> +       }
>
> -       html_ntxt(cp, cpend - cp);
> +       for (len = 0; len < maxlen - 1; len++)
> +               html(" ");
>  }
>
>  struct walk_tree_context {
> @@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const char *path,
>                          const char *basename, const char *rev)
>  {
>         enum object_type type;
> +       char *buf;
>         unsigned long size;
>         struct argv_array rev_argv = ARGV_ARRAY_INIT;
>         struct rev_info revs;
> @@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const char *path,
>                 return;
>         }
>
> +       buf = read_sha1_file(sha1, &type, &size);
> +       if (!buf) {
> +               cgit_print_error_page(500, "Internal server error",
> +                       "Error reading object %s", sha1_to_hex(sha1));
> +               return;
> +       }
> +
>         argv_array_push(&rev_argv, "blame");
>         argv_array_push(&rev_argv, rev);
>         init_revisions(&revs, NULL);
> @@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const char *path,
>                 html("</td>\n");
>         }
>
> -       /* Lines */
> -       html("<td class='lines'>");
> +       html("<td class='lines'><div>");
> +
> +       /* Colored bars behind lines */
> +       html("<div>");
>         for (ent = sb.ent; ent; ) {
>                 struct blame_entry *e = ent->next;
> -               html("<div class='alt'><pre><code>");
> -               emit_blame_entry_line(&sb, ent);
> -               html("</code></pre></div>");
> +               html("<div class='alt'><pre>");
> +               emit_blame_entry_line_background(&sb, ent);
> +               html("</pre></div>");
>                 free(ent);
>                 ent = e;
>         }
> -       html("</td>\n");
> +       html("</div>");
>
>         free((void *)sb.final_buf);
>
> +       /* Lines */
> +       html("<pre><code>");
> +       if (ctx.repo->source_filter) {
> +               char *filter_arg = xstrdup(basename);
> +               cgit_open_filter(ctx.repo->source_filter, filter_arg);
> +               html_raw(buf, size);
> +               cgit_close_filter(ctx.repo->source_filter);
> +               free(filter_arg);
> +       } else {
> +               html_txt(buf);
> +       }
> +       html("</code></pre>");
> +
> +       html("</div></td>\n");
> +
>         html("</tr>\n</table>\n");
>
>         cgit_print_layout_end();
> --
> 2.9.4
>


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4 v3] ui-blame: Allow syntax highlighting
  2017-10-29  2:26           ` whydoubt
@ 2017-10-29  2:43             ` whydoubt
  2017-10-29 22:23               ` Jason
  0 siblings, 1 reply; 17+ messages in thread
From: whydoubt @ 2017-10-29  2:43 UTC (permalink / raw)


Place file contents into a single block so that syntax highlighting can
be applied in the usual fashion.  Place the alternating color bars
behind the file contents.  Force the default syntax highlighting
background to transparent.

Signed-off-by: Jeff Smith <whydoubt at gmail.com>
---

Here is the version that corrects for tab characters in the text.

 cgit.css                       | 10 +++++++
 filters/syntax-highlighting.py |  2 +-
 ui-blame.c                     | 63 ++++++++++++++++++++++++++++++++++--------
 3 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/cgit.css b/cgit.css
index 20b7e86..217a05a 100644
--- a/cgit.css
+++ b/cgit.css
@@ -353,6 +353,16 @@ div#cgit table.blame div.alt:nth-child(odd) {
 	background: white;
 }
 
+div#cgit table.blame td.lines > div {
+	position: relative;
+}
+
+div#cgit table.blame td.lines > div > pre {
+	padding: 0 0 0 0.5em;
+	position: absolute;
+	top: 0;
+}
+
 div#cgit table.bin-blob {
 	margin-top: 0.5em;
 	border: solid 1px black;
diff --git a/filters/syntax-highlighting.py b/filters/syntax-highlighting.py
index 5888b50..e912594 100755
--- a/filters/syntax-highlighting.py
+++ b/filters/syntax-highlighting.py
@@ -34,7 +34,7 @@ sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8', errors='replace
 sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
 data = sys.stdin.read()
 filename = sys.argv[1]
-formatter = HtmlFormatter(style='pastie')
+formatter = HtmlFormatter(style='pastie', nobackground=True)
 
 try:
 	lexer = guess_lexer_for_filename(filename, data)
diff --git a/ui-blame.c b/ui-blame.c
index f506616..afbcf0d 100644
--- a/ui-blame.c
+++ b/ui-blame.c
@@ -67,15 +67,29 @@ static void emit_blame_entry_linenumber(struct blame_entry *ent)
 		htmlf(numberfmt, ++lineno);
 }
 
-static void emit_blame_entry_line(struct blame_scoreboard *sb,
-				  struct blame_entry *ent)
+static void emit_blame_entry_line_background(struct blame_scoreboard *sb,
+					     struct blame_entry *ent)
 {
-	const char *cp, *cpend;
+	unsigned long line;
+	size_t len, maxlen = 2;
+	const char* pos, *endpos;
 
-	cp = blame_nth_line(sb, ent->lno);
-	cpend = blame_nth_line(sb, ent->lno + ent->num_lines);
+	for (line = ent->lno; line < ent->lno + ent->num_lines; line++) {
+		html("\n");
+		pos = blame_nth_line(sb, line);
+		endpos = blame_nth_line(sb, line + 1);
+		len = 0;
+		while (pos < endpos) {
+			len++;
+			if (*pos++ == '\t')
+				len = (len + 7) & ~7;
+		}
+		if (len > maxlen)
+			maxlen = len;
+	}
 
-	html_ntxt(cp, cpend - cp);
+	for (len = 0; len < maxlen - 1; len++)
+		html(" ");
 }
 
 struct walk_tree_context {
@@ -88,6 +102,7 @@ static void print_object(const unsigned char *sha1, const char *path,
 			 const char *basename, const char *rev)
 {
 	enum object_type type;
+	char *buf;
 	unsigned long size;
 	struct argv_array rev_argv = ARGV_ARRAY_INIT;
 	struct rev_info revs;
@@ -102,6 +117,13 @@ static void print_object(const unsigned char *sha1, const char *path,
 		return;
 	}
 
+	buf = read_sha1_file(sha1, &type, &size);
+	if (!buf) {
+		cgit_print_error_page(500, "Internal server error",
+			"Error reading object %s", sha1_to_hex(sha1));
+		return;
+	}
+
 	argv_array_push(&rev_argv, "blame");
 	argv_array_push(&rev_argv, rev);
 	init_revisions(&revs, NULL);
@@ -157,20 +179,37 @@ static void print_object(const unsigned char *sha1, const char *path,
 		html("</td>\n");
 	}
 
-	/* Lines */
-	html("<td class='lines'>");
+	html("<td class='lines'><div>");
+
+	/* Colored bars behind lines */
+	html("<div>");
 	for (ent = sb.ent; ent; ) {
 		struct blame_entry *e = ent->next;
-		html("<div class='alt'><pre><code>");
-		emit_blame_entry_line(&sb, ent);
-		html("</code></pre></div>");
+		html("<div class='alt'><pre>");
+		emit_blame_entry_line_background(&sb, ent);
+		html("</pre></div>");
 		free(ent);
 		ent = e;
 	}
-	html("</td>\n");
+	html("</div>");
 
 	free((void *)sb.final_buf);
 
+	/* Lines */
+	html("<pre><code>");
+	if (ctx.repo->source_filter) {
+		char *filter_arg = xstrdup(basename);
+		cgit_open_filter(ctx.repo->source_filter, filter_arg);
+		html_raw(buf, size);
+		cgit_close_filter(ctx.repo->source_filter);
+		free(filter_arg);
+	} else {
+		html_txt(buf);
+	}
+	html("</code></pre>");
+
+	html("</div></td>\n");
+
 	html("</tr>\n</table>\n");
 
 	cgit_print_layout_end();
-- 
2.9.4



^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4 v3] ui-blame: Allow syntax highlighting
  2017-10-29  2:43             ` [PATCH 4/4 v3] " whydoubt
@ 2017-10-29 22:23               ` Jason
  2017-11-05 12:36                 ` john
  0 siblings, 1 reply; 17+ messages in thread
From: Jason @ 2017-10-29 22:23 UTC (permalink / raw)


Works remarkably well. Excellent work. Example, for others on the list:

https://git.zx2c4.com/WireGuard/blame/src/noise.c

Pending objections from others, I'll merge this from jd/color-blame to
master in a few days.

Thanks for this series!

Jason


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 4/4 v3] ui-blame: Allow syntax highlighting
  2017-10-29 22:23               ` Jason
@ 2017-11-05 12:36                 ` john
  0 siblings, 0 replies; 17+ messages in thread
From: john @ 2017-11-05 12:36 UTC (permalink / raw)


On Sun, Oct 29, 2017 at 11:23:38PM +0100, Jason A. Donenfeld wrote:
> Works remarkably well. Excellent work. Example, for others on the list:
> 
> https://git.zx2c4.com/WireGuard/blame/src/noise.c
> 
> Pending objections from others, I'll merge this from jd/color-blame to
> master in a few days.

This version looks great to me, so I say merge away!


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 0/4] Add ui-blame syntax highlighting
  2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
                   ` (3 preceding siblings ...)
  2017-10-18  4:17 ` [PATCH 4/4] ui-blame: Allow syntax highlighting whydoubt
@ 2018-01-19 10:41 ` Jason
  4 siblings, 0 replies; 17+ messages in thread
From: Jason @ 2018-01-19 10:41 UTC (permalink / raw)


This patchset has been merged to master. Thanks for your contribution!

Jason


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-01-19 10:41 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-18  4:17 [PATCH 0/4] Add ui-blame syntax highlighting whydoubt
2017-10-18  4:17 ` [PATCH 1/4] ui-blame: Distinguish hashes column from lines column whydoubt
2017-10-21 14:33   ` john
2017-10-18  4:17 ` [PATCH 2/4] ui-blame: Break out emit_blame_entry into component methods whydoubt
2017-10-21 14:33   ` john
2017-10-18  4:17 ` [PATCH 3/4] ui-blame: Make each column into a single table cell whydoubt
2017-10-21 14:34   ` john
2017-10-18  4:17 ` [PATCH 4/4] ui-blame: Allow syntax highlighting whydoubt
2017-10-21 14:43   ` john
2017-10-21 21:53     ` whydoubt
2017-10-24 14:30       ` Jason
2017-10-29  2:23         ` [PATCH 4/4 v2] " whydoubt
2017-10-29  2:26           ` whydoubt
2017-10-29  2:43             ` [PATCH 4/4 v3] " whydoubt
2017-10-29 22:23               ` Jason
2017-11-05 12:36                 ` john
2018-01-19 10:41 ` [PATCH 0/4] Add ui-blame " Jason

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).