Skip to content

Commit fc33964

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-hide-signs` is turned on.
1 parent 388d395 commit fc33964

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

doc/tigrc.5.adoc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,18 @@ The following variables can be set:
274274
275275
Hide the leading `+` and `-` signs in diff output. Copy-paste of lines
276276
from the diff view may be aided by this option. Enabling this only makes
277-
sense when coloring is used to distinguish added and removed lines.
278-
Removed and added lines are indicated in the first column by a space
279-
highlighted by the color `diff-add-highlight` or `diff-del-highlight`,
280-
respectively. Keeping the `standout` (reverse) property set for these is
281-
suggested, as white space is otherwise invisible. Off by default.
277+
sense when coloring is used to distinguish added and removed lines. Off
278+
by default.
279+
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-hide-signs' is 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 all lines.
282289
283290
'diff-highlight' (mixed)::
284291

include/tig/options.h

Lines changed: 1 addition & 0 deletions
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_hide_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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,15 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
8080
view->col == 0 &&
8181
(type == LINE_DIFF_ADD || type == LINE_DIFF_DEL)
8282
) {
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 */
83+
if (opt_diff_column_highlight != DIFF_COLUMN_HIGHLIGHT_NO) {
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+
if (opt_diff_column_highlight == DIFF_COLUMN_HIGHLIGHT_ALL || len == 1) {
89+
waddnstr(view->win, " ", 1);
90+
}
91+
}
9192
set_view_attr(view, type);
9293
waddnstr(view->win, string+1, len-1);
9394
} else {

tigrc

Lines changed: 1 addition & 0 deletions
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-hide-signs = no # Hide diff signs (+ and -) at the start of diff lines
118+
set diff-column-highlight = all # 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)