NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
simple.c
Go to the documentation of this file.
1
22
29
30#include "config.h"
31#include <stdbool.h>
32#include <stddef.h>
33#include "mutt/lib.h"
34#include "core/lib.h"
35#include "gui/lib.h"
36#include "attr.h"
37#include "color.h"
38#include "commands.h"
39#include "debug.h"
40#include "module_data.h"
41#include "notify2.h"
42#include "simple2.h"
43
48void simple_colors_init(struct AttrColor *simple_colors)
49{
50 for (int i = 0; i < MT_COLOR_MAX; i++)
51 {
52 simple_colors[i].fg.color = COLOR_DEFAULT;
53 simple_colors[i].bg.color = COLOR_DEFAULT;
54 }
55
56 // Set some defaults
57 color_debug(LL_DEBUG5, "init indicator, markers, etc\n");
58 simple_colors[MT_COLOR_BOLD].attrs = A_BOLD;
59 simple_colors[MT_COLOR_INDICATOR].attrs = A_REVERSE;
60 simple_colors[MT_COLOR_ITALIC].attrs = A_ITALIC;
61 simple_colors[MT_COLOR_MARKERS].attrs = A_REVERSE;
62 simple_colors[MT_COLOR_SEARCH].attrs = A_REVERSE;
63 simple_colors[MT_COLOR_STATUS].attrs = A_REVERSE;
64 simple_colors[MT_COLOR_STRIPE_EVEN].attrs = A_BOLD;
65 simple_colors[MT_COLOR_UNDERLINE].attrs = A_UNDERLINE;
66}
67
72void simple_colors_reset(struct AttrColor *simple_colors)
73{
74 color_debug(LL_DEBUG5, "reset defs\n");
75 for (size_t i = 0; i < MT_COLOR_MAX; i++)
76 {
77 attr_color_clear(&simple_colors[i]);
78 }
79 simple_colors_init(simple_colors);
80}
81
86void simple_colors_cleanup(struct AttrColor *simple_colors)
87{
88 simple_colors_reset(simple_colors);
89}
90
99{
100 if (cid >= MT_COLOR_MAX)
101 {
102 mutt_debug(LL_DEBUG1, "color overflow %d/%d\n", cid, MT_COLOR_MAX);
103 return NULL;
104 }
105 if (cid <= MT_COLOR_NONE)
106 {
107 mutt_debug(LL_DEBUG1, "color underflow %d/%d\n", cid, MT_COLOR_NONE);
108 return NULL;
109 }
110
112 return &mod_data->simple_colors[cid];
113}
114
121{
123}
124
131struct AttrColor *simple_color_set(enum ColorId cid, struct AttrColor *ac_val)
132{
133 struct AttrColor *ac = simple_color_get(cid);
134 if (!ac)
135 return NULL;
136
137 attr_color_overwrite(ac, ac_val);
138
139 struct Buffer *buf = buf_pool_get();
140 get_colorid_name(cid, buf);
141 color_debug(LL_DEBUG5, "NT_COLOR_SET: %s\n", buf_string(buf));
142 buf_pool_release(&buf);
143
145 struct EventColor ev_c = { cid, NULL };
147
148 return ac;
149}
150
156{
157 struct AttrColor *ac = simple_color_get(cid);
158 if (!ac)
159 return;
160
161 struct Buffer *buf = buf_pool_get();
162 get_colorid_name(cid, buf);
163 color_debug(LL_DEBUG5, "NT_COLOR_RESET: %s\n", buf_string(buf));
164 buf_pool_release(&buf);
165
167
169 struct EventColor ev_c = { cid, ac };
171}
void attr_color_clear(struct AttrColor *ac)
Free the contents of an AttrColor.
Definition attr.c:47
void attr_color_overwrite(struct AttrColor *ac_old, const struct AttrColor *ac_new)
Update an AttrColor in-place.
Definition attr.c:394
bool attr_color_is_set(const struct AttrColor *ac)
Is the object coloured?
Definition attr.c:178
Colour and attributes.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
void get_colorid_name(unsigned int cid, struct Buffer *buf)
Get the name of a Colour ID.
Definition commands.c:128
Parse colour commands.
Color private Module data.
void simple_colors_init(struct AttrColor *simple_colors)
Initialise the simple colour definitions.
Definition simple.c:48
struct AttrColor * simple_color_set(enum ColorId cid, struct AttrColor *ac_val)
Set the colour of a simple object.
Definition simple.c:131
void simple_colors_cleanup(struct AttrColor *simple_colors)
Cleanup the simple colour definitions.
Definition simple.c:86
void simple_color_reset(enum ColorId cid)
Clear the colour of a simple object.
Definition simple.c:155
bool simple_color_is_set(enum ColorId cid)
Is the object coloured?
Definition simple.c:120
void simple_colors_reset(struct AttrColor *simple_colors)
Reset the simple colour definitions.
Definition simple.c:72
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition simple.c:98
Color and attribute parsing.
#define COLOR_DEFAULT
Definition color.h:102
ColorId
List of all coloured objects.
Definition color.h:35
@ MT_COLOR_MARKERS
Pager: markers, line continuation.
Definition color.h:51
@ MT_COLOR_MAX
Definition color.h:97
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition color.h:78
@ MT_COLOR_INDICATOR
Selected item in list.
Definition color.h:49
@ MT_COLOR_STRIPE_EVEN
Stripes: even lines of the Help Page.
Definition color.h:79
@ MT_COLOR_NONE
No colour.
Definition color.h:36
@ MT_COLOR_BOLD
Bold text.
Definition color.h:40
@ MT_COLOR_SEARCH
Pager: search matches.
Definition color.h:67
@ MT_COLOR_ITALIC
Italic text.
Definition color.h:50
@ MT_COLOR_UNDERLINE
Underlined text.
Definition color.h:83
Convenience wrapper for the core headers.
Colour Debugging.
static int color_debug(enum LogLevel level, const char *format,...)
Definition debug.h:51
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
Convenience wrapper for the gui headers.
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
@ MODULE_ID_COLOR
ModuleColor, Color
Definition module_api.h:53
Convenience wrapper for the library headers.
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
#define A_ITALIC
Definition mutt_curses.h:48
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
Colour notifications.
@ NT_COLOR_RESET
Color has been reset/removed.
Definition notify2.h:41
@ NT_COLOR_SET
Color has been set.
Definition notify2.h:40
@ 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:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
Simple colour.
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
String manipulation buffer.
Definition buffer.h:36
color_t color
Colour.
Definition attr.h:56
Color private Module data.
Definition module_data.h:35
struct Notify * colors_notify
Notifications: ColorId, EventColor.
Definition module_data.h:40
struct AttrColor simple_colors[MT_COLOR_MAX]
Array of Simple colours.
Definition module_data.h:42
An Event that happened to a Colour.
Definition notify2.h:52
enum ColorId cid
Colour ID that has changed.
Definition notify2.h:53
Container for Accounts, Notifications.
Definition neomutt.h:41