NeoMutt  2024-11-14-138-ge5ca67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
cbar.c
Go to the documentation of this file.
1
62#include "config.h"
63#include "mutt/lib.h"
64#include "config/lib.h"
65#include "email/lib.h"
66#include "core/lib.h"
67#include "gui/lib.h"
68#include "cbar.h"
69#include "color/lib.h"
70#include "expando/lib.h"
71#include "index/lib.h"
72#include "cbar_data.h"
73#include "expando.h"
74#include "shared_data.h"
75
81static int cbar_recalc(struct MuttWindow *win)
82{
83 struct Buffer *buf = buf_pool_get();
84 struct ComposeSharedData *shared = win->parent->wdata;
85
86 const struct Expando *c_compose_format = cs_subset_expando(shared->sub, "compose_format");
87 expando_filter(c_compose_format, ComposeRenderCallbacks, shared,
89
90 struct ComposeBarData *cbar_data = win->wdata;
91 if (!mutt_str_equal(buf_string(buf), cbar_data->compose_format))
92 {
94 win->actions |= WA_REPAINT;
95 mutt_debug(LL_DEBUG5, "recalc done, request WA_REPAINT\n");
96 }
97 buf_pool_release(&buf);
98
99 return 0;
100}
101
105static int cbar_repaint(struct MuttWindow *win)
106{
107 struct ComposeBarData *cbar_data = win->wdata;
108
109 mutt_window_move(win, 0, 0);
112
113 mutt_window_move(win, 0, 0);
114 mutt_draw_statusline(win, win->state.cols, cbar_data->compose_format,
115 mutt_str_len(cbar_data->compose_format));
117 mutt_debug(LL_DEBUG5, "repaint done\n");
118
119 return 0;
120}
121
126{
127 if (nc->event_type != NT_COLOR)
128 return 0;
129 if (!nc->global_data || !nc->event_data)
130 return -1;
131
132 struct EventColor *ev_c = nc->event_data;
133
134 // MT_COLOR_MAX is sent on `uncolor *`
135 if ((ev_c->cid != MT_COLOR_STATUS) && (ev_c->cid != MT_COLOR_NORMAL) &&
136 (ev_c->cid != MT_COLOR_MAX))
137 {
138 return 0;
139 }
140
141 struct MuttWindow *win_cbar = nc->global_data;
142 win_cbar->actions |= WA_REPAINT;
143 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
144
145 return 0;
146}
147
152{
153 if (nc->event_type != NT_CONFIG)
154 return 0;
155 if (!nc->global_data || !nc->event_data)
156 return -1;
157
158 struct EventConfig *ev_c = nc->event_data;
159 if (!mutt_str_equal(ev_c->name, "compose_format"))
160 return 0;
161
162 struct MuttWindow *win_cbar = nc->global_data;
163 win_cbar->actions |= WA_RECALC;
164 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
165
166 return 0;
167}
168
173{
174 if (nc->event_type != NT_EMAIL)
175 return 0;
176 if (!nc->global_data)
177 return -1;
178
179 struct MuttWindow *win_cbar = nc->global_data;
180 win_cbar->actions |= WA_RECALC;
181 mutt_debug(LL_DEBUG5, "compose done, request WA_RECALC\n");
182
183 return 0;
184}
185
190{
191 if (nc->event_type != NT_WINDOW)
192 return 0;
193 if (!nc->global_data || !nc->event_data)
194 return -1;
195
196 struct MuttWindow *win_cbar = nc->global_data;
197 struct EventWindow *ev_w = nc->event_data;
198 if (ev_w->win != win_cbar)
199 return 0;
200
202 {
203 win_cbar->actions |= WA_RECALC | WA_REPAINT;
204 mutt_debug(LL_DEBUG5, "window state done, request WA_RECALC\n");
205 }
206 else if (nc->event_subtype == NT_WINDOW_DELETE)
207 {
208 struct MuttWindow *dlg = win_cbar->parent;
209 struct ComposeSharedData *shared = dlg->wdata;
210
215
216 mutt_debug(LL_DEBUG5, "window delete done\n");
217 }
218
219 return 0;
220}
221
226struct MuttWindow *cbar_new(struct ComposeSharedData *shared)
227{
231
232 win_cbar->wdata = cbar_data_new();
233 win_cbar->wdata_free = cbar_data_free;
234 win_cbar->recalc = cbar_recalc;
235 win_cbar->repaint = cbar_repaint;
236
241
242 return win_cbar;
243}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
struct MuttWindow * cbar_new(struct ComposeSharedData *shared)
Create the Compose Bar (status)
Definition: cbar.c:226
Compose Bar.
struct ComposeBarData * cbar_data_new(void)
Create the private data for the Compose Bar.
Definition: cbar_data.c:52
Compose Bar Data.
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition: notify.c:69
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition: notify.c:59
@ MT_COLOR_MAX
Definition: color.h:94
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
const struct ExpandoRenderCallback ComposeRenderCallbacks[]
Callbacks for Compose Expandos.
Definition: expando.c:105
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:357
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
void mutt_draw_statusline(struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:958
Structs that make up an email.
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:138
Parse Expando string.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
int cbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition: cbar.c:125
int cbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: cbar.c:151
static int cbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: cbar.c:189
static int cbar_email_observer(struct NotifyCallback *nc)
Notification that the Email has changed - Implements observer_t -.
Definition: cbar.c:172
static int cbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition: cbar.c:81
static int cbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition: cbar.c:105
void cbar_data_free(struct MuttWindow *win, void **ptr)
Free the private Compose Bar data - Implements MuttWindow::wdata_free() -.
Definition: cbar_data.c:36
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
Data shared between Index, Pager and Sidebar.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
const struct AttrColor * mutt_curses_set_normal_backed_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:63
const struct AttrColor * mutt_curses_set_color_by_id(enum ColorId cid)
Set the colour and attributes by the colour id.
Definition: mutt_curses.c:79
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:297
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:244
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
Definition: mutt_window.h:230
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:229
#define WA_REPAINT
Redraw the contents of the Window.
Definition: mutt_window.h:111
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:57
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
@ NT_COLOR
Colour has changed, NotifyColor, EventColor.
Definition: notify_type.h:41
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
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
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: render.h:33
Sidebar Expando definitions.
String manipulation buffer.
Definition: buffer.h:36
Data to fill the Compose Bar Window.
Definition: cbar_data.h:34
char * compose_format
Cached status string.
Definition: cbar_data.h:35
Shared Compose Data.
Definition: shared_data.h:35
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:36
struct Email * email
Email being composed.
Definition: shared_data.h:38
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
An Event that happened to a Colour.
Definition: notify2.h:53
enum ColorId cid
Colour ID that has changed.
Definition: notify2.h:54
A config-change event.
Definition: subset.h:71
const char * name
Name of config item that changed.
Definition: subset.h:73
An Event that happened to a Window.
Definition: mutt_window.h:239
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:240
Parsed Expando trees.
Definition: expando.h:41
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
struct MuttWindow * parent
Parent Window.
Definition: mutt_window.h:135
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61