Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how a toggle option value is shown on the status line #944

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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