NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dump.c File Reference

Colour Dump Command. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "dump.h"
#include "pager/lib.h"
#include "attr.h"
#include "color.h"
#include "parse_color.h"
#include "quoted.h"
#include "regex4.h"
#include "simple2.h"
+ Include dependency graph for dump.c:

Go to the source code of this file.

Functions

void color_log_color_attrs (struct AttrColor *ac, struct Buffer *swatch)
 Get a colourful string to represent a colour in the log.
 
const char * color_log_attrs_list (int attrs)
 Get a string to represent some attributes in the log.
 
const char * color_log_name (char *buf, int buflen, struct ColorElement *elem)
 Get a string to represent a colour name.
 
void quoted_colors_dump (struct Buffer *buf)
 Dump all the Quoted colours.
 
void regex_colors_dump (struct Buffer *buf)
 Dump all the Regex colours.
 
void simple_colors_dump (struct Buffer *buf)
 Dump all the Simple colours.
 
void status_colors_dump (struct Buffer *buf)
 Dump all the Status colours.
 
void color_dump (void)
 Display all the colours in the Pager.
 

Detailed Description

Colour Dump Command.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file dump.c.

Function Documentation

◆ color_log_color_attrs()

void color_log_color_attrs ( struct AttrColor ac,
struct Buffer swatch 
)

Get a colourful string to represent a colour in the log.

Parameters
acColour
swatchBuffer for swatch
Note
Do not free the returned string

Definition at line 52 of file dump.c.

53{
54 buf_reset(swatch);
55
56 if (ac->attrs & A_BLINK)
57 buf_add_printf(swatch, "\033[5m");
58 if (ac->attrs & A_BOLD)
59 buf_add_printf(swatch, "\033[1m");
60 if (ac->attrs & A_ITALIC)
61 buf_add_printf(swatch, "\033[3m");
62 if (ac->attrs == A_NORMAL)
63 buf_add_printf(swatch, "\033[0m");
64 if (ac->attrs & A_REVERSE)
65 buf_add_printf(swatch, "\033[7m");
66 if (ac->attrs & A_STANDOUT)
67 buf_add_printf(swatch, "\033[1m");
68 if (ac->attrs & A_UNDERLINE)
69 buf_add_printf(swatch, "\033[4m");
70
71 if (ac->fg.color >= 0)
72 {
73 switch (ac->fg.type)
74 {
75 case CT_SIMPLE:
76 {
77 buf_add_printf(swatch, "\033[%dm", 30 + ac->fg.color);
78 break;
79 }
80
81 case CT_PALETTE:
82 {
83 buf_add_printf(swatch, "\033[38;5;%dm", ac->fg.color);
84 break;
85 }
86
87 case CT_RGB:
88 {
89 int r = (ac->fg.color >> 16) & 0xff;
90 int g = (ac->fg.color >> 8) & 0xff;
91 int b = (ac->fg.color >> 0) & 0xff;
92 buf_add_printf(swatch, "\033[38;2;%d;%d;%dm", r, g, b);
93 break;
94 }
95 }
96 }
97
98 if (ac->bg.color >= 0)
99 {
100 switch (ac->bg.type)
101 {
102 case CT_SIMPLE:
103 {
104 buf_add_printf(swatch, "\033[%dm", 40 + ac->bg.color);
105 break;
106 }
107
108 case CT_PALETTE:
109 {
110 buf_add_printf(swatch, "\033[48;5;%dm", ac->bg.color);
111 break;
112 }
113
114 case CT_RGB:
115 {
116 int r = (ac->bg.color >> 16) & 0xff;
117 int g = (ac->bg.color >> 8) & 0xff;
118 int b = (ac->bg.color >> 0) & 0xff;
119 buf_add_printf(swatch, "\033[48;2;%d;%d;%dm", r, g, b);
120 break;
121 }
122 }
123 }
124
125 buf_addstr(swatch, "XXXXXX\033[0m");
126}
@ CT_SIMPLE
Simple colour, e.g. "Red".
Definition: attr.h:36
@ CT_PALETTE
Palette colour, e.g. "color207".
Definition: attr.h:37
@ CT_RGB
True colour, e.g. "#11AAFF".
Definition: attr.h:38
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:226
#define A_ITALIC
Definition: mutt_curses.h:49
struct ColorElement bg
Background colour.
Definition: attr.h:68
struct ColorElement fg
Foreground colour.
Definition: attr.h:67
int attrs
Text attributes, e.g. A_BOLD.
Definition: attr.h:69
enum ColorType type
Type of Colour.
Definition: attr.h:58
color_t color
Colour.
Definition: attr.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ color_log_attrs_list()

