Skip to content

Commit 54d0e72

Browse files
committed
Add support for hiding diff signs (leading + and -)
The `+` and `-` signs in diff views can be removed by changing the new option `diff-show-signs`. When set, only the color of the lines distinguishes added, removed and context lines. Empty added or removed lines are indicated by a space in column 0 with the "diff highlight" colors which has the `reverse` property by default. Closes #855
1 parent 93ea970 commit 54d0e72

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

doc/tigrc.5.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ The following variables can be set:
270270
271271
Number of context lines to show for diffs.
272272
273+
'diff-show-signs' (bool)::
274+
275+
Show (or hide) the leading `+` and `-` signs in diff output. Copy-paste
276+
of lines from the diff view may be aided by hiding these signs. Note
277+
that disabling signs only makes sense when coloring is used to
278+
distinguish added and removed lines. On by default.
279+
273280
'diff-highlight' (mixed)::
274281
275282
Whether to highlight diffs using Git's 'diff-highlight' program. Defaults

include/tig/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct view_column *view_settings;
3737
_(commit_order, enum commit_order, VIEW_LOG_LIKE) \
3838
_(diff_context, int, VIEW_DIFF_LIKE) \
3939
_(diff_noprefix, bool, VIEW_NO_FLAGS) \
40+
_(diff_show_signs, bool, VIEW_NO_FLAGS) \
4041
_(diff_options, const char **, VIEW_DIFF_LIKE) \
4142
_(diff_highlight, const char *, VIEW_DIFF_LIKE) \
4243
_(diff_view, view_settings, VIEW_NO_FLAGS) \

src/draw.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,25 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
7575

7676
set_view_attr(view, type);
7777
if (len > 0)
78-
waddnstr(view->win, string, len);
78+
{
79+
if (!opt_diff_show_signs &&
80+
view->col == 0 &&
81+
(type == LINE_DIFF_ADD || type == LINE_DIFF_DEL)
82+
) {
83+
/* Mark first column by color-only for add/del line */
84+
if (type == LINE_DIFF_ADD)
85+
set_view_attr(view, LINE_DIFF_ADD_HIGHLIGHT);
86+
else if (type == LINE_DIFF_DEL)
87+
set_view_attr(view, LINE_DIFF_DEL_HIGHLIGHT);
88+
waddnstr(view->win, " ", 1);
89+
90+
/* Add the actual diff line */
91+
set_view_attr(view, type);
92+
waddnstr(view->win, string+1, len-1);
93+
} else {
94+
waddnstr(view->win, string, len);
95+
}
96+
}
7997

8098
if (trimmed && use_tilde) {
8199
set_view_attr(view, LINE_DELIMITER);

test/diff/diff-hide-signs-test

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
3+
. libtest.sh
4+
. libgit.sh
5+
6+
tigrc <<EOF
7+
set diff-show-signs = false
8+
EOF
9+
10+
steps '
11+
:save-display diff-hide-signs.screen
12+
'
13+
14+
in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
15+
16+
test_tig show master^
17+
18+
assert_equals 'diff-hide-signs.screen' <<EOF
19+
commit a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff
20+
Author: Jonas Fonseca <[email protected]>
21+
AuthorDate: Sat Mar 1 15:59:02 2014 -0500
22+
Commit: Jonas Fonseca <[email protected]>
23+
CommitDate: Sat Mar 1 15:59:02 2014 -0500
24+
25+
Add type parameter for js.Dynamic
26+
---
27+
common/src/main/scala/org/scalajs/benchmark/Benchmark.scala | 2 +-
28+
1 file changed, 1 insertion(+), 1 deletion(-)
29+
30+
diff --git a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala b/commo
31+
index 65f914a..3aa4320 100644
32+
--- a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
33+
+++ b/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala
34+
@@ -15,7 +15,7 @@ object Benchmark {
35+
val benchmarks = js.Array[Benchmark]()
36+
val benchmarkApps = js.Array[BenchmarkApp]()
37+
38+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary]
39+
val global = js.Dynamic.global.asInstanceOf[js.Dictionary[js.Any]]
40+
global("runScalaJSBenchmarks") = runBenchmarks _
41+
global("initScalaJSBenchmarkApps") = initBenchmarkApps _
42+
43+
44+
45+
46+
47+
[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff - line 1 of 24 100%
48+
EOF

tigrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff)
114114
#set diff-options = -C # User-defined options for `tig show` (git-diff)
115115
#set diff-highlight = true # String (or bool): Path to diff-highlight script,
116116
# defaults to `diff-highlight`.
117+
set diff-show-signs = yes # Show diff signs (+ and -) at the start of diff lines
117118
#set blame-options = -C -C -C # User-defined options for `tig blame` (git-blame)
118119
#set log-options = --pretty=raw # User-defined options for `tig log` (git-log)
119120
#set main-options = -n 1000 # User-defined options for `tig` (git-log)

0 commit comments

Comments
 (0)