NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
debug.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "core/lib.h"
33#include "gui/lib.h"
34#include "debug.h"
35#include "pager/lib.h"
36#include "attr.h"
37#include "curses2.h"
38#include "dump.h"
39#include "module_data.h"
40#include "pager/private_data.h"
41
51{
52 static char text[64];
53 size_t pos = 0;
54
55 if (fg != -1)
56 {
57 int r = (fg >> 16) & 0xff;
58 int g = (fg >> 8) & 0xff;
59 int b = (fg >> 0) & 0xff;
60
61 pos += snprintf(text + pos, sizeof(text) - pos, "\033[38;2;%d;%d;%dm", r, g, b);
62 }
63
64 if (bg != -1)
65 {
66 int r = (bg >> 16) & 0xff;
67 int g = (bg >> 8) & 0xff;
68 int b = (bg >> 0) & 0xff;
69
70 pos += snprintf(text + pos, sizeof(text) - pos, "\033[48;2;%d;%d;%dm", r, g, b);
71 }
72
73 pos += snprintf(text + pos, sizeof(text) - pos, "XXXXXX\033[0m");
74
75 return text;
76}
77
82void ansi_colors_dump(struct Buffer *buf)
83{
84 struct MuttWindow *win = window_get_focus();
85 if (!win || (win->type != WT_CUSTOM) || !win->parent || (win->parent->type != WT_PAGER))
86 return;
87
88 struct PagerPrivateData *priv = win->parent->wdata;
89 if (!priv || TAILQ_EMPTY(&priv->ansi_list))
90 return;
91
92 struct Buffer *swatch = buf_pool_get();
93 char color_fg[64] = { 0 };
94 char color_bg[64] = { 0 };
95
96 buf_addstr(buf, "# Ansi Colors\n");
97 struct AttrColor *ac = NULL;
98 TAILQ_FOREACH(ac, &priv->ansi_list, entries)
99 {
100 struct CursesColor *cc = ac->curses_color;
101 if (!cc)
102 continue;
103
104 color_log_color_attrs(ac, swatch);
105 buf_add_printf(buf, "# %-30s %-16s %-16s # %s\n", color_log_attrs_list(ac->attrs),
106 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
107 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
108 buf_string(swatch));
109 }
110
111 buf_addstr(buf, "\n");
112 buf_pool_release(&swatch);
113}
114
120void curses_color_dump(struct CursesColor *cc, const char *prefix)
121{
122 if (!cc)
123 return;
124
125 char fg[16] = "-";
126 char bg[16] = "-";
127
128 if (cc->fg != -1)
129 snprintf(fg, sizeof(fg), "#%06x", cc->fg);
130 if (cc->bg != -1)
131 snprintf(bg, sizeof(bg), "#%06x", cc->bg);
132
133 const char *color = color_log_color(cc->fg, cc->bg);
134 color_debug(LL_DEBUG5, "%s index %d, %s %s %s rc %d\n", NONULL(prefix),
135 cc->index, fg, bg, color, cc->ref_count);
136}
137
142void curses_colors_dump(struct Buffer *buf)
143{
145 if (TAILQ_EMPTY(&mod_data->curses_colors))
146 return;
147
148 struct Buffer *swatch = buf_pool_get();
149
150 buf_addstr(buf, "# Curses Colors\n");
151 buf_add_printf(buf, "# Index fg bg Color rc\n");
152
153 struct CursesColor *cc = NULL;
154 TAILQ_FOREACH(cc, &mod_data->curses_colors, entries)
155 {
156 char fg[16] = "-";
157 char bg[16] = "-";
158
159 if (cc->fg != -1)
160 snprintf(fg, sizeof(fg), "#%06x", cc->fg);
161 if (cc->bg != -1)
162 snprintf(bg, sizeof(bg), "#%06x", cc->bg);
163
164 const char *color = color_log_color(cc->fg, cc->bg);
165 buf_add_printf(buf, "# %5d %-7s %-7s %s %2d\n", cc->index, fg, bg, color, cc->ref_count);
166 }
167
168 buf_addstr(buf, "\n");
169 buf_pool_release(&swatch);
170}
171
176void merged_colors_dump(struct Buffer *buf)
177{
179 if (TAILQ_EMPTY(&mod_data->merged_colors))
180 return;
181
182 struct Buffer *swatch = buf_pool_get();
183 char color_fg[64] = { 0 };
184 char color_bg[64] = { 0 };
185
186 buf_addstr(buf, "# Merged Colors\n");
187 struct AttrColor *ac = NULL;
188 TAILQ_FOREACH(ac, &mod_data->merged_colors, entries)
189 {
190 struct CursesColor *cc = ac->curses_color;
191 if (!cc)
192 continue;
193
194 color_log_color_attrs(ac, swatch);
195 buf_add_printf(buf, "# %-30s %-16s %-16s # %s\n", color_log_attrs_list(ac->attrs),
196 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
197 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
198 buf_string(swatch));
199 }
200
201 buf_addstr(buf, "\n");
202 buf_pool_release(&swatch);
203}
Colour and attributes.
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
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:55
const char * color_log_name(char *buf, int buflen, struct ColorElement *elem)
Get a string to represent a colour name.
Definition dump.c:168
const char * color_log_attrs_list(int attrs)
Get a string to represent some attributes in the log.
Definition dump.c:138
Colour Dump Command.
Color private Module data.
Convenience wrapper for the core headers.
Curses Colour.
int32_t color_t
Type for 24-bit colour value.
Definition curses2.h:30
const char * color_log_color(color_t fg, color_t bg)
Get a colourful string to represent a colour in the log.
Definition debug.c:50
void ansi_colors_dump(struct Buffer *buf)
Dump all the ANSI colours.
Definition debug.c:82
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition debug.c:120
void curses_colors_dump(struct Buffer *buf)
Dump all the Curses colours.
Definition debug.c:142
void merged_colors_dump(struct Buffer *buf)
Dump all the Merged colours.
Definition debug.c:176
Colour Debugging.
static int color_debug(enum LogLevel level, const char *format,...)
Definition debug.h:51
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
Convenience wrapper for the library headers.
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
@ WT_CUSTOM
Window with a custom drawing function.
Definition mutt_window.h:95
@ WT_PAGER
A panel containing the Pager Window.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
GUI display a file/email/help in a viewport with paging.
Private state data for the Pager.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define TAILQ_EMPTY(head)
Definition queue.h:778
#define NONULL(x)
Definition string2.h:44
A curses colour and its attributes.
Definition attr.h:65
struct ColorElement bg
Background colour.
Definition attr.h:67
struct ColorElement fg
Foreground colour.
Definition attr.h:66
int attrs
Text attributes, e.g. A_BOLD.
Definition attr.h:68
struct CursesColor * curses_color
Underlying Curses colour.
Definition attr.h:69
String manipulation buffer.
Definition buffer.h:36
Color private Module data.
Definition module_data.h:35
struct AttrColorList merged_colors
Array of user colours.
Definition module_data.h:39
struct CursesColorList curses_colors
List of all Curses colours.
Definition module_data.h:37
Colour in the ncurses palette.
Definition curses2.h:40
color_t fg
Foreground colour.
Definition curses2.h:41
color_t bg
Background colour.
Definition curses2.h:42
short index
Index number.
Definition curses2.h:43
short ref_count
Number of users.
Definition curses2.h:44
void * wdata
Private data.
struct MuttWindow * parent
Parent Window.
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Container for Accounts, Notifications.
Definition neomutt.h:41
Private state data for the Pager.
struct AttrColorList ansi_list
List of ANSI colours used in the Pager.