/* Set a colour option. */ struct options_entry * cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq, const struct options_table_entry *oe, struct options *oo, const char *value) { int colour; if ((colour = colour_fromstring(value)) == -1) { cmdq_error(cmdq, "bad colour: %s", value); return (NULL); } return (options_set_number(oo, oe->name, colour)); }
/* Set a colour option. */ struct options_entry * cmd_set_option_colour(struct cmd *self, struct cmd_ctx *ctx, const struct options_table_entry *oe, struct options *oo) { struct cmd_target_data *data = self->data; int colour; if ((colour = colour_fromstring(data->arg2)) == -1) { ctx->error(ctx, "bad colour: %s", data->arg2); return (NULL); } return (options_set_number(oo, oe->name, colour)); }
void cmd_set_option_colour(struct cmd_ctx *ctx, struct options *oo, const struct set_option_entry *entry, char *value) { struct options_entry *o; int colour; if (value == NULL) { ctx->error(ctx, "empty value"); return; } if ((colour = colour_fromstring(value)) == -1) { ctx->error(ctx, "bad colour: %s", value); return; } o = options_set_number(oo, entry->name, colour); ctx->info(ctx, "set option: %s -> %s", o->name, cmd_set_option_print(entry, o)); }
/* Parse an embedded style of the form "fg=colour,bg=colour,bright,...". */ void screen_write_parsestyle( struct grid_cell *defgc, struct grid_cell *gc, const char *in) { const char delimiters[] = " ,"; char tmp[32]; int val; size_t end; u_char fg, bg, attr, flags; if (*in == '\0') return; if (strchr(delimiters, in[strlen(in) - 1]) != NULL) return; fg = gc->fg; bg = gc->bg; attr = gc->attr; flags = gc->flags; do { end = strcspn(in, delimiters); if (end > (sizeof tmp) - 1) return; memcpy(tmp, in, end); tmp[end] = '\0'; if (strcasecmp(tmp, "default") == 0) { fg = defgc->fg; bg = defgc->bg; attr = defgc->attr; } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) { if ((val = colour_fromstring(tmp + 3)) == -1) return; if (*in == 'f' || *in == 'F') { if (val != 8) { if (val & 0x100) { flags |= GRID_FLAG_FG256; val &= ~0x100; } else flags &= ~GRID_FLAG_FG256; fg = val; } else fg = defgc->fg; } else if (*in == 'b' || *in == 'B') { if (val != 8) { if (val & 0x100) { flags |= GRID_FLAG_BG256; val &= ~0x100; } else flags &= ~GRID_FLAG_BG256; bg = val; } else bg = defgc->bg; } else return; } else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) { if ((val = attributes_fromstring(tmp + 2)) == -1) return; attr &= ~val; } else { if ((val = attributes_fromstring(tmp)) == -1) return; attr |= val; } in += end + strspn(in + end, delimiters); } while (*in != '\0'); gc->fg = fg; gc->bg = bg; gc->attr = attr; gc->flags = flags; }
/* Parse an embedded style of the form "fg=colour,bg=colour,bright,...". */ int style_parse(const struct grid_cell *defgc, struct grid_cell *gc, const char *in) { struct grid_cell savedgc; const char delimiters[] = " ,"; char tmp[32]; int val; size_t end; u_char fg, bg, attr, flags; if (*in == '\0') return (0); if (strchr(delimiters, in[strlen(in) - 1]) != NULL) return (-1); memcpy(&savedgc, gc, sizeof savedgc); fg = gc->fg; bg = gc->bg; attr = gc->attr; flags = gc->flags; do { end = strcspn(in, delimiters); if (end > (sizeof tmp) - 1) goto error; memcpy(tmp, in, end); tmp[end] = '\0'; if (strcasecmp(tmp, "default") == 0) { fg = defgc->fg; bg = defgc->bg; attr = defgc->attr; flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256); flags |= defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256); } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) { if ((val = colour_fromstring(tmp + 3)) == -1) goto error; if (*in == 'f' || *in == 'F') { if (val != 8) { if (val & 0x100) { flags |= GRID_FLAG_FG256; val &= ~0x100; } else flags &= ~GRID_FLAG_FG256; fg = val; } else { fg = defgc->fg; flags &= ~GRID_FLAG_FG256; flags |= defgc->flags & GRID_FLAG_FG256; } } else if (*in == 'b' || *in == 'B') { if (val != 8) { if (val & 0x100) { flags |= GRID_FLAG_BG256; val &= ~0x100; } else flags &= ~GRID_FLAG_BG256; bg = val; } else { bg = defgc->bg; flags &= ~GRID_FLAG_BG256; flags |= defgc->flags & GRID_FLAG_BG256; } } else goto error; } else if (strcasecmp(tmp, "none") == 0) attr = 0; else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) { if ((val = attributes_fromstring(tmp + 2)) == -1) goto error; attr &= ~val; } else { if ((val = attributes_fromstring(tmp)) == -1) goto error; attr |= val; } in += end + strspn(in + end, delimiters); } while (*in != '\0'); gc->fg = fg; gc->bg = bg; gc->attr = attr; gc->flags = flags; return (0); error: memcpy(gc, &savedgc, sizeof *gc); return (-1); }