const char * color_log_attrs_list ( int  attrs)

Get a string to represent some attributes in the log.

Parameters
attrsAttributes, e.g. A_UNDERLINE
Return values
ptrGenerated string
Note
Do not free the returned string

Definition at line 135 of file dump.c.

136{
137 static char text[64];
138
139 text[0] = '\0';
140 int pos = 0;
141 // We can ignore the A_NORMAL case
142 if (attrs & A_BLINK)
143 pos += snprintf(text + pos, sizeof(text) - pos, "blink ");
144 if (attrs & A_BOLD)
145 pos += snprintf(text + pos, sizeof(text) - pos, "bold ");
146 if (attrs & A_ITALIC)
147 pos += snprintf(text + pos, sizeof(text) - pos, "italic ");
148 if (attrs & A_REVERSE)
149 pos += snprintf(text + pos, sizeof(text) - pos, "reverse ");
150 if (attrs & A_STANDOUT)
151 pos += snprintf(text + pos, sizeof(text) - pos, "standout ");
152 if (attrs & A_UNDERLINE)
153 pos += snprintf(text + pos, sizeof(text) - pos, "underline ");
154
155 return text;
156}
+ Here is the caller graph for this function:

◆ color_log_name()

const char * color_log_name ( char *  buf,
int  buflen,
struct ColorElement elem 
)

Get a string to represent a colour name.

Parameters
bufBuffer for the result
buflenLength of the Buffer
elemColour to use
Return values
ptrGenerated string

Definition at line 165 of file dump.c.

166{
167 if (elem->color < 0)
168 return "default";
169
170 switch (elem->type)
171 {
172 case CT_SIMPLE:
173 {
174 const char *prefix = NULL;
175 switch (elem->prefix)
176 {
178 prefix = "alert";
179 break;
181 prefix = "bright";
182 break;
184 prefix = "light";
185 break;
186 default:
187 prefix = "";
188 break;
189 }
190
191 const char *name = mutt_map_get_name(elem->color, ColorNames);
192 snprintf(buf, buflen, "%s%s", prefix, name);
193 break;
194 }
195
196 case CT_PALETTE:
197 {
198 if (elem->color < 256)
199 snprintf(buf, buflen, "color%d", elem->color);
200 else
201 snprintf(buf, buflen, "BAD:%d", elem->color); // LCOV_EXCL_LINE
202 break;
203 }
204
205 case CT_RGB:
206 {
207 int r = (elem->color >> 16) & 0xff;
208 int g = (elem->color >> 8) & 0xff;
209 int b = (elem->color >> 0) & 0xff;
210 snprintf(buf, buflen, "#%02x%02x%02x", r, g, b);
211 break;
212 }
213 }
214
215 return buf;
216}
@ COLOR_PREFIX_ALERT
"alert" colour prefix
Definition: attr.h:47
@ COLOR_PREFIX_LIGHT
"light" colour prefix
Definition: attr.h:49
@ COLOR_PREFIX_BRIGHT
"bright" colour prefix
Definition: attr.h:48
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
const struct Mapping ColorNames[]
Mapping between a colour name and an ncurses colour.
Definition: parse_color.c:41
enum ColorPrefix prefix
Optional Colour Modifier.
Definition: attr.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quoted_colors_dump()

void quoted_colors_dump ( struct Buffer buf)

Dump all the Quoted colours.

Parameters
bufBuffer for result

Definition at line 222 of file dump.c.

223{
224 int num = quoted_colors_num_used();
225 if (num == 0)
226 return;
227
228 struct Buffer *swatch = buf_pool_get();
229 char color_fg[64] = { 0 };
230 char color_bg[64] = { 0 };
231
232 buf_addstr(buf, _("# Quoted Colors\n"));
233 for (int i = 0; i < num; i++)
234 {
235 struct AttrColor *ac = quoted_colors_get(i);
236 if (!ac)
237 continue; // LCOV_EXCL_LINE
238
239 color_log_color_attrs(ac, swatch);
240 buf_add_printf(buf, "color quoted%d %-20s %-16s %-16s # %s\n", i,
242 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
243 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
244 buf_string(swatch));
245 }
246
247 buf_addstr(buf, "\n");
248 buf_pool_release(&swatch);
249}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
void color_log_color_attrs(struct AttrColor *ac, struct Buffer *swatch)
Get a colourful string to represent a colour in the log.
Definition: dump.c:52
const char * color_log_name(char *buf, int buflen, struct ColorElement *elem)
Get a string to represent a colour name.
Definition: dump.c:165
const char * color_log_attrs_list(int attrs)
Get a string to represent some attributes in the log.
Definition: dump.c:135
#define _(a)
Definition: message.h:28
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
struct AttrColor * quoted_colors_get(int q)
Return the color of a quote, cycling through the used quotes.
Definition: quoted.c:86
int quoted_colors_num_used(void)
Return the number of used quotes.
Definition: quoted.c:97
A curses colour and its attributes.
Definition: attr.h:66
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regex_colors_dump()

void regex_colors_dump ( struct Buffer buf)

Dump all the Regex colours.

Parameters
bufBuffer for result

Definition at line 255 of file dump.c.

256{
257 struct Buffer *swatch = buf_pool_get();
258 struct Buffer *pattern = buf_pool_get();
259 char color_fg[64] = { 0 };
260 char color_bg[64] = { 0 };
261
262 for (enum ColorId cid = MT_COLOR_NONE; cid != MT_COLOR_MAX; cid++)
263 {
264 if (cid == MT_COLOR_STATUS)
265 continue;
266
267 if (!mutt_color_has_pattern(cid))
268 continue;
269
270 struct RegexColorList *rcl = regex_colors_get_list(cid);
271 if (STAILQ_EMPTY(rcl))
272 continue;
273
274 const char *name = mutt_map_get_name(cid, ColorFields);
275 if (!name)
276 continue; // LCOV_EXCL_LINE
277
278 buf_add_printf(buf, _("# Regex Color %s\n"), name);
279
280 struct RegexColor *rc = NULL;
281 STAILQ_FOREACH(rc, rcl, entries)
282 {
283 struct AttrColor *ac = &rc->attr_color;
284
285 buf_reset(pattern);
286 pretty_var(rc->pattern, pattern);
287 color_log_color_attrs(ac, swatch);
288 buf_add_printf(buf, "color %-16s %-20s %-16s %-16s %-30s # %s\n", name,
290 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
291 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
292 buf_string(pattern), buf_string(swatch));
293 }
294 buf_addstr(buf, "\n");
295 }
296
297 buf_pool_release(&swatch);
298 buf_pool_release(&pattern);
299}
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:190
bool mutt_color_has_pattern(enum ColorId cid)
Check if a color object supports a regex pattern.
Definition: color.c:98
const struct Mapping ColorFields[]
Mapping of colour names to their IDs.
Definition: command.c:56
ColorId
List of all coloured objects.
Definition: color.h:36
@ MT_COLOR_MAX
Definition: color.h:90
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:71
@ MT_COLOR_NONE
No colour.
Definition: color.h:37
size_t pretty_var(const char *str, struct Buffer *buf)
Escape and stringify a config item value.
Definition: dump.c:85
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
A regular expression and a color to highlight a line.
Definition: regex4.h:36
struct AttrColor attr_color
Colour and attributes to apply.
Definition: regex4.h:37
char * pattern
Pattern to match.
Definition: regex4.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ simple_colors_dump()

void simple_colors_dump ( struct Buffer buf)

Dump all the Simple colours.

Parameters
bufBuffer for result

Definition at line 305 of file dump.c.

306{
307 struct Buffer *swatch = buf_pool_get();
308 char color_fg[64] = { 0 };
309 char color_bg[64] = { 0 };
310
311 int count = 0;
312 for (enum ColorId cid = MT_COLOR_NONE + 1; cid < MT_COLOR_MAX; cid++)
313 {
314 if (COLOR_QUOTED(cid) || (cid == MT_COLOR_STATUS))
315 continue;
316
317 struct AttrColor *ac = simple_color_get(cid);
318 if (attr_color_is_set(ac))
319 count++;
320 }
321
322 if (count > 0)
323 {
324 buf_addstr(buf, _("# Simple Colors\n"));
325 for (enum ColorId cid = MT_COLOR_NONE + 1; cid < MT_COLOR_MAX; cid++)
326 {
327 if (COLOR_QUOTED(cid) || (cid == MT_COLOR_STATUS))
328 continue;
329
330 struct AttrColor *ac = simple_color_get(cid);
331 if (!attr_color_is_set(ac))
332 continue;
333
334 const char *name = mutt_map_get_name(cid, ColorFields);
335 if (!name)
336 continue;
337
338 color_log_color_attrs(ac, swatch);
339 buf_add_printf(buf, "color %-18s %-20s %-16s %-16s # %s\n", name,
341 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
342 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
343 buf_string(swatch));
344 }
345 buf_addstr(buf, "\n");
346 }
347
348 count = 0;
349 for (int i = 0; ComposeColorFields[i].name; i++)
350 {
351 enum ColorId cid = ComposeColorFields[i].value;
352
353 struct AttrColor *ac = simple_color_get(cid);
354 if (attr_color_is_set(ac))
355 count++;
356 }
357
358 if (count > 0)
359 {
360 buf_addstr(buf, _("# Compose Colors\n"));
361 for (int i = 0; ComposeColorFields[i].name; i++)
362 {
363 const char *name = ComposeColorFields[i].name;
364 enum ColorId cid = ComposeColorFields[i].value;
365
366 struct AttrColor *ac = simple_color_get(cid);
367 if (!attr_color_is_set(ac))
368 continue;
369
370 color_log_color_attrs(ac, swatch);
371 buf_add_printf(buf, "color compose %-18s %-20s %-16s %-16s # %s\n", name,
373 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
374 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
375 buf_string(swatch));
376 }
377 buf_addstr(buf, "\n");
378 }
379
380 buf_pool_release(&swatch);
381}
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:179
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:95
const struct Mapping ComposeColorFields[]
Mapping of compose colour names to their IDs.
Definition: command.c:112
#define COLOR_QUOTED(cid)
Definition: quoted.h:39
int value
Integer value.
Definition: mapping.h:35
const char * name
String value.
Definition: mapping.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ status_colors_dump()

void status_colors_dump ( struct Buffer buf)

Dump all the Status colours.

Parameters
bufBuffer for result

Definition at line 387 of file dump.c.

388{
389 struct Buffer *swatch = buf_pool_get();
390 struct Buffer *pattern = buf_pool_get();
391 char color_fg[64] = { 0 };
392 char color_bg[64] = { 0 };
393
394 bool set = false;
395
396 const enum ColorId cid = MT_COLOR_STATUS;
397 struct AttrColor *ac = simple_color_get(cid);
398 if (attr_color_is_set(ac))
399 set = true;
400
401 struct RegexColorList *rcl = regex_colors_get_list(cid);
402 if (!STAILQ_EMPTY(rcl))
403 set = true;
404
405 if (set)
406 {
407 buf_addstr(buf, _("# Status Colors\n"));
408
409 color_log_color_attrs(ac, swatch);
410 buf_add_printf(buf, "color status %-20s %-16s %-16s # %s\n",
412 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
413 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
414 buf_string(swatch));
415
416 struct RegexColor *rc = NULL;
417 STAILQ_FOREACH(rc, rcl, entries)
418 {
419 ac = &rc->attr_color;
420
423 color_log_color_attrs(ac, swatch);
424 if (rc->match == 0)
425 {
426 buf_add_printf(buf, "color status %-20s %-16s %-16s %-30s # %s\n",
428 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
429 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
430 buf_string(pattern), buf_string(swatch));
431 }
432 else
433 {
434 buf_add_printf(buf, "color status %-20s %-16s %-16s %-28s %d # %s\n",
436 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
437 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
438 buf_string(pattern), rc->match, buf_string(swatch));
439 }
440 }
441 buf_addstr(buf, "\n");
442 }
443
444 buf_pool_release(&swatch);
446}
int match
Substring to match, 0 for old behaviour.
Definition: regex4.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ color_dump()

void color_dump ( void  )

Display all the colours in the Pager.

Definition at line 451 of file dump.c.

452{
453 struct Buffer *tempfile = buf_pool_get();
454
455 buf_mktemp(tempfile);
456 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w");
457 if (!fp)
458 {
459 // LCOV_EXCL_START
460 // L10N: '%s' is the file name of the temporary file
461 mutt_error(_("Could not create temporary file %s"), buf_string(tempfile));
462 buf_pool_release(&tempfile);
463 return;
464 // LCOV_EXCL_STOP
465 }
466
467 struct Buffer *buf = buf_pool_get();
468
473
474#ifdef USE_DEBUG_COLOR
476 ansi_colors_dump(buf);
479#endif
480
482 buf_pool_release(&buf);
483 mutt_file_fclose(&fp);
484
485 struct PagerData pdata = { 0 };
486 struct PagerView pview = { &pdata };
487
488 pdata.fname = buf_string(tempfile);
489
490 pview.banner = "color";
491 pview.flags = MUTT_SHOWCOLOR;
492 pview.mode = PAGER_MODE_OTHER;
493
494 mutt_do_pager(&pview, NULL);
495 buf_pool_release(&tempfile);
496}
void simple_colors_dump(struct Buffer *buf)
Dump all the Simple colours.
Definition: dump.c:305
void quoted_colors_dump(struct Buffer *buf)
Dump all the Quoted colours.
Definition: dump.c:222
void regex_colors_dump(struct Buffer *buf)
Dump all the Regex colours.
Definition: dump.c:255
void status_colors_dump(struct Buffer *buf)
Dump all the Status colours.
Definition: dump.c:387
void ansi_colors_dump(struct Buffer *buf)
Dump all the ANSI colours.
Definition: debug.c:84
void curses_colors_dump(struct Buffer *buf)
Dump all the Curses colours.
Definition: debug.c:144
void merged_colors_dump(struct Buffer *buf)
Dump all the Merged colours.
Definition: debug.c:177
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:122
size_t mutt_file_save_str(FILE *fp, const char *str)
Save a string to a file.
Definition: file.c:1679
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
#define mutt_error(...)
Definition: logging2.h:92
#define log_multiline(LEVEL, STRING)
Definition: logging2.h:96
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define MUTT_SHOWCOLOR
Show characters in color otherwise don't show characters.
Definition: lib.h:62
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:142
Data to be displayed by PagerView.
Definition: lib.h:161
const char * fname
Name of the file to read.
Definition: lib.h:165
Paged view into some data.
Definition: lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:173
enum PagerMode mode
Pager mode.
Definition: lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:175
const char * banner
Title to display in status bar.
Definition: lib.h:176
#define buf_mktemp(buf)
Definition: tmp.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function: