/* Wants: object fgcolor bgcolor [attribute] */ static enum status_code option_color_command(int argc, const char *argv[]) { struct line_rule rule = {}; const char *prefix = NULL; struct line_info *info; enum status_code code; if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; code = parse_color_name(argv[0], &rule, &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); if (!info) { static const struct enum_map_entry obsolete[] = { ENUM_MAP_ENTRY("main-delim", LINE_DELIMITER), ENUM_MAP_ENTRY("main-date", LINE_DATE), ENUM_MAP_ENTRY("main-author", LINE_AUTHOR), ENUM_MAP_ENTRY("blame-id", LINE_ID), }; int index; if (!map_enum(&index, obsolete, argv[0])) return ERROR_UNKNOWN_COLOR_NAME; info = get_line_info(NULL, index); } if (!set_color(&info->fg, argv[1]) || !set_color(&info->bg, argv[2])) return ERROR_UNKNOWN_COLOR; info->attr = 0; while (argc-- > 3) { int attr; if (!set_attribute(&attr, argv[argc])) return ERROR_UNKNOWN_ATTRIBUTE; info->attr |= attr; } return SUCCESS; }
static void set_git_color_option(const char *name, char *value) { struct line_info parsed = {}; struct line_info *color = NULL; size_t namelen = strlen(name); int i; if (!opt_git_colors) return; 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(sep + 1, &rule, &prefix) == SUCCESS && (info = add_line_rule(prefix, &rule))) { info->fg = parsed.fg; info->bg = parsed.bg; info->attr = parsed.attr; } } }
/* Wants: object fgcolor bgcolor [attribute] */ static enum status_code option_color_command(int argc, const char *argv[]) { struct line_rule rule = {}; const char *prefix = NULL; struct line_info *info; enum status_code code; if (argc < 3) return error("Invalid color mapping: color area fgcolor bgcolor [attrs]"); code = parse_color_name(argv[0], &rule, &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); if (!info) { static const char *obsolete[][2] = { { "acked", "' Acked-by'" }, { "diff-copy-from", "'copy from '" }, { "diff-copy-to", "'copy to '" }, { "diff-deleted-file-mode", "'deleted file mode '" }, { "diff-dissimilarity", "'dissimilarity '" }, { "diff-rename-from", "'rename from '" }, { "diff-rename-to", "'rename to '" }, { "diff-tree", "'diff-tree '" }, { "filename", "file" }, { "help-keymap", "help.section" }, { "main-revgraph", "" }, { "pp-adate", "'AuthorDate: '" }, { "pp-author", "'Author: '" }, { "pp-cdate", "'CommitDate: '" }, { "pp-commit", "'Commit: '" }, { "pp-date", "'Date: '" }, { "reviewed", "' Reviewed-by'" }, { "signoff", "' Signed-off-by'" }, { "stat-head", "status.header" }, { "stat-section", "status.section" }, { "tested", "' Tested-by'" }, { "tree-dir", "tree.directory" }, { "tree-file", "tree.file" }, { "tree-head", "tree.header" }, }; int index; index = find_remapped(obsolete, ARRAY_SIZE(obsolete), rule.name); if (index != -1) { if (!*obsolete[index][1]) return error("%s is obsolete", argv[0]); /* Keep the initial prefix if defined. */ code = parse_color_name(obsolete[index][1], &rule, prefix ? NULL : &prefix); if (code != SUCCESS) return code; info = add_line_rule(prefix, &rule); } if (!info) return error("Unknown color name: %s", argv[0]); code = error("%s has been replaced by %s", obsolete[index][0], obsolete[index][1]); } if (!set_color(&info->fg, argv[1])) return error("Unknown color: %s", argv[1]); if (!set_color(&info->bg, argv[2])) return error("Unknown color: %s", argv[2]); info->attr = 0; while (argc-- > 3) { int attr; if (!set_attribute(&attr, argv[argc])) return error("Unknown color attribute: %s", argv[argc]); info->attr |= attr; } return code; }