NeoMutt  2025-01-09-41-g086358
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dump.h File Reference

Colour Dump Command. More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void color_dump (void)
 Display all the colours in the Pager.
 
const char * color_log_attrs_list (int attrs)
 Get a string to represent some attributes in the log.
 
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_name (char *buf, int buflen, struct ColorElement *elem)
 Get a string to represent a colour name.
 

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.h.

Function Documentation

◆ color_dump()

void color_dump ( void  )

Display all the colours in the Pager.

Definition at line 450 of file dump.c.

451{
452 struct Buffer *tempfile = buf_pool_get();
453
454 buf_mktemp(tempfile);
455 FILE *fp = mutt_file_fopen(buf_string(tempfile), "w");
456 if (!fp)
457 {
458 // LCOV_EXCL_START
459 // L10N: '%s' is the file name of the temporary file
460 mutt_error(_("Could not create temporary file %s"), buf_string(tempfile));
461 buf_pool_release(&tempfile);
462 return;
463 // LCOV_EXCL_STOP
464 }
465
466 struct Buffer *buf = buf_pool_get();
467
472
473#ifdef USE_DEBUG_COLOR
475 ansi_colors_dump(buf);
478#endif
479
481 buf_pool_release(&buf);
482 mutt_file_fclose(&fp);
483
484 struct PagerData pdata = { 0 };
485 struct PagerView pview = { &pdata };
486
487 pdata.fname = buf_string(tempfile);
488
489 pview.banner = "color";
490 pview.flags = MUTT_SHOWCOLOR;
491 pview.mode = PAGER_MODE_OTHER;
492
493 mutt_do_pager(&pview, NULL);
494 buf_pool_release(&tempfile);
495}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
void simple_colors_dump(struct Buffer *buf)
Dump all the Simple colours.
Definition: dump.c:304
void quoted_colors_dump(struct Buffer *buf)
Dump all the Quoted colours.
Definition: dump.c:225
void regex_colors_dump(struct Buffer *buf)
Dump all the Regex colours.
Definition: dump.c:254
void status_colors_dump(struct Buffer *buf)
Dump all the Status colours.
Definition: dump.c:386
void ansi_colors_dump(struct Buffer *buf)
Dump all the ANSI colours.
Definition: debug.c:83
void curses_colors_dump(struct Buffer *buf)
Dump all the Curses colours.
Definition: debug.c:143
void merged_colors_dump(struct Buffer *buf)
Dump all the Merged colours.
Definition: debug.c:176
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:1572
#define mutt_file_fclose(FP)
Definition: file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:138
#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 _(a)
Definition: message.h:28
#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:140
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
String manipulation buffer.
Definition: buffer.h:36
Data to be displayed by PagerView.
Definition: lib.h:159
const char * fname
Name of the file to read.
Definition: lib.h:163
Paged view into some data.
Definition: lib.h:170
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:171
enum PagerMode mode
Pager mode.
Definition: lib.h:172
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:173
const char * banner
Title to display in status bar.
Definition: lib.h:174
#define buf_mktemp(buf)
Definition: tmp.h:33
+ 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 138 of file dump.c.

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

◆ 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 55 of file dump.c.

56{
57 buf_reset(swatch);
58
59 if (ac->attrs & A_BLINK)
60 buf_add_printf(swatch, "\033[5m");
61 if (ac->attrs & A_BOLD)
62 buf_add_printf(swatch, "\033[1m");
63 if (ac->attrs & A_ITALIC)
64 buf_add_printf(swatch, "\033[3m");
65 if (ac->attrs == A_NORMAL)
66 buf_add_printf(swatch, "\033[0m");
67 if (ac->attrs & A_REVERSE)
68 buf_add_printf(swatch, "\033[7m");
69 if (ac->attrs & A_STANDOUT)
70 buf_add_printf(swatch, "\033[1m");
71 if (ac->attrs & A_UNDERLINE)
72 buf_add_printf(swatch, "\033[4m");
73
74 if (ac->fg.color >= 0)
75 {
76 switch (ac->fg.type)
77 {
78 case CT_SIMPLE:
79 {
80 buf_add_printf(swatch, "\033[%dm", 30 + ac->fg.color);
81 break;
82 }
83
84 case CT_PALETTE:
85 {
86 buf_add_printf(swatch, "\033[38;5;%dm", ac->fg.color);
87 break;
88 }
89
90 case CT_RGB:
91 {
92 int r = (ac->fg.color >> 16) & 0xff;
93 int g = (ac->fg.color >> 8) & 0xff;
94 int b = (ac->fg.color >> 0) & 0xff;
95 buf_add_printf(swatch, "\033[38;2;%d;%d;%dm", r, g, b);
96 break;
97 }
98 }
99 }
100
101 if (ac->bg.color >= 0)
102 {
103 switch (ac->bg.type)
104 {
105 case CT_SIMPLE:
106 {
107 buf_add_printf(swatch, "\033[%dm", 40 + ac->bg.color);
108 break;
109 }
110
111 case CT_PALETTE:
112 {
113 buf_add_printf(swatch, "\033[48;5;%dm", ac->bg.color);
114 break;
115 }
116
117 case CT_RGB:
118 {
119 int r = (ac->bg.color >> 16) & 0xff;
120 int g = (ac->bg.color >> 8) & 0xff;
121 int b = (ac->bg.color >> 0) & 0xff;
122 buf_add_printf(swatch, "\033[48;2;%d;%d;%dm", r, g, b);
123 break;
124 }
125 }
126 }
127
128 buf_addstr(swatch, "XXXXXX\033[0m");
129}
@ 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
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_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 168 of file dump.c.

169{
170 if (elem->color < 0)
171 return "default";
172
173 switch (elem->type)
174 {
175 case CT_SIMPLE:
176 {
177 const char *prefix = NULL;
178 switch (elem->prefix)
179 {
181 prefix = "alert";
182 break;
184 prefix = "bright";
185 break;
187 prefix = "light";
188 break;
189 default:
190 prefix = "";
191 break;
192 }
193
194 const char *name = mutt_map_get_name(elem->color, ColorNames);
195 snprintf(buf, buflen, "%s%s", prefix, name);
196 break;
197 }
198
199 case CT_PALETTE:
200 {
201 if (elem->color < 256)
202 snprintf(buf, buflen, "color%d", elem->color);
203 else
204 snprintf(buf, buflen, "BAD:%d", elem->color); // LCOV_EXCL_LINE
205 break;
206 }
207
208 case CT_RGB:
209 {
210 int r = (elem->color >> 16) & 0xff;
211 int g = (elem->color >> 8) & 0xff;
212 int b = (elem->color >> 0) & 0xff;
213 snprintf(buf, buflen, "#%02x%02x%02x", r, g, b);
214 break;
215 }
216 }
217
218 return buf;
219}
@ 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: