NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
debug.c File Reference

Colour Debugging. More...

#include "config.h"
#include <stdio.h>
#include "mutt/lib.h"
#include "gui/lib.h"
#include "debug.h"
#include "pager/lib.h"
#include "attr.h"
#include "curses2.h"
#include "dump.h"
#include "pager/private_data.h"
+ Include dependency graph for debug.c:

Go to the source code of this file.

Functions

const char * color_log_color (color_t fg, color_t bg)
 Get a colourful string to represent a colour in the log.
 
void ansi_colors_dump (struct Buffer *buf)
 Dump all the ANSI colours.
 
void curses_color_dump (struct CursesColor *cc, const char *prefix)
 Log one Curses colour.
 
void curses_colors_dump (struct Buffer *buf)
 Dump all the Curses colours.
 
void merged_colors_dump (struct Buffer *buf)
 Dump all the Merged colours.
 

Variables

struct AttrColorList MergedColors
 Array of user colours.
 
struct CursesColorList CursesColors
 List of all Curses colours.
 

Detailed Description

Colour Debugging.

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 debug.c.

Function Documentation

◆ color_log_color()

const char * color_log_color ( color_t  fg,
color_t  bg 
)

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

Parameters
fgForeground colour
bgBackground colour
Return values
ptrGenerated string
Note
Do not free the returned string

Definition at line 51 of file debug.c.

52{
53 static char text[64];
54 size_t pos = 0;
55 // snprintf(text, sizeof(text), "\033[38;5;%dm\033[48;5;%dmXXXXXX\033[0m", fg, bg);
56
57 if (fg != -1)
58 {
59 int r = (fg >> 16) & 0xff;
60 int g = (fg >> 8) & 0xff;
61 int b = (fg >> 0) & 0xff;
62
63 pos += snprintf(text + pos, sizeof(text) - pos, "\033[38;2;%d;%d;%dm", r, g, b);
64 }
65
66 if (bg != -1)
67 {
68 int r = (bg >> 16) & 0xff;
69 int g = (bg >> 8) & 0xff;
70 int b = (bg >> 0) & 0xff;
71
72 pos += snprintf(text + pos, sizeof(text) - pos, "\033[48;2;%d;%d;%dm", r, g, b);
73 }
74
75 pos += snprintf(text + pos, sizeof(text) - pos, "XXXXXX\033[0m");
76
77 return text;
78}
+ Here is the caller graph for this function:

◆ ansi_colors_dump()

void ansi_colors_dump ( struct Buffer buf)

Dump all the ANSI colours.

Parameters
bufBuffer for result

Definition at line 84 of file debug.c.

85{
86 struct MuttWindow *win = window_get_focus();
87 if (!win || (win->type != WT_CUSTOM) || !win->parent || (win->parent->type != WT_PAGER))
88 return;
89
90 struct PagerPrivateData *priv = win->parent->wdata;
91 if (!priv || TAILQ_EMPTY(&priv->ansi_list))
92 return;
93
94 struct Buffer *swatch = buf_pool_get();
95 char color_fg[64] = { 0 };
96 char color_bg[64] = { 0 };
97
98 buf_addstr(buf, "# Ansi Colors\n");
99 struct AttrColor *ac = NULL;
100 TAILQ_FOREACH(ac, &priv->ansi_list, entries)
101 {
102 struct CursesColor *cc = ac->curses_color;
103 if (!cc)
104 continue;
105
106 color_log_color_attrs(ac, swatch);
107 buf_add_printf(buf, "# %-30s %-16s %-16s # %s\n", color_log_attrs_list(ac->attrs),
108 color_log_name(color_fg, sizeof(color_fg), &ac->fg),
109 color_log_name(color_bg, sizeof(color_bg), &ac->bg),
110 buf_string(swatch));
111 }
112
113 buf_addstr(buf, "\n");
114 buf_pool_release(&swatch);
115}
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: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
struct MuttWindow * window_get_focus(void)
Get the currently focused Window.
Definition: mutt_window.c:667
@ WT_CUSTOM
Window with a custom drawing function.
Definition: mutt_window.h:94
@ WT_PAGER
A panel containing the Pager Window.
Definition: mutt_window.h:99
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
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_EMPTY(head)
Definition: queue.h:721
A curses colour and its attributes.
Definition: attr.h:66
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
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:70
String manipulation buffer.
Definition: buffer.h:36
Colour in the ncurses palette.
Definition: curses2.h:41
void * wdata
Private data.
Definition: mutt_window.h:144
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:134
enum WindowType type
Window type, e.g. WT_SIDEBAR.
Definition: mutt_window.h:143
Private state data for the Pager.
Definition: private_data.h:41
struct AttrColorList ansi_list
List of ANSI colours used in the Pager.
Definition: private_data.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_color_dump()

void curses_color_dump ( struct CursesColor cc,
const char *  prefix 
)

Log one Curses colour.

Parameters
ccCursesColor to log
prefixPrefix for the log line

Definition at line 122 of file debug.c.

123{
124 if (!cc)
125 return;
126
127 char fg[16] = "-";
128 char bg[16] = "-";
129
130 if (cc->fg != -1)
131 snprintf(fg, sizeof(fg), "#%06x", cc->fg);
132 if (cc->bg != -1)
133 snprintf(bg, sizeof(bg), "#%06x", cc->bg);
134
135 const char *color = color_log_color(cc->fg, cc->bg);
136 color_debug(LL_DEBUG5, "%s index %d, %s %s %s rc %d\n", NONULL(prefix),
137 cc->index, fg, bg, color, cc->ref_count);
138}
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:51
static int color_debug(enum LogLevel level, const char *format,...)
Definition: debug.h:52
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#define NONULL(x)
Definition: string2.h:37
color_t fg
Foreground colour.
Definition: curses2.h:42
color_t bg
Background colour.
Definition: curses2.h:43
short index
Index number.
Definition: curses2.h:44
short ref_count
Number of users.
Definition: curses2.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ curses_colors_dump()

void curses_colors_dump ( struct Buffer buf)

Dump all the Curses colours.

Parameters
bufBuffer for result

Definition at line 144 of file debug.c.

145{
147 return;
148
149 struct Buffer *swatch = buf_pool_get();
150
151 buf_addstr(buf, "# Curses Colors\n");
152 buf_add_printf(buf, "# Index fg bg Color rc\n");
153
154 struct CursesColor *cc = NULL;
155 TAILQ_FOREACH(cc, &CursesColors, entries)
156 {
157 char fg[16] = "-";
158 char bg[16] = "-";
159
160 if (cc->fg != -1)
161 snprintf(fg, sizeof(fg), "#%06x", cc->fg);
162 if (cc->bg != -1)
163 snprintf(bg, sizeof(bg), "#%06x", cc->bg);
164
165 const char *color = color_log_color(cc->fg, cc->bg);
166 buf_add_printf(buf, "# %5d %-7s %-7s %s %2d\n", cc->index, fg, bg, color, cc->ref_count);
167 }
168
169 buf_addstr(buf, "\n");
170 buf_pool_release(&swatch);
171}
struct CursesColorList CursesColors
List of all Curses colours.
Definition: curses.c:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ merged_colors_dump()

void merged_colors_dump ( struct Buffer buf)

Dump all the Merged colours.

Parameters
bufBuffer for result

Definition at line 177 of file debug.c.

178{
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, &MergedColors, 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}
struct AttrColorList MergedColors
Array of user colours.
Definition: merged.c:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MergedColors

struct AttrColorList MergedColors
extern

Array of user colours.

Definition at line 39 of file merged.c.

◆ CursesColors

struct CursesColorList CursesColors
extern

List of all Curses colours.

Definition at line 38 of file curses.c.