📄 color.c
字号:
|| (!parse_uncolor && has_colors())#else /* We don't even have colors compiled in */ parse_uncolor#endif ) { /* just eat the command, but don't do anything real about it */ do mutt_extract_token (buf, s, 0); while (MoreArgs (s)); return 0; } do { mutt_extract_token (buf, s, 0); if (!mutt_strcmp ("*", buf->data)) { for (tmp = ColorIndexList; tmp; ) { if (!do_cache) do_cache = 1; last = tmp; tmp = tmp->next; mutt_free_color_line(&last, parse_uncolor); } ColorIndexList = NULL; } else { for (last = NULL, tmp = ColorIndexList; tmp; last = tmp, tmp = tmp->next) { if (!mutt_strcmp (buf->data, tmp->pattern)) { if (!do_cache) do_cache = 1; dprint(1,(debugfile,"Freeing pattern \"%s\" from ColorIndexList\n", tmp->pattern)); if (last) last->next = tmp->next; else ColorIndexList = tmp->next; mutt_free_color_line(&tmp, parse_uncolor); break; } } } } while (MoreArgs (s)); if (do_cache && !option (OPTNOCURSES)) { int i; set_option (OPTFORCEREDRAWINDEX); /* force re-caching of index colors */ for (i = 0; Context && i < Context->msgcount; i++) Context->hdrs[i]->pair = 0; } return (0);}static int add_pattern (COLOR_LINE **top, const char *s, int sensitive, int fg, int bg, int attr, BUFFER *err, int is_index){ /* is_index used to store compiled pattern * only for `index' color object * when called from mutt_parse_color() */ COLOR_LINE *tmp = *top; while (tmp) { if (sensitive) { if (mutt_strcmp (s, tmp->pattern) == 0) break; } else { if (mutt_strcasecmp (s, tmp->pattern) == 0) break; } tmp = tmp->next; } if (tmp) {#ifdef HAVE_COLOR if (fg != -1 && bg != -1) { if (tmp->fg != fg || tmp->bg != bg) { mutt_free_color (tmp->fg, tmp->bg); tmp->fg = fg; tmp->bg = bg; attr |= mutt_alloc_color (fg, bg); } else attr |= (tmp->pair & ~A_BOLD); }#endif /* HAVE_COLOR */ tmp->pair = attr; } else { int r; char buf[STRING]; tmp = mutt_new_color_line (); if (is_index) { int i; strfcpy(buf, NONULL(s), sizeof(buf)); mutt_check_simple (buf, sizeof (buf), NONULL(SimpleSearch)); if((tmp->color_pattern = mutt_pattern_comp (buf, M_FULL_MSG, err)) == NULL) { mutt_free_color_line(&tmp, 1); return -1; } /* force re-caching of index colors */ for (i = 0; Context && i < Context->msgcount; i++) Context->hdrs[i]->pair = 0; } else if ((r = REGCOMP (&tmp->rx, s, (sensitive ? mutt_which_case (s) : REG_ICASE))) != 0) { regerror (r, &tmp->rx, err->data, err->dsize); mutt_free_color_line(&tmp, 1); return (-1); } tmp->next = *top; tmp->pattern = safe_strdup (s);#ifdef HAVE_COLOR if(fg != -1 && bg != -1) { tmp->fg = fg; tmp->bg = bg; attr |= mutt_alloc_color (fg, bg); }#endif tmp->pair = attr; *top = tmp; } return 0;}static intparse_object(BUFFER *buf, BUFFER *s, int *o, int *ql, BUFFER *err){ int q_level = 0; char *eptr; if(!MoreArgs(s)) { strfcpy(err->data, _("Missing arguments."), err->dsize); return -1; } mutt_extract_token(buf, s, 0); if(!mutt_strncmp(buf->data, "quoted", 6)) { if(buf->data[6]) { *ql = strtol(buf->data + 6, &eptr, 10); if(*eptr || q_level < 0) { snprintf(err->data, err->dsize, _("%s: no such object"), buf->data); return -1; } } else *ql = 0; *o = MT_COLOR_QUOTED; } else if ((*o = mutt_getvaluebyname (buf->data, Fields)) == -1) { snprintf (err->data, err->dsize, _("%s: no such object"), buf->data); return (-1); } return 0;}typedef int (*parser_callback_t)(BUFFER *, BUFFER *, int *, int *, int *, BUFFER *);#ifdef HAVE_COLORstatic intparse_color_pair(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err){ if (! MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); if (parse_color_name (buf->data, fg, attr, A_BOLD, err) != 0) return (-1); if (! MoreArgs (s)) { strfcpy (err->data, _("color: too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); if (parse_color_name (buf->data, bg, attr, A_BLINK, err) != 0) return (-1); return 0;}#endifstatic intparse_attr_spec(BUFFER *buf, BUFFER *s, int *fg, int *bg, int *attr, BUFFER *err){ if(fg) *fg = -1; if(bg) *bg = -1; if (! MoreArgs (s)) { strfcpy (err->data, _("mono: too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); if (ascii_strcasecmp ("bold", buf->data) == 0) *attr |= A_BOLD; else if (ascii_strcasecmp ("underline", buf->data) == 0) *attr |= A_UNDERLINE; else if (ascii_strcasecmp ("none", buf->data) == 0) *attr = A_NORMAL; else if (ascii_strcasecmp ("reverse", buf->data) == 0) *attr |= A_REVERSE; else if (ascii_strcasecmp ("standout", buf->data) == 0) *attr |= A_STANDOUT; else if (ascii_strcasecmp ("normal", buf->data) == 0) *attr = A_NORMAL; /* needs use = instead of |= to clear other bits */ else { snprintf (err->data, err->dsize, _("%s: no such attribute"), buf->data); return (-1); } return 0;}static int fgbgattr_to_color(int fg, int bg, int attr){#ifdef HAVE_COLOR if(fg != -1 && bg != -1) return attr | mutt_alloc_color(fg, bg); else#endif return attr;}/* usage: color <object> <fg> <bg> [ <regexp> ] * mono <object> <attr> [ <regexp> ] */static int _mutt_parse_color (BUFFER *buf, BUFFER *s, BUFFER *err, parser_callback_t callback, short dry_run){ int object = 0, attr = 0, fg = 0, bg = 0, q_level = 0; int r = 0; if(parse_object(buf, s, &object, &q_level, err) == -1) return -1; if(callback(buf, s, &fg, &bg, &attr, err) == -1) return -1; /* extract a regular expression if needed */ if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY || object == MT_COLOR_INDEX) { if (!MoreArgs (s)) { strfcpy (err->data, _("too few arguments"), err->dsize); return (-1); } mutt_extract_token (buf, s, 0); } if (MoreArgs (s)) { strfcpy (err->data, _("too many arguments"), err->dsize); return (-1); } /* dry run? */ if(dry_run) return 0; #ifdef HAVE_COLOR# ifdef HAVE_USE_DEFAULT_COLORS if (!option (OPTNOCURSES) && has_colors() /* delay use_default_colors() until needed, since it initializes things */ && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) && use_default_colors () != OK) { strfcpy (err->data, _("default colors not supported"), err->dsize); return (-1); }# endif /* HAVE_USE_DEFAULT_COLORS */#endif if (object == MT_COLOR_HEADER) r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err,0); else if (object == MT_COLOR_BODY) r = add_pattern (&ColorBodyList, buf->data, 1, fg, bg, attr, err, 0); else if (object == MT_COLOR_INDEX) { r = add_pattern (&ColorIndexList, buf->data, 1, fg, bg, attr, err, 1); set_option (OPTFORCEREDRAWINDEX); } else if (object == MT_COLOR_QUOTED) { if (q_level >= ColorQuoteSize) { safe_realloc (&ColorQuote, (ColorQuoteSize += 2) * sizeof (int)); ColorQuote[ColorQuoteSize-2] = ColorDefs[MT_COLOR_QUOTED]; ColorQuote[ColorQuoteSize-1] = ColorDefs[MT_COLOR_QUOTED]; } if (q_level >= ColorQuoteUsed) ColorQuoteUsed = q_level + 1; if (q_level == 0) { ColorDefs[MT_COLOR_QUOTED] = fgbgattr_to_color(fg, bg, attr); ColorQuote[0] = ColorDefs[MT_COLOR_QUOTED]; for (q_level = 1; q_level < ColorQuoteUsed; q_level++) { if (ColorQuote[q_level] == A_NORMAL) ColorQuote[q_level] = ColorDefs[MT_COLOR_QUOTED]; } } else ColorQuote[q_level] = fgbgattr_to_color(fg, bg, attr); } else ColorDefs[object] = fgbgattr_to_color(fg, bg, attr);#ifdef HAVE_COLOR# ifdef HAVE_BKGDSET if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors()) BKGDSET (MT_COLOR_NORMAL);# endif#endif return (r);}#ifdef HAVE_COLORint mutt_parse_color(BUFFER *buff, BUFFER *s, unsigned long data, BUFFER *err){ int dry_run = 0; if(option(OPTNOCURSES) || !has_colors()) dry_run = 1; return _mutt_parse_color(buff, s, err, parse_color_pair, dry_run);}#endifint mutt_parse_mono(BUFFER *buff, BUFFER *s, unsigned long data, BUFFER *err){ int dry_run = 0; #ifdef HAVE_COLOR if(option(OPTNOCURSES) || has_colors()) dry_run = 1;#else if(option(OPTNOCURSES)) dry_run = 1;#endif return _mutt_parse_color(buff, s, err, parse_attr_spec, dry_run);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -