Skip to content

Commit 053eb5c

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.
1 parent 54d0e72 commit 053eb5c

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

doc/tigrc.5.adoc

Lines changed: 10 additions & 0 deletions
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 all lines.
289+
280290
'diff-highlight' (mixed)::
281291
282292
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
@@ -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

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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ 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);
83+
if ( opt_diff_column_highlight != DIFF_COLUMN_HIGHLIGHT_NO &&
84+
(opt_diff_column_highlight == DIFF_COLUMN_HIGHLIGHT_ALL || len == 1)
85+
) {
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+
}
8991

90-
/* Add the actual diff line */
92+
waddnstr(view->win, " ", 1);
9193
set_view_attr(view, type);
9294
waddnstr(view->win, string+1, len-1);
9395
} 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-show-signs = yes # Show 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)