NeoMutt  2024-12-12-19-ge4b57e
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
quoted.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "core/lib.h"
34#include "quoted.h"
35#include "attr.h"
36#include "color.h"
37#include "command2.h"
38#include "curses2.h"
39#include "debug.h"
40#include "notify2.h"
41#include "simple2.h"
42
44static int NumQuotedColors = 0;
45
50{
51 for (size_t i = 0; i < COLOR_QUOTES_MAX; i++)
52 {
53 struct AttrColor *ac = &QuotedColors[i];
56 }
58}
59
64{
65 color_debug(LL_DEBUG5, "QuotedColors: reset\n");
66 for (size_t i = 0; i < COLOR_QUOTES_MAX; i++)
67 {
69 }
71}
72
77{
79}
80
87{
88 if (NumQuotedColors == 0)
89 return NULL;
90 return &QuotedColors[q % NumQuotedColors];
91}
92
98{
99 return NumQuotedColors;
100}
101
106static int find_highest_used(void)
107{
108 for (int i = COLOR_QUOTES_MAX - 1; i >= 0; i--)
109 {
111 return i + 1;
112 }
113 return 0;
114}
115
125bool quoted_colors_parse_color(enum ColorId cid, struct AttrColor *ac_val,
126 int q_level, int *rc, struct Buffer *err)
127{
128 if (!COLOR_QUOTED(cid))
129 return false;
130
131 color_debug(LL_DEBUG5, "quoted %d\n", q_level);
132 if (q_level >= COLOR_QUOTES_MAX)
133 {
134 buf_printf(err, _("Maximum quoting level is %d"), COLOR_QUOTES_MAX - 1);
135 return false;
136 }
137
138 if (q_level >= NumQuotedColors)
139 NumQuotedColors = q_level + 1;
140
141 struct AttrColor *ac = &QuotedColors[q_level];
142
143 attr_color_overwrite(ac, ac_val);
144
145 struct CursesColor *cc = ac->curses_color;
146 if (!cc)
148
149 struct Buffer *buf = buf_pool_get();
150 get_colorid_name(cid, buf);
151 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf->data);
152 buf_pool_release(&buf);
153
154 if (q_level == 0)
155 {
156 // Copy the colour into the SimpleColors
157 struct AttrColor *ac_quoted = simple_color_get(MT_COLOR_QUOTED);
158 curses_color_free(&ac_quoted->curses_color);
159 *ac_quoted = *ac;
160 ac_quoted->ref_count = 1;
161 if (ac_quoted->curses_color)
162 {
163 ac_quoted->curses_color->ref_count++;
164 curses_color_dump(cc, "curses rc++");
165 }
166 }
167
168 struct EventColor ev_c = { cid, ac };
170
172
173 *rc = MUTT_CMD_SUCCESS;
174 return true;
175}
176
185 struct Buffer *err)
186{
187 color_debug(LL_DEBUG5, "unquoted %d\n", q_level);
188
189 struct AttrColor *ac = &QuotedColors[q_level];
191
193
194 struct EventColor ev_c = { cid, ac };
196
197 return MUTT_CMD_SUCCESS;
198}
void attr_color_overwrite(struct AttrColor *ac_old, struct AttrColor *ac_new)
Update an AttrColor in-place.
Definition: attr.c:395
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition: attr.c:48
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition: attr.c:179
Colour and attributes.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:161
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a color id.
Definition: command.c:128
struct Notify * ColorsNotify
Notifications: ColorId, EventColor.
Definition: notify.c:36
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:95
Color and attribute parsing.
#define COLOR_DEFAULT
Definition: color.h:96
ColorId
List of all coloured objects.
Definition: color.h:36
@ MT_COLOR_QUOTED
Pager: quoted text.
Definition: color.h:59
Parse colour commands.
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
Convenience wrapper for the core headers.
Curses Colour.
void curses_color_free(struct CursesColor **ptr)
Free a CursesColor.
Definition: curses.c:120
void curses_color_dump(struct CursesColor *cc, const char *prefix)
Log one Curses colour.
Definition: debug.c:122
void curses_colors_dump(struct Buffer *buf)
Dump all the Curses colours.
Definition: debug.c:144
Colour Debugging.
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
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
Colour notifications.
@ NT_COLOR_RESET
Color has been reset/removed.
Definition: notify2.h:44
@ NT_COLOR_SET
Color has been set.
Definition: notify2.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
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
enum CommandResult quoted_colors_parse_uncolor(enum ColorId cid, int q_level, struct Buffer *err)
Parse the 'uncolor quoted' command.
Definition: quoted.c:184
struct AttrColor * quoted_colors_get(int q)
Return the color of a quote, cycling through the used quotes.
Definition: quoted.c:86
bool quoted_colors_parse_color(enum ColorId cid, struct AttrColor *ac_val, int q_level, int *rc, struct Buffer *err)
Parse the 'color quoted' command.
Definition: quoted.c:125
int quoted_colors_num_used(void)
Return the number of used quotes.
Definition: quoted.c:97
static int NumQuotedColors
Number of colours for quoted email text.
Definition: quoted.c:44
struct AttrColor QuotedColors[COLOR_QUOTES_MAX]
Array of colours for quoted email text.
Definition: quoted.c:43
void quoted_colors_init(void)
Initialise the Quoted colours.
Definition: quoted.c:49
void quoted_colors_reset(void)
Reset the quoted-email colours.
Definition: quoted.c:63
void quoted_colors_cleanup(void)
Cleanup the quoted-email colours.
Definition: quoted.c:76
static int find_highest_used(void)
Find the highest-numbered quotedN in use.
Definition: quoted.c:106
Quoted-Email colours.
#define COLOR_QUOTES_MAX
Ten colours, quoted0..quoted9 (quoted and quoted0 are equivalent)
Definition: quoted.h:35
#define COLOR_QUOTED(cid)
Definition: quoted.h:39
Simple colour.
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
short ref_count
Number of users.
Definition: attr.h:71
struct CursesColor * curses_color
Underlying Curses colour.
Definition: attr.h:70
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
color_t color
Colour.
Definition: attr.h:57
Colour in the ncurses palette.
Definition: curses2.h:41
short ref_count
Number of users.
Definition: curses2.h:45
An Event that happened to a Colour.
Definition: notify2.h:55
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:56