Skip to content

Commit

Permalink
Add option to tune diff highlighting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andebjor committed Mar 8, 2019
1 parent 54d0e72 commit 053eb5c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
10 changes: 10 additions & 0 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ The following variables can be set:
that disabling signs only makes sense when coloring is used to
distinguish added and removed lines. On by default.
'diff-column-highlight' (enum) [no|all|only-empty]::
Highlight the left-most column in diff views visually when the option
'diff-show-signs' is not in effect. All added/removed lines can be
highlighted, or only empty lines. Changed 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. Default is to highlight all lines.
'diff-highlight' (mixed)::
Whether to highlight diffs using Git's 'diff-highlight' program. Defaults
Expand Down
1 change: 1 addition & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct view_column *view_settings;
_(diff_context, int, VIEW_DIFF_LIKE) \
_(diff_noprefix, bool, VIEW_NO_FLAGS) \
_(diff_show_signs, bool, VIEW_NO_FLAGS) \
_(diff_column_highlight, enum diff_column_highlight, VIEW_NO_FLAGS) \
_(diff_options, const char **, VIEW_DIFF_LIKE) \
_(diff_highlight, const char *, VIEW_DIFF_LIKE) \
_(diff_view, view_settings, VIEW_NO_FLAGS) \
Expand Down
6 changes: 6 additions & 0 deletions include/tig/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value,
_(REFRESH_MODE, AFTER_COMMAND), \
_(REFRESH_MODE, PERIODIC),

#define DIFF_COLUMN_HIGHLIGHT_ENUM(_) \
_(DIFF_COLUMN_HIGHLIGHT, NO), \
_(DIFF_COLUMN_HIGHLIGHT, ALL), \
_(DIFF_COLUMN_HIGHLIGHT, ONLY_EMPTY)

#define ENUM_INFO(_) \
_(author, AUTHOR_ENUM) \
_(commit_order, COMMIT_ORDER_ENUM) \
Expand All @@ -176,6 +181,7 @@ bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value,
_(reference_type, REFERENCE_ENUM) \
_(refresh_mode, REFRESH_MODE_ENUM) \
_(status_label, STATUS_LABEL_ENUM) \
_(diff_column_highlight, DIFF_COLUMN_HIGHLIGHT_ENUM) \

#define DEFINE_ENUMS(name, macro) DEFINE_ENUM(name, macro)
ENUM_INFO(DEFINE_ENUMS)
Expand Down
16 changes: 9 additions & 7 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt
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);
if ( opt_diff_column_highlight != DIFF_COLUMN_HIGHLIGHT_NO &&
(opt_diff_column_highlight == DIFF_COLUMN_HIGHLIGHT_ALL || len == 1)
) {
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);
}

/* Add the actual diff line */
waddnstr(view->win, " ", 1);
set_view_attr(view, type);
waddnstr(view->win, string+1, len-1);
} else {
Expand Down
1 change: 1 addition & 0 deletions tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff)
#set diff-highlight = true # String (or bool): Path to diff-highlight script,
# defaults to `diff-highlight`.
set diff-show-signs = yes # Show diff signs (+ and -) at the start of diff lines
set diff-column-highlight = all # Enum: no, all, only-empty
#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)
Expand Down

0 comments on commit 053eb5c

Please sign in to comment.