NeoMutt  2024-11-14-34-g5aaf0d
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 *tmp_file = buf_pool_get();
453
454 buf_mktemp(tmp_file);
455 FILE *fp = mutt_file_fopen(buf_string(tmp_file), "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(tmp_file));
461 buf_pool_release(&tmp_file);
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(tmp_file);
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(&tmp_file);
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:222
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: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 _(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:142
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
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:

◆ 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}
#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 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
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 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: