Skip to content

Commit

Permalink
Improve how a toggle option value is shown on the status line
Browse files Browse the repository at this point in the history
Whenever a view column option is toggled, the new setting is echoed on the status line, but it does not mimic what should be typed on the status line using the set command to achieve the same thing.

For example, the message 'set commit-title-graph = v1' is shown but the user needs to type ':set main-view-commit-title-graph = v1' on the status line to achieve the same setting, ie, the user needs to type colon to initiate prompt mode, and then type the view name as a prefix to the option name.

The PR modifies prompt_toggle_option() to show exactly what needs to be typed on the status line. The function called success() with a format string, an option name, and an option value to generate a status line for each type of option value. The format string is modified to include view->name as a prefix to option name. A macro wrapper for success() is used to reduce repetition.

Fixes issue #879.
  • Loading branch information
stevenyvr987 authored and koutcher committed Nov 6, 2019
1 parent 0684b8c commit 80b40c2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/prompt.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ static enum status_code
prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
struct option_info *toggle, enum view_flag *flags)
{
/* Define a partial version of success() to format the option name as a suffix to the view name,
* thereby reducing the arguments needed by success() to only the option value and its format string.
*/
#define Success(opt_fmt, opt_val) success(":set %s-view-%s = " opt_fmt, view->name, name, opt_val)

char name[SIZEOF_STR];

if (!enum_name_prefixed(name, sizeof(name), prefix, toggle->name))
Expand All @@ -731,15 +736,15 @@ prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
*opt = !*opt;
if (opt == &opt_mouse)
enable_mouse(*opt);
return success("set %s = %s", name, *opt ? "yes" : "no");
return Success("%s", *opt ? "yes" : "no");

} else if (!strncmp(toggle->type, "enum", 4)) {
const char *type = toggle->type + STRING_SIZE("enum ");
enum author *opt = toggle->value;
const struct enum_map *map = find_enum_map(type);

*opt = (*opt + 1) % map->size;
return success("set %s = %s", name, enum_name(map->entries[*opt].name));
return Success("%s", enum_name(map->entries[*opt].name));

} else if (!strcmp(toggle->type, "int")) {
const char *arg = argv[2] ? argv[2] : "1";
Expand All @@ -761,12 +766,12 @@ prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
if (strstr(name, "commit-title-overflow")) {
*opt = *opt ? -*opt : 50;
if (*opt < 0)
return success("set %s = no", name);
return Success("%s", "no");
diff = 0;
}

*opt += diff;
return success("set %s = %d", name, *opt);
return Success("%d", *opt);

} else if (!strcmp(toggle->type, "double")) {
const char *arg = argv[2] ? argv[2] : "1.0";
Expand All @@ -783,7 +788,7 @@ prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
diff = strtod(arg, NULL);

*opt += sign * diff;
return success("set %s = %.2f", name, *opt);
return Success("%.2f", *opt);

} else if (!strcmp(toggle->type, "const char **")) {
const char ***opt = toggle->value;
Expand Down Expand Up @@ -826,6 +831,7 @@ prompt_toggle_option(struct view *view, const char *argv[], const char *prefix,
} else {
return error("Unsupported `:toggle %s` (%s)", name, toggle->type);
}
#undef Success
}

static enum status_code
Expand Down

0 comments on commit 80b40c2

Please sign in to comment.