Commit 11b20872df392ca0904b1dc128407bf2522ebe87

Stefan Sperling 2019-11-08T14:28:58

add colors for 'tog log' and 'tog blame'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
diff --git a/tog/tog.1 b/tog/tog.1
index 01154b7..19ba4d6 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -354,6 +354,21 @@ The color used to mark up executable file tree entries.
 If not set, the default value
 .Dq green
 is used.
+.It Ev TOG_COLOR_COMMIT
+The color used to mark up commit IDs.
+If not set, the default value
+.Dq green
+is used.
+.It Ev TOG_COLOR_AUTHOR
+The color used to mark up author information.
+If not set, the default value
+.Dq cyan
+is used.
+.It Ev TOG_COLOR_DATE
+The color used to mark up date information.
+If not set, the default value
+.Dq yellow
+is used.
 .El
 .Sh EXIT STATUS
 .Ex -std tog
diff --git a/tog/tog.c b/tog/tog.c
index 1b12e4f..c425c02 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -119,6 +119,126 @@ struct tog_color {
 };
 SIMPLEQ_HEAD(tog_colors, tog_color);
 
+static const struct got_error *
+add_color(struct tog_colors *colors, const char *pattern,
+    int idx, short color)
+{
+	const struct got_error *err = NULL;
+	struct tog_color *tc;
+	int regerr = 0;
+
+	if (idx < 1 || idx > COLOR_PAIRS - 1)
+		return NULL;
+
+	init_pair(idx, color, -1);
+
+	tc = calloc(1, sizeof(*tc));
+	if (tc == NULL)
+		return got_error_from_errno("calloc");
+	regerr = regcomp(&tc->regex, pattern,
+	    REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
+	if (regerr) {
+		static char regerr_msg[512];
+		static char err_msg[512];
+		regerror(regerr, &tc->regex, regerr_msg,
+		    sizeof(regerr_msg));
+		snprintf(err_msg, sizeof(err_msg), "regcomp: %s",
+		    regerr_msg);
+		err = got_error_msg(GOT_ERR_REGEX, err_msg);
+		free(tc);
+		return err;
+	}
+	tc->colorpair = idx;
+	SIMPLEQ_INSERT_HEAD(colors, tc, entry);
+	return NULL;
+}
+
+static void
+free_colors(struct tog_colors *colors)
+{
+	struct tog_color *tc;
+
+	while (!SIMPLEQ_EMPTY(colors)) {
+		tc = SIMPLEQ_FIRST(colors);
+		SIMPLEQ_REMOVE_HEAD(colors, entry);
+		regfree(&tc->regex);
+		free(tc);
+	}
+}
+
+struct tog_color *
+get_color(struct tog_colors *colors, int colorpair)
+{
+	struct tog_color *tc = NULL;
+
+	SIMPLEQ_FOREACH(tc, colors, entry) {
+		if (tc->colorpair == colorpair)
+			return tc;
+	}
+
+	return NULL;
+}
+
+static int
+default_color_value(const char *envvar)
+{
+	if (strcmp(envvar, "TOG_COLOR_DIFF_MINUS") == 0)
+		return COLOR_MAGENTA;
+	if (strcmp(envvar, "TOG_COLOR_DIFF_PLUS") == 0)
+		return COLOR_CYAN;
+	if (strcmp(envvar, "TOG_COLOR_DIFF_CHUNK_HEADER") == 0)
+		return COLOR_YELLOW;
+	if (strcmp(envvar, "TOG_COLOR_DIFF_META") == 0)
+		return COLOR_GREEN;
+	if (strcmp(envvar, "TOG_COLOR_TREE_SUBMODULE") == 0)
+		return COLOR_MAGENTA;
+	if (strcmp(envvar, "TOG_COLOR_TREE_SYMLINK") == 0)
+		return COLOR_CYAN;
+	if (strcmp(envvar, "TOG_COLOR_TREE_DIRECTORY") == 0)
+		return COLOR_BLUE;
+	if (strcmp(envvar, "TOG_COLOR_TREE_EXECUTABLE") == 0)
+		return COLOR_GREEN;
+	if (strcmp(envvar, "TOG_COLOR_COMMIT") == 0)
+		return COLOR_GREEN;
+	if (strcmp(envvar, "TOG_COLOR_AUTHOR") == 0)
+		return COLOR_CYAN;
+	if (strcmp(envvar, "TOG_COLOR_DATE") == 0)
+		return COLOR_YELLOW;
+
+	return -1;
+}
+
+static int
+get_color_value(const char *envvar)
+{
+	const char *val = getenv(envvar);
+
+	if (val == NULL)
+		return default_color_value(envvar);
+
+	if (strcasecmp(val, "black") == 0)
+		return COLOR_BLACK;
+	if (strcasecmp(val, "red") == 0)
+		return COLOR_RED;
+	if (strcasecmp(val, "green") == 0)
+		return COLOR_GREEN;
+	if (strcasecmp(val, "yellow") == 0)
+		return COLOR_YELLOW;
+	if (strcasecmp(val, "blue") == 0)
+		return COLOR_BLUE;
+	if (strcasecmp(val, "magenta") == 0)
+		return COLOR_MAGENTA;
+	if (strcasecmp(val, "cyan") == 0)
+		return COLOR_CYAN;
+	if (strcasecmp(val, "white") == 0)
+		return COLOR_WHITE;
+	if (strcasecmp(val, "default") == 0)
+		return -1;
+
+	return default_color_value(envvar);
+}
+
+
 struct tog_diff_view_state {
 	struct got_object_id *id1, *id2;
 	FILE *f;
@@ -169,8 +289,21 @@ struct tog_log_view_state {
 	struct tog_log_thread_args thread_args;
 	struct commit_queue_entry *matched_entry;
 	struct commit_queue_entry *search_entry;
+	struct tog_colors colors;
 };
 
+#define TOG_COLOR_DIFF_MINUS		1
+#define TOG_COLOR_DIFF_PLUS		2
+#define TOG_COLOR_DIFF_CHUNK_HEADER	3
+#define TOG_COLOR_DIFF_META		4
+#define TOG_COLOR_TREE_SUBMODULE	5
+#define TOG_COLOR_TREE_SYMLINK		6
+#define TOG_COLOR_TREE_DIRECTORY	7
+#define TOG_COLOR_TREE_EXECUTABLE	8
+#define TOG_COLOR_COMMIT		9
+#define TOG_COLOR_AUTHOR		10
+#define TOG_COLOR_DATE		11
+
 struct tog_blame_cb_args {
 	struct tog_blame_line *lines; /* one per line */
 	int nlines;
@@ -216,6 +349,7 @@ struct tog_blame_view_state {
 	struct got_object_id *commit_id;
 	struct tog_blame blame;
 	int matched_line;
+	struct tog_colors colors;
 };
 
 struct tog_parent_tree {
@@ -1067,7 +1201,8 @@ format_author(wchar_t **wauthor, int *author_width, char *author, int limit,
 static const struct got_error *
 draw_commit(struct tog_view *view, struct got_commit_object *commit,
     struct got_object_id *id, struct got_reflist_head *refs,
-    const size_t date_display_cols, int author_display_cols)
+    const size_t date_display_cols, int author_display_cols,
+    struct tog_colors *colors)
 {
 	const struct got_error *err = NULL;
 	char datebuf[10]; /* YY-MM-DD + SPACE + NUL */
@@ -1080,6 +1215,7 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
 	const int avail = view->ncols;
 	struct tm tm;
 	time_t committer_time;
+	struct tog_color *tc;
 
 	committer_time = got_object_commit_get_committer_time(commit);
 	if (localtime_r(&committer_time, &tm) == NULL)
@@ -1092,7 +1228,14 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
 		limit = MIN(sizeof(datebuf) - 1, avail);
 	else
 		limit = MIN(date_display_cols, sizeof(datebuf) - 1);
+	tc = get_color(colors, TOG_COLOR_DATE);
+	if (tc)
+		wattr_on(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	waddnstr(view->window, datebuf, limit);
+	if (tc)
+		wattr_off(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	col = limit;
 	if (col > avail)
 		goto done;
@@ -1102,7 +1245,14 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
 		err = got_object_id_str(&id_str, id);
 		if (err)
 			goto done;
+		tc = get_color(colors, TOG_COLOR_COMMIT);
+		if (tc)
+			wattr_on(view->window,
+			    COLOR_PAIR(tc->colorpair), NULL);
 		wprintw(view->window, "%.8s ", id_str);
+		if (tc)
+			wattr_off(view->window,
+			    COLOR_PAIR(tc->colorpair), NULL);
 		free(id_str);
 		col += 9;
 		if (col > avail)
@@ -1117,7 +1267,14 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
 	err = format_author(&wauthor, &author_width, author, avail - col, col);
 	if (err)
 		goto done;
+	tc = get_color(colors, TOG_COLOR_AUTHOR);
+	if (tc)
+		wattr_on(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wauthor);
+	if (tc)
+		wattr_off(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	col += author_width;
 	while (col < avail && author_width < author_display_cols + 2) {
 		waddch(view->window, ' ');
@@ -1323,7 +1480,8 @@ static const struct got_error *
 draw_commits(struct tog_view *view, struct commit_queue_entry **last,
     struct commit_queue_entry **selected, struct commit_queue_entry *first,
     struct commit_queue *commits, int selected_idx, int limit,
-    struct got_reflist_head *refs, const char *path, int commits_needed)
+    struct got_reflist_head *refs, const char *path, int commits_needed,
+    struct tog_colors *colors)
 {
 	const struct got_error *err = NULL;
 	struct tog_log_view_state *s = &view->state.log;
@@ -1333,6 +1491,7 @@ draw_commits(struct tog_view *view, struct commit_queue_entry **last,
 	char *id_str = NULL, *header = NULL, *ncommits_str = NULL;
 	char *refs_str = NULL;
 	wchar_t *wline;
+	struct tog_color *tc;
 	static const size_t date_display_cols = 9;
 
 	entry = first;
@@ -1394,7 +1553,14 @@ draw_commits(struct tog_view *view, struct commit_queue_entry **last,
 
 	if (view_needs_focus_indication(view))
 		wstandout(view->window);
+	tc = get_color(colors, TOG_COLOR_COMMIT);
+	if (tc)
+		wattr_on(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
+	if (tc)
+		wattr_off(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	while (width < view->ncols) {
 		waddch(view->window, ' ');
 		width++;
@@ -1438,7 +1604,7 @@ draw_commits(struct tog_view *view, struct commit_queue_entry **last,
 		if (ncommits == selected_idx)
 			wstandout(view->window);
 		err = draw_commit(view, entry->commit, entry->id, refs,
-		    date_display_cols, author_cols);
+		    date_display_cols, author_cols, colors);
 		if (ncommits == selected_idx)
 			wstandend(view->window);
 		if (err)
@@ -1965,6 +2131,26 @@ open_log_view(struct tog_view *view, struct got_object_id *start_id,
 		goto done;
 	}
 
+	SIMPLEQ_INIT(&s->colors);
+	if (has_colors() && getenv("TOG_COLORS") != NULL) {
+		err = add_color(&s->colors, "^$", TOG_COLOR_COMMIT,
+		    get_color_value("TOG_COLOR_COMMIT"));
+		if (err)
+			goto done;
+		err = add_color(&s->colors, "^$", TOG_COLOR_AUTHOR,
+		    get_color_value("TOG_COLOR_AUTHOR"));
+		if (err) {
+			free_colors(&s->colors);
+			goto done;
+		}
+		err = add_color(&s->colors, "^$", TOG_COLOR_DATE,
+		    get_color_value("TOG_COLOR_DATE"));
+		if (err) {
+			free_colors(&s->colors);
+			goto done;
+		}
+	}
+
 	view->show = show_log_view;
 	view->input = input_log_view;
 	view->close = close_log_view;
@@ -2019,7 +2205,7 @@ show_log_view(struct tog_view *view)
 	return draw_commits(view, &s->last_displayed_entry,
 	    &s->selected_entry, s->first_displayed_entry,
 	    &s->commits, s->selected, view->nlines, s->refs,
-	    s->in_repo_path, s->thread_args.commits_needed);
+	    s->in_repo_path, s->thread_args.commits_needed, &s->colors);
 }
 
 static const struct got_error *
@@ -2727,103 +2913,6 @@ diff_view_indicate_progress(struct tog_view *view)
 }
 
 static const struct got_error *
-add_color(struct tog_colors *colors, const char *pattern,
-    int idx, short color)
-{
-	const struct got_error *err = NULL;
-	struct tog_color *tc;
-	int regerr = 0;
-
-	init_pair(idx, color, -1);
-
-	tc = calloc(1, sizeof(*tc));
-	if (tc == NULL)
-		return got_error_from_errno("calloc");
-	regerr = regcomp(&tc->regex, pattern,
-	    REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
-	if (regerr) {
-		static char regerr_msg[512];
-		static char err_msg[512];
-		regerror(regerr, &tc->regex, regerr_msg,
-		    sizeof(regerr_msg));
-		snprintf(err_msg, sizeof(err_msg), "regcomp: %s",
-		    regerr_msg);
-		err = got_error_msg(GOT_ERR_REGEX, err_msg);
-		free(tc);
-		return err;
-	}
-	tc->colorpair = idx;
-	SIMPLEQ_INSERT_HEAD(colors, tc, entry);
-	return NULL;
-}
-
-static void
-free_colors(struct tog_colors *colors)
-{
-	struct tog_color *tc;
-
-	while (!SIMPLEQ_EMPTY(colors)) {
-		tc = SIMPLEQ_FIRST(colors);
-		SIMPLEQ_REMOVE_HEAD(colors, entry);
-		regfree(&tc->regex);
-		free(tc);
-	}
-}
-
-static int
-default_color_value(const char *envvar)
-{
-	if (strcmp(envvar, "TOG_COLOR_DIFF_MINUS") == 0)
-		return COLOR_MAGENTA;
-	if (strcmp(envvar, "TOG_COLOR_DIFF_PLUS") == 0)
-		return COLOR_CYAN;
-	if (strcmp(envvar, "TOG_COLOR_DIFF_CHUNK_HEADER") == 0)
-		return COLOR_YELLOW;
-	if (strcmp(envvar, "TOG_COLOR_DIFF_META") == 0)
-		return COLOR_GREEN;
-	if (strcmp(envvar, "TOG_COLOR_TREE_SUBMODULE") == 0)
-		return COLOR_MAGENTA;
-	if (strcmp(envvar, "TOG_COLOR_TREE_SYMLINK") == 0)
-		return COLOR_CYAN;
-	if (strcmp(envvar, "TOG_COLOR_TREE_DIRECTORY") == 0)
-		return COLOR_BLUE;
-	if (strcmp(envvar, "TOG_COLOR_TREE_EXECUTABLE") == 0)
-		return COLOR_GREEN;
-
-	return -1;
-}
-
-static int
-get_color_value(const char *envvar)
-{
-	const char *val = getenv(envvar);
-
-	if (val == NULL)
-		return default_color_value(envvar);
-
-	if (strcasecmp(val, "black") == 0)
-		return COLOR_BLACK;
-	if (strcasecmp(val, "red") == 0)
-		return COLOR_RED;
-	if (strcasecmp(val, "green") == 0)
-		return COLOR_GREEN;
-	if (strcasecmp(val, "yellow") == 0)
-		return COLOR_YELLOW;
-	if (strcasecmp(val, "blue") == 0)
-		return COLOR_BLUE;
-	if (strcasecmp(val, "magenta") == 0)
-		return COLOR_MAGENTA;
-	if (strcasecmp(val, "cyan") == 0)
-		return COLOR_CYAN;
-	if (strcasecmp(val, "white") == 0)
-		return COLOR_WHITE;
-	if (strcasecmp(val, "default") == 0)
-		return -1;
-
-	return default_color_value(envvar);
-}
-
-static const struct got_error *
 open_diff_view(struct tog_view *view, struct got_object_id *id1,
     struct got_object_id *id2, struct tog_view *log_view,
     struct got_reflist_head *refs, struct got_repository *repo)
@@ -2867,17 +2956,19 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
 
 	if (has_colors() && getenv("TOG_COLORS") != NULL) {
 		err = add_color(&view->state.diff.colors,
-		    "^-", 1, get_color_value("TOG_COLOR_DIFF_MINUS"));
+		    "^-", TOG_COLOR_DIFF_MINUS,
+		    get_color_value("TOG_COLOR_DIFF_MINUS"));
 		if (err)
 			return err;
-		err = add_color(&view->state.diff.colors,
-		    "^\\+", 2, get_color_value("TOG_COLOR_DIFF_PLUS"));
+		err = add_color(&view->state.diff.colors, "^\\+",
+		    TOG_COLOR_DIFF_PLUS,
+		    get_color_value("TOG_COLOR_DIFF_PLUS"));
 		if (err) {
 			free_colors(&view->state.diff.colors);
 			return err;
 		}
 		err = add_color(&view->state.diff.colors, 
-		    "^@@", 3,
+		    "^@@", TOG_COLOR_DIFF_CHUNK_HEADER,
 		    get_color_value("TOG_COLOR_DIFF_CHUNK_HEADER"));
 		if (err) {
 			free_colors(&view->state.diff.colors);
@@ -2885,12 +2976,28 @@ open_diff_view(struct tog_view *view, struct got_object_id *id1,
 		}
 
 		err = add_color(&view->state.diff.colors, 
-		    "^(commit|(blob|file) [-+] )", 4,
+		    "^(commit|(blob|file) [-+] )", TOG_COLOR_DIFF_META,
 		    get_color_value("TOG_COLOR_DIFF_META"));
 		if (err) {
 			free_colors(&view->state.diff.colors);
 			return err;
 		}
+
+		err = add_color(&view->state.diff.colors, 
+		    "^(from|via): ", TOG_COLOR_AUTHOR,
+		    get_color_value("TOG_COLOR_AUTHOR"));
+		if (err) {
+			free_colors(&view->state.diff.colors);
+			return err;
+		}
+
+		err = add_color(&view->state.diff.colors, 
+		    "^date: ", TOG_COLOR_DATE,
+		    get_color_value("TOG_COLOR_DATE"));
+		if (err) {
+			free_colors(&view->state.diff.colors);
+			return err;
+		}
 	}
 
 	if (log_view && view_is_splitscreen(view))
@@ -3221,7 +3328,8 @@ static const struct got_error *
 draw_blame(struct tog_view *view, struct got_object_id *id, FILE *f,
     const char *path, struct tog_blame_line *lines, int nlines,
     int blame_complete, int selected_line, int *first_displayed_line,
-    int *last_displayed_line, int *eof, int max_lines)
+    int *last_displayed_line, int *eof, int max_lines,
+    struct tog_colors *colors)
 {
 	const struct got_error *err;
 	int lineno = 0, nprinted = 0;
@@ -3232,6 +3340,7 @@ draw_blame(struct tog_view *view, struct got_object_id *id, FILE *f,
 	struct tog_blame_line *blame_line;
 	struct got_object_id *prev_id = NULL;
 	char *id_str;
+	struct tog_color *tc;
 
 	err = got_object_id_str(&id_str, id);
 	if (err)
@@ -3253,7 +3362,14 @@ draw_blame(struct tog_view *view, struct got_object_id *id, FILE *f,
 		return err;
 	if (view_needs_focus_indication(view))
 		wstandout(view->window);
+	tc = get_color(colors, TOG_COLOR_COMMIT);
+	if (tc)
+		wattr_on(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
+	if (tc)
+		wattr_off(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	if (view_needs_focus_indication(view))
 		wstandend(view->window);
 	free(wline);
@@ -3324,7 +3440,14 @@ draw_blame(struct tog_view *view, struct got_object_id *id, FILE *f,
 					free(wline);
 					return err;
 				}
+				tc = get_color(colors, TOG_COLOR_COMMIT);
+				if (tc)
+					wattr_on(view->window,
+					    COLOR_PAIR(tc->colorpair), NULL);
 				wprintw(view->window, "%.8s", id_str);
+				if (tc)
+					wattr_off(view->window,
+					    COLOR_PAIR(tc->colorpair), NULL);
 				free(id_str);
 				prev_id = blame_line->id;
 			} else {
@@ -3620,6 +3743,14 @@ open_blame_view(struct tog_view *view, char *path,
 	s->commit_id = commit_id;
 	memset(&s->blame, 0, sizeof(s->blame));
 
+	SIMPLEQ_INIT(&s->colors);
+	if (has_colors() && getenv("TOG_COLORS") != NULL) {
+		err = add_color(&s->colors, "^", TOG_COLOR_COMMIT,
+		    get_color_value("TOG_COLOR_COMMIT"));
+		if (err)
+			return err;
+	}
+
 	view->show = show_blame_view;
 	view->input = input_blame_view;
 	view->close = close_blame_view;
@@ -3649,6 +3780,7 @@ close_blame_view(struct tog_view *view)
 	}
 
 	free(s->path);
+	free_colors(&s->colors);
 
 	return err;
 }
@@ -3753,7 +3885,7 @@ show_blame_view(struct tog_view *view)
 	err = draw_blame(view, s->blamed_commit->id, s->blame.f,
 	    s->path, s->blame.lines, s->blame.nlines, s->blame_complete,
 	    s->selected_line, &s->first_displayed_line,
-	    &s->last_displayed_line, &s->eof, view->nlines);
+	    &s->last_displayed_line, &s->eof, view->nlines, &s->colors);
 
 	view_vborder(view);
 	return err;
@@ -4147,7 +4279,14 @@ draw_tree_entries(struct tog_view *view,
 		return err;
 	if (view_needs_focus_indication(view))
 		wstandout(view->window);
+	tc = get_color(colors, TOG_COLOR_COMMIT);
+	if (tc)
+		wattr_on(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
+	if (tc)
+		wattr_off(view->window,
+		    COLOR_PAIR(tc->colorpair), NULL);
 	if (view_needs_focus_indication(view))
 		wstandend(view->window);
 	free(wline);
@@ -4446,25 +4585,35 @@ open_tree_view(struct tog_view *view, struct got_tree_object *root,
 	SIMPLEQ_INIT(&s->colors);
 
 	if (has_colors() && getenv("TOG_COLORS") != NULL) {
-		err = add_color(&s->colors,
-		    "\\$$", 1, get_color_value("TOG_COLOR_TREE_SUBMODULE"));
+		err = add_color(&s->colors, "\\$$",
+		    TOG_COLOR_TREE_SUBMODULE,
+		    get_color_value("TOG_COLOR_TREE_SUBMODULE"));
 		if (err)
 			goto done;
-		err = add_color(&s->colors,
-		    "@$", 2, get_color_value("TOG_COLOR_TREE_SYMLINK"));
+		err = add_color(&s->colors, "@$", TOG_COLOR_TREE_SYMLINK,
+		    get_color_value("TOG_COLOR_TREE_SYMLINK"));
+		if (err) {
+			free_colors(&s->colors);
+			goto done;
+		}
+		err = add_color(&s->colors, "/$",
+		    TOG_COLOR_TREE_DIRECTORY,
+		    get_color_value("TOG_COLOR_TREE_DIRECTORY"));
 		if (err) {
 			free_colors(&s->colors);
 			goto done;
 		}
-		err = add_color(&s->colors, 
-		    "/$", 3, get_color_value("TOG_COLOR_TREE_DIRECTORY"));
+
+		err = add_color(&s->colors, "\\*$",
+		    TOG_COLOR_TREE_EXECUTABLE,
+		    get_color_value("TOG_COLOR_TREE_EXECUTABLE"));
 		if (err) {
 			free_colors(&s->colors);
 			goto done;
 		}
 
-		err = add_color(&s->colors, 
-		    "\\*$", 4, get_color_value("TOG_COLOR_TREE_EXECUTABLE"));
+		err = add_color(&s->colors, "^$", TOG_COLOR_COMMIT,
+		    get_color_value("TOG_COLOR_COMMIT"));
 		if (err) {
 			free_colors(&s->colors);
 			goto done;