From 6c58ecc3a29e7dd0387ca3dc241d7c43d5cfaf3a Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 27 Apr 2014 01:43:07 -0400 Subject: [PATCH] Move git color mappings to tigrc --- NEWS.adoc | 1 + doc/tigrc.5.adoc | 12 +++++++----- include/tig/options.h | 2 +- src/options.c | 51 ++++++++++++++++++++------------------------------- tigrc | 27 ++++++++++++++++++++++++++- 5 files changed, 55 insertions(+), 38 deletions(-) diff --git a/NEWS.adoc b/NEWS.adoc index 0924f45..d7f51d5 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -79,6 +79,7 @@ Improvements: - Add support for `--graph` and highlight diff stats in the log view. - Add builtin command bindings: `!` to delete branch, `!` to drop stash. - Add %(remote) and %(tag) symbols to complement %(branch). + - Git color mappings can be configured in tigrc. Bug fixes: diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index cfc8e67..b8badae 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -49,8 +49,8 @@ the Git configuration: 'color.*':: - Colors for the various UI types. Can be completely disabled by setting - 'read-git-colors'. + Colors for the various UI types. Can be configured via the 'git-colors' + setting. 'core.abbrev':: @@ -85,7 +85,7 @@ Examples: -------------------------------------------------------------------------- set commit-order = topo # Order commits topologically -set read-git-colors = no # Do not read Git's color settings. +set git-colors = no # Do not read Git's color settings. set horizontal-scroll = 33% # Scroll 33% of the view width set blame-options = -C -C -C # Blame lines from other files @@ -183,9 +183,11 @@ The following variables can be set: Mouse support requires that ncurses itself support mouse events and that you have enabled mouse support in ~/.tigrc with `set mouse = true`. -'read-git-colors' (bool):: +'git-colors' (list):: - Whether to read Git's color settings. True by default. + A space separated list of "key=value" pairs where the key is a Git color + name and the value is a Tig color name, e.g. "branch.current=main-head" + and "grep.filename=grep.file". Set to "no" to disable. 'show-notes' (mixed) [note reference | bool]:: diff --git a/include/tig/options.h b/include/tig/options.h index 8ef2cba..1b4ddf4 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -33,6 +33,7 @@ _(editor_line_number, bool, VIEW_NO_FLAGS) \ _(file_filter, bool, VIEW_DIFF_LIKE | VIEW_LOG_LIKE) \ _(focus_child, bool, VIEW_NO_FLAGS) \ + _(git_colors, const char **, VIEW_NO_FLAGS) \ _(grep_view, const char **, VIEW_NO_FLAGS) \ _(horizontal_scroll, double, VIEW_NO_FLAGS) \ _(id_width, int, VIEW_NO_FLAGS) \ @@ -44,7 +45,6 @@ _(mouse, bool, VIEW_NO_FLAGS) \ _(mouse_scroll, int, VIEW_NO_FLAGS) \ _(pager_view, const char **, VIEW_NO_FLAGS) \ - _(read_git_colors, bool, VIEW_NO_FLAGS) \ _(refs_view, const char **, VIEW_NO_FLAGS) \ _(show_changes, bool, VIEW_NO_FLAGS) \ _(show_notes, bool, VIEW_NO_FLAGS) \ diff --git a/src/options.c b/src/options.c index 479f7f2..fd43acf 100644 --- a/src/options.c +++ b/src/options.c @@ -616,6 +616,9 @@ option_set_command(int argc, const char *argv[]) if (index != -1) return error("%s is obsolete; use the %s view column options instead", obsolete[index][0], obsolete[index][1]); + + if (!strcmp(argv[0], "read-git-colors")) + return error("read-git-colors has been obsoleted by the git-colors option"); } return error("Unknown option name: %s", argv[0]); @@ -970,46 +973,32 @@ parse_git_color_option(struct line_info *info, char *value) static void set_git_color_option(const char *name, char *value) { - static const char *git_colors[][2] = { - { "branch.current", "main-head" }, - { "branch.local", "main-ref" }, - { "branch.plain", "main-ref" }, - { "branch.remote", "main-remote" }, - - { "diff.meta", "diff-header" }, - { "diff.meta", "diff-index" }, - { "diff.meta", "diff-oldmode" }, - { "diff.meta", "diff-newmode" }, - { "diff.frag", "diff-chunk" }, - { "diff.old", "diff-del" }, - { "diff.new", "diff-add" }, - - { "grep.filename", "grep.file" }, - { "grep.linenumber", "grep.line-number" }, - { "grep.separator", "grep.delimiter" }, - - { "status.branch", "status.header" }, - { "status.added", "stat-staged" }, - { "status.updated", "stat-staged" }, - { "status.changed", "stat-unstaged" }, - { "status.untracked", "stat-untracked" }, - }; struct line_info parsed = {}; + struct line_info *color = NULL; + size_t namelen = strlen(name); int i; - if (!opt_read_git_colors) - return; - - i = find_remapped(git_colors, ARRAY_SIZE(git_colors), name); - if (i < 0 || !parse_git_color_option(&parsed, value)) + if (!opt_git_colors) return; - for (; i < ARRAY_SIZE(git_colors) && !strcasecmp(git_colors[i][0], name); i++) { + for (i = 0; opt_git_colors[i]; i++) { struct line_rule rule = {}; const char *prefix = NULL; struct line_info *info; + const char *alias = opt_git_colors[i]; + const char *sep = strchr(alias, '='); + + if (!sep || namelen != sep - alias || + string_enum_compare(name, alias, namelen)) + continue; + + if (!color) { + color = parse_git_color_option(&parsed, value); + if (!color) + return; + } - if (parse_color_name(git_colors[i][1], &rule, &prefix) == SUCCESS && + if (parse_color_name(sep + 1, &rule, &prefix) == SUCCESS && (info = add_line_rule(prefix, &rule))) { info->fg = parsed.fg; info->bg = parsed.bg; diff --git a/tigrc b/tigrc index 608be56..355367d 100644 --- a/tigrc +++ b/tigrc @@ -95,7 +95,6 @@ set show-notes = yes # When non-bool passed as `--show-notes=...` (diff) #set blame-options = -C -C -C # User-defined options for `tig blame` (blame) # Misc -set read-git-colors = yes # Use Git colors? set ignore-case = no # Ignore case when searching? set focus-child = yes # Move focus to child view when opened? set horizontal-scroll = 50% # Number of columns to scroll as % of width @@ -360,3 +359,29 @@ color palette-4 default default color palette-5 white default color palette-6 red default color graph-commit blue default + +# Mappings for colors read from git configuration. +# Set to "no" to disable. +set git-colors = \ + branch.current=main-head \ + branch.local=main-ref \ + branch.plain=main-ref \ + branch.remote=main-remote \ + \ + diff.meta=diff-header \ + diff.meta=diff-index \ + diff.meta=diff-oldmode \ + diff.meta=diff-newmode \ + diff.frag=diff-chunk \ + diff.old=diff-del \ + diff.new=diff-add \ + \ + grep.filename=grep.file \ + grep.linenumber=grep.line-number \ + grep.separator=grep.delimiter \ + \ + status.branch=status.header \ + status.added=stat-staged \ + status.updated=stat-staged \ + status.changed=stat-unstaged \ + status.untracked=stat-untracked -- 2.11.4.GIT