Skip to content

Commit 06e0edc

Browse files
committed
Add option to tune diff highlighting
The new option `diff-column-highlight` can be set to highlight all changed lines, only empty added/removed lines, or to not highlight in any special way. This option is only in effect when `diff-show-signs` is turned off. Default is to only highlight empty lines.
1 parent 1e9d807 commit 06e0edc

8 files changed

+139
-1
lines changed

doc/tigrc.5.adoc

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ The following variables can be set:
277277
that disabling signs only makes sense when coloring is used to
278278
distinguish added and removed lines. On by default.
279279
280+
'diff-column-highlight' (enum) [no|all|only-empty]::
281+
282+
Highlight the left-most column in diff views visually when the option
283+
'diff-show-signs' is not in effect. All added/removed lines can be
284+
highlighted, or only empty lines. Changed lines are indicated in the
285+
first column by a space highlighted by the color `diff-add-highlight` or
286+
`diff-del-highlight`, respectively. Keeping the `standout` (reverse)
287+
property set for these is suggested, as white space is otherwise
288+
invisible. Default is to highlight only empty lines.
289+
280290
'diff-highlight' (mixed)::
281291
282292
Whether to highlight diffs using Git's 'diff-highlight' program. Defaults

include/tig/options.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ typedef struct view_column *view_settings;
3838
_(diff_context, int, VIEW_DIFF_LIKE) \
3939
_(diff_noprefix, bool, VIEW_NO_FLAGS) \
4040
_(diff_show_signs, bool, VIEW_NO_FLAGS) \
41+
_(diff_column_highlight, enum diff_column_highlight, VIEW_NO_FLAGS) \
4142
_(diff_options, const char **, VIEW_DIFF_LIKE) \
4243
_(diff_highlight, const char *, VIEW_DIFF_LIKE) \
4344
_(diff_view, view_settings, VIEW_NO_FLAGS) \

include/tig/types.h

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value,
161161
_(REFRESH_MODE, AFTER_COMMAND), \
162162
_(REFRESH_MODE, PERIODIC),
163163

164+
#define DIFF_COLUMN_HIGHLIGHT_ENUM(_) \
165+
_(DIFF_COLUMN_HIGHLIGHT, NO), \
166+
_(DIFF_COLUMN_HIGHLIGHT, ALL), \
167+
_(DIFF_COLUMN_HIGHLIGHT, ONLY_EMPTY)
168+
164169
#define ENUM_INFO(_) \
165170
_(author, AUTHOR_ENUM) \
166171
_(commit_order, COMMIT_ORDER_ENUM) \
@@ -176,6 +181,7 @@ bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value,
176181
_(reference_type, REFERENCE_ENUM) \
177182
_(refresh_mode, REFRESH_MODE_ENUM) \
178183
_(status_label, STATUS_LABEL_ENUM) \
184+
_(diff_column_highlight, DIFF_COLUMN_HIGHLIGHT_ENUM) \
179185

180186
#define DEFINE_ENUMS(name, macro) DEFINE_ENUM(name, macro)
181187
ENUM_INFO(DEFINE_ENUMS)

src/draw.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,29 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
8080
!opt_diff_show_signs &&
8181
view->col == 0 &&
8282
(type == LINE_DIFF_ADD || type == LINE_DIFF_DEL || type == LINE_DEFAULT) &&
83-
(string[0] == ' ' || string[0] == '+' || string[0] == '-')
83+
(string[0] == ' ' || string[0] == '+' || string[0] == '-')
8484
) {
85+
if (opt_diff_column_highlight == DIFF_COLUMN_HIGHLIGHT_ALL) {
86+
if (type == LINE_DIFF_ADD) {
87+
set_view_attr(view, LINE_DIFF_ADD_HIGHLIGHT);
88+
} else if (type == LINE_DIFF_DEL) {
89+
set_view_attr(view, LINE_DIFF_DEL_HIGHLIGHT);
90+
}
91+
waddch(view->win, ' ');
92+
set_view_attr(view, type);
93+
}
94+
else if (opt_diff_column_highlight == DIFF_COLUMN_HIGHLIGHT_ONLY_EMPTY && len == 1) {
95+
if (type == LINE_DIFF_ADD) {
96+
set_view_attr(view, LINE_DIFF_ADD_HIGHLIGHT);
97+
waddch(view->win, ' ');
98+
} else if (type == LINE_DIFF_DEL) {
99+
set_view_attr(view, LINE_DIFF_DEL_HIGHLIGHT);
100+
waddch(view->win, ' ');
101+
}
102+
103+
set_view_attr(view, type);
104+
}
105+
85106
waddnstr(view->win, string+1, len-1);
86107
} else {
87108
waddnstr(view->win, string, len);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
. libtest.sh
4+
. libgit.sh
5+
6+
tigrc <<EOF
7+
set diff-show-signs = false
8+
set diff-column-highlight = all
9+
EOF
10+
11+
steps '
12+
:save-display diff-hide-signs.screen
13+
'
14+
15+
in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
16+
17+
test_tig show master^
18+
19+
assert_equals 'diff-hide-signs.screen' '' <<EOF
20+
commit a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff
21+
Author: Jonas Fonseca <[email protected]>
22+
AuthorDate: Sat Mar 1 15:59:02 2014 -0500
23+
Commit: Jonas Fonseca <[email protected]>
24+
CommitDate: Sat Mar 1 15:59:02 2014 -0500
25+
26+
Add type parameter for js.Dynamic
27+
---
28+
common/src/main/scala/org/scalajs/benchmark/Benchmark.scala | 2 +-
29+
1 file changed, 1 insertion(+), 1 deletion(-)
30+
31+
diff --git a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala b/commo
32+
index 65f914a..3aa4320 100644
33+
--- a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
34+
+++ b/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
35+
@@ -15,7 +15,7 @@ object Benchmark {
36+
val benchmarks = js.Array[Benchmark]()
37+
val benchmarkApps = js.Array[BenchmarkApp]()
38+
39+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary]
40+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary[js.Any]]
41+
global("runScalaJSBenchmarks") = runBenchmarks _
42+
global("initScalaJSBenchmarkApps") = initBenchmarkApps _
43+
44+
45+
46+
47+
48+
[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff - line 1 of 24 100%
49+
EOF
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
. libtest.sh
4+
. libgit.sh
5+
6+
tigrc <<EOF
7+
set diff-show-signs = false
8+
set diff-column-highlight = only-empty
9+
EOF
10+
11+
steps '
12+
:save-display diff-hide-signs.screen
13+
'
14+
15+
in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
16+
17+
test_tig show master^
18+
19+
assert_equals 'diff-hide-signs.screen' '' <<EOF
20+
commit a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff
21+
Author: Jonas Fonseca <[email protected]>
22+
AuthorDate: Sat Mar 1 15:59:02 2014 -0500
23+
Commit: Jonas Fonseca <[email protected]>
24+
CommitDate: Sat Mar 1 15:59:02 2014 -0500
25+
26+
Add type parameter for js.Dynamic
27+
---
28+
common/src/main/scala/org/scalajs/benchmark/Benchmark.scala | 2 +-
29+
1 file changed, 1 insertion(+), 1 deletion(-)
30+
31+
diff --git a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala b/commo
32+
index 65f914a..3aa4320 100644
33+
--- a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
34+
+++ b/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
35+
@@ -15,7 +15,7 @@ object Benchmark {
36+
val benchmarks = js.Array[Benchmark]()
37+
val benchmarkApps = js.Array[BenchmarkApp]()
38+
39+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary]
40+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary[js.Any]]
41+
global("runScalaJSBenchmarks") = runBenchmarks _
42+
global("initScalaJSBenchmarkApps") = initBenchmarkApps _
43+
44+
45+
46+
47+
48+
[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff - line 1 of 24 100%
49+
EOF

test/diff/diff-hide-signs-test

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
tigrc <<EOF
77
set diff-show-signs = false
8+
set diff-column-hightlight = no
89
EOF
910

1011
steps '

tigrc

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff)
115115
#set diff-highlight = true # String (or bool): Path to diff-highlight script,
116116
# defaults to `diff-highlight`.
117117
set diff-show-signs = yes # Show diff signs (+ and -) at the start of diff lines
118+
set diff-column-highlight = only-empty # Enum: no, all, only-empty
118119
#set blame-options = -C -C -C # User-defined options for `tig blame` (git-blame)
119120
#set log-options = --pretty=raw # User-defined options for `tig log` (git-log)
120121
#set main-options = -n 1000 # User-defined options for `tig` (git-log)

0 commit comments

Comments
 (0)