/* Wants: mode request key */ static enum status_code option_bind_command(int argc, const char *argv[]) { struct key key[1]; size_t keys = 0; enum request request; struct keymap *keymap; const char *key_arg; if (argc < 3) return error("Invalid key binding: bind keymap key action"); if (!(keymap = get_keymap(argv[0], strlen(argv[0])))) { if (!strcmp(argv[0], "branch")) keymap = get_keymap("refs", strlen("refs")); if (!keymap) return error("Unknown key map: %s", argv[0]); } for (keys = 0, key_arg = argv[1]; *key_arg && keys < ARRAY_SIZE(key); keys++) { enum status_code code = get_key_value(&key_arg, &key[keys]); if (code != SUCCESS) return code; } if (*key_arg && keys == ARRAY_SIZE(key)) return error("Except for <Esc> combos only one key is allowed " "in key combos: %s", argv[1]); request = get_request(argv[2]); if (request == REQ_UNKNOWN) { static const char *obsolete[][2] = { { "view-branch", "view-refs" }, }; static const char *toggles[][2] = { { "diff-context-down", "diff-context" }, { "diff-context-up", "diff-context" }, { "stage-next", ":/^@@" }, { "toggle-author", "author" }, { "toggle-changes", "show-changes" }, { "toggle-commit-order", "show-commit-order" }, { "toggle-date", "date" }, { "toggle-files", "file-filter" }, { "toggle-file-filter", "file-filter" }, { "toggle-file-size", "file-size" }, { "toggle-filename", "filename" }, { "toggle-graphic", "show-graphic" }, { "toggle-id", "id" }, { "toggle-ignore-space", "show-ignore-space" }, { "toggle-lineno", "line-number" }, { "toggle-refs", "commit-title-refs" }, { "toggle-rev-graph", "commit-title-graph" }, { "toggle-show-changes", "show-changes" }, { "toggle-sort-field", "sort-field" }, { "toggle-sort-order", "sort-order" }, { "toggle-title-overflow", "commit-title-overflow" }, { "toggle-untracked-dirs", "status-untracked-dirs" }, { "toggle-vertical-split", "show-vertical-split" }, }; int alias; alias = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[2]); if (alias != -1) { const char *action = obsolete[alias][1]; add_keybinding(keymap, get_request(action), key, keys); return error("%s has been renamed to %s", obsolete[alias][0], action); } alias = find_remapped(toggles, ARRAY_SIZE(toggles), argv[2]); if (alias != -1) { const char *action = toggles[alias][0]; const char *arg = prefixcmp(action, "diff-context-") ? NULL : (strstr(action, "-down") ? "-1" : "+1"); const char *mapped = toggles[alias][1]; const char *toggle[] = { ":toggle", mapped, arg, NULL}; const char *other[] = { mapped, NULL }; const char **prompt = *mapped == ':' ? other : toggle; enum status_code code = add_run_request(keymap, key, keys, prompt); if (code == SUCCESS) code = error("%s has been replaced by `%s%s%s%s'", action, prompt == other ? mapped : ":toggle ", prompt == other ? "" : mapped, arg ? " " : "", arg ? arg : ""); return code; } } if (request == REQ_UNKNOWN) return add_run_request(keymap, key, keys, argv + 2); return add_keybinding(keymap, request, key, keys); }
/* 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; }
/* Wants: name = value */ static enum status_code option_set_command(int argc, const char *argv[]) { struct option_info *option; if (argc < 3) return error("Invalid set command: set option = value"); if (strcmp(argv[1], "=")) return error("No value assigned to %s", argv[0]); if (!strcmp(argv[0], "reference-format")) return parse_ref_formats(argv + 2); option = find_option_info(option_info, ARRAY_SIZE(option_info), argv[0]); if (option) { enum status_code code; if (option->seen) return SUCCESS; if (!strcmp(option->type, "const char **")) { code = check_view_config(option, argv + 2); if (code != SUCCESS) return code; return parse_args(option->value, argv + 2); } code = parse_option(option, "", argv[2]); if (code == SUCCESS && argc != 3) return error("Option %s only takes one value", argv[0]); return code; } { const char *obsolete[][2] = { { "author-width", "author" }, { "filename-width", "file-name" }, { "line-number-interval", "line-number" }, { "show-author", "author" }, { "show-date", "date" }, { "show-file-size", "file-size" }, { "show-filename", "file-name" }, { "show-id", "id" }, { "show-line-numbers", "line-number" }, { "show-refs", "commit-title" }, { "show-rev-graph", "commit-title" }, { "title-overflow", "commit-title and text" }, }; int index = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[0]); if (index != -1) return error("%s is obsolete; see tigrc(5) for how to set the %s column option", 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]); }
/* Wants: mode request key */ static enum status_code option_bind_command(int argc, const char *argv[]) { struct key_input input; enum request request; struct keymap *keymap; if (argc < 3) return error("Invalid key binding: bind keymap key action"); if (!(keymap = get_keymap(argv[0], strlen(argv[0])))) { if (!strcmp(argv[0], "branch")) keymap = get_keymap("refs", strlen("refs")); if (!keymap) return error("Unknown key map: %s", argv[0]); } if (get_key_value(argv[1], &input) == ERR) return error("Unknown key: %s", argv[1]); request = get_request(argv[2]); if (request == REQ_UNKNOWN) { static const char *obsolete[][2] = { { "view-branch", "view-refs" }, }; static const char *toggles[][2] = { { "diff-context-down", "diff-context" }, { "diff-context-up", "diff-context" }, { "toggle-author", "show-author" }, { "toggle-changes", "show-changes" }, { "toggle-commit-order", "show-commit-order" }, { "toggle-date", "show-date" }, { "toggle-file-filter", "file-filter" }, { "toggle-file-size", "show-file-size" }, { "toggle-filename", "show-filename" }, { "toggle-graphic", "show-graphic" }, { "toggle-id", "show-id" }, { "toggle-ignore-space", "show-ignore-space" }, { "toggle-lineno", "show-line-numbers" }, { "toggle-refs", "show-refs" }, { "toggle-rev-graph", "show-rev-graph" }, { "toggle-sort-field", "sort-field" }, { "toggle-sort-order", "sort-order" }, { "toggle-title-overflow", "show-title-overflow" }, { "toggle-untracked-dirs", "status-untracked-dirs" }, { "toggle-vertical-split", "show-vertical-split" }, }; int alias; alias = find_remapped(obsolete, ARRAY_SIZE(obsolete), argv[2]); if (alias != -1) { const char *action = obsolete[alias][1]; add_keybinding(keymap, get_request(action), &input); return error("%s has been renamed to %s", obsolete[alias][0], action); } alias = find_remapped(toggles, ARRAY_SIZE(toggles), argv[2]); if (alias != -1) { const char *action = toggles[alias][0]; const char *arg = prefixcmp(action, "diff-context-") ? NULL : (strstr(action, "-down") ? "-1" : "+1"); const char *toggle[] = { ":toggle", toggles[alias][1], arg, NULL}; enum status_code code = add_run_request(keymap, &input, toggle); if (code == SUCCESS) code = error("%s has been replaced by `:toggle %s%s%s'", action, toggles[alias][1], arg ? " " : "", arg ? arg : ""); return code; } } if (request == REQ_UNKNOWN) return add_run_request(keymap, &input, argv + 2); return add_keybinding(keymap, request, &input); }