From 388d395360622513c6693c8c2998540524549a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Andersson?= Date: Sun, 3 Mar 2019 12:05:20 +0100 Subject: [PATCH] Add support for hiding diff signs (leading + and -) The `+` and `-` signs in diff views can be removed by setting the new option `diff-hide-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 --- doc/tigrc.5.adoc | 10 +++++++ include/tig/options.h | 1 + src/draw.c | 20 +++++++++++++- test/diff/diff-hide-signs-test | 48 ++++++++++++++++++++++++++++++++++ tigrc | 1 + 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 test/diff/diff-hide-signs-test diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 0570836cf..e48217342 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -270,6 +270,16 @@ The following variables can be set: Number of context lines to show for diffs. +'diff-hide-signs' (bool):: + + Hide the leading `+` and `-` signs in diff output. Copy-paste of lines + from the diff view may be aided by this option. Enabling this only makes + sense when coloring is used to distinguish added and removed lines. + Removed and added lines are indicated in the first column by a space + highlighted by the color `diff-add-highlight` or `diff-del-highlight`, + respectively. Keeping the `standout` (reverse) property set for these is + suggested, as white space is otherwise invisible. Off by default. + 'diff-highlight' (mixed):: Whether to highlight diffs using Git's 'diff-highlight' program. Defaults diff --git a/include/tig/options.h b/include/tig/options.h index c02291996..3226edd0d 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -37,6 +37,7 @@ typedef struct view_column *view_settings; _(commit_order, enum commit_order, VIEW_LOG_LIKE) \ _(diff_context, int, VIEW_DIFF_LIKE) \ _(diff_noprefix, bool, VIEW_NO_FLAGS) \ + _(diff_hide_signs, bool, VIEW_NO_FLAGS) \ _(diff_options, const char **, VIEW_DIFF_LIKE) \ _(diff_highlight, const char *, VIEW_DIFF_LIKE) \ _(diff_view, view_settings, VIEW_NO_FLAGS) \ diff --git a/src/draw.c b/src/draw.c index bec721089..d25f9b013 100644 --- a/src/draw.c +++ b/src/draw.c @@ -75,7 +75,25 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt set_view_attr(view, type); if (len > 0) - waddnstr(view->win, string, len); + { + if (opt_diff_hide_signs && + view->col == 0 && + (type == LINE_DIFF_ADD || type == LINE_DIFF_DEL) + ) { + /* Mark first column by color-only for add/del line */ + if (type == LINE_DIFF_ADD) + set_view_attr(view, LINE_DIFF_ADD_HIGHLIGHT); + else if (type == LINE_DIFF_DEL) + set_view_attr(view, LINE_DIFF_DEL_HIGHLIGHT); + waddnstr(view->win, " ", 1); + + /* Add the actual diff line */ + set_view_attr(view, type); + waddnstr(view->win, string+1, len-1); + } else { + waddnstr(view->win, string, len); + } + } if (trimmed && use_tilde) { set_view_attr(view, LINE_DELIMITER); diff --git a/test/diff/diff-hide-signs-test b/test/diff/diff-hide-signs-test new file mode 100755 index 000000000..8a65b6e98 --- /dev/null +++ b/test/diff/diff-hide-signs-test @@ -0,0 +1,48 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +tigrc < +AuthorDate: Sat Mar 1 15:59:02 2014 -0500 +Commit: Jonas Fonseca +CommitDate: Sat Mar 1 15:59:02 2014 -0500 + + Add type parameter for js.Dynamic +--- + common/src/main/scala/org/scalajs/benchmark/Benchmark.scala | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala b/commo +index 65f914a..3aa4320 100644 +--- a/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala ++++ b/common/src/main/scala/org/scalajs/benchmark/Benchmark.scala +@@ -15,7 +15,7 @@ object Benchmark { + val benchmarks = js.Array[Benchmark]() + val benchmarkApps = js.Array[BenchmarkApp]() + + val global = js.Dynamic.global.asInstanceOf[js.Dictionary] + val global = js.Dynamic.global.asInstanceOf[js.Dictionary[js.Any]] + global("runScalaJSBenchmarks") = runBenchmarks _ + global("initScalaJSBenchmarkApps") = initBenchmarkApps _ + + + + + +[diff] a1dcf1aaa11470978db1d5d8bcf9e16201eb70ff - line 1 of 24 100% +EOF diff --git a/tigrc b/tigrc index a8ceaa8d0..dc04ee5a4 100644 --- a/tigrc +++ b/tigrc @@ -114,6 +114,7 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff) #set diff-options = -C # User-defined options for `tig show` (git-diff) #set diff-highlight = true # String (or bool): Path to diff-highlight script, # defaults to `diff-highlight`. +set diff-hide-signs = no # Hide diff signs (+ and -) at the start of diff lines #set blame-options = -C -C -C # User-defined options for `tig blame` (git-blame) #set log-options = --pretty=raw # User-defined options for `tig log` (git-log) #set main-options = -n 1000 # User-defined options for `tig` (git-log)