NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
pbar.c
Go to the documentation of this file.
1
22
61
62#include "config.h"
63#include <stdio.h>
64#include <sys/stat.h>
65#include "mutt/lib.h"
66#include "config/lib.h"
67#include "core/lib.h"
68#include "gui/lib.h"
69#include "pbar.h"
70#include "lib.h"
71#include "color/lib.h"
72#include "expando/lib.h"
73#include "index/lib.h"
74#include "display.h"
75#include "private_data.h"
76
86
90static int pbar_recalc(struct MuttWindow *win)
91{
92 struct PBarPrivateData *pbar_data = win->wdata;
93 struct IndexSharedData *shared = pbar_data->shared;
94 struct PagerPrivateData *priv = pbar_data->priv;
95 if (!priv || !priv->pview)
96 return 0;
97
98 struct Buffer *buf = buf_pool_get();
99 char pager_progress_str[65] = { 0 }; /* Lots of space for translations */
100
101 long offset;
102 if (priv->lines && (priv->cur_line <= priv->lines_used))
103 offset = priv->lines[priv->cur_line].offset;
104 else
105 offset = priv->bytes_read;
106
107 if (offset < (priv->st.st_size - 1))
108 {
109 const long percent = (100 * offset) / priv->st.st_size;
110 /* L10N: Pager position percentage.
111 `%ld` is the number, `%%` is the percent symbol.
112 They may be reordered, or space inserted, if you wish. */
113 snprintf(pager_progress_str, sizeof(pager_progress_str), _("%ld%%"), percent);
114 }
115 else
116 {
117 const char *msg = (priv->top_line == 0) ?
118 /* L10N: Status bar message: the entire email is visible in the pager */
119 _("all") :
120 /* L10N: Status bar message: the end of the email is visible in the pager */
121 _("end");
122 mutt_str_copy(pager_progress_str, msg, sizeof(pager_progress_str));
123 }
124
125 if ((priv->pview->mode == PAGER_MODE_EMAIL) || (priv->pview->mode == PAGER_MODE_ATTACH_E))
126 {
127 int msg_in_pager = shared->mailbox_view ? shared->mailbox_view->msg_in_pager : -1;
128
129 const struct Expando *c_pager_format = cs_subset_expando(shared->sub, "pager_format");
130 mutt_make_string(buf, win->state.cols, c_pager_format, shared->mailbox, msg_in_pager,
131 shared->email, MUTT_FORMAT_NO_FLAGS, pager_progress_str);
132 }
133 else
134 {
135 buf_printf(buf, "%s (%s)", priv->pview->banner, pager_progress_str);
136 }
137
138 if (!mutt_str_equal(buf_string(buf), pbar_data->pager_format))
139 {
140 mutt_str_replace(&pbar_data->pager_format, buf_string(buf));
141 win->actions |= WA_REPAINT;
142 }
143
144 buf_pool_release(&buf);
145 return 0;
146}
147
151static int pbar_repaint(struct MuttWindow *win)
152{
153 struct PBarPrivateData *pbar_data = win->wdata;
154
155 mutt_window_move(win, 0, 0);
158
159 mutt_window_move(win, 0, 0);
160 mutt_draw_statusline(win, win->state.cols, pbar_data->pager_format,
161 mutt_str_len(pbar_data->pager_format));
163
164 mutt_debug(LL_DEBUG5, "repaint done\n");
165 return 0;
166}
167
172{
173 if (nc->event_type != NT_COLOR)
174 return 0;
175 if (!nc->global_data || !nc->event_data)
176 return -1;
177
178 struct EventColor *ev_c = nc->event_data;
179 enum ColorId cid = ev_c->cid;
180
181 if ((cid != MT_COLOR_STATUS) && (cid != MT_COLOR_NORMAL) && (cid != MT_COLOR_MAX))
182 return 0;
183
184 struct MuttWindow *win_pbar = nc->global_data;
185 win_pbar->actions |= WA_REPAINT;
186 mutt_debug(LL_DEBUG5, "color done, request WA_REPAINT\n");
187
188 return 0;
189}
190
195{
196 if (nc->event_type != NT_CONFIG)
197 return 0;
198 if (!nc->global_data || !nc->event_data)
199 return -1;
200
201 struct EventConfig *ev_c = nc->event_data;
202 if (!mutt_str_equal(ev_c->name, "pager_format"))
203 return 0;
204
205 struct MuttWindow *win_pbar = nc->global_data;
206 win_pbar->actions |= WA_RECALC;
207 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC\n");
208
209 return 0;
210}
211
222{
223 if (!nc->global_data)
224 return -1;
225
226 struct MuttWindow *win_pbar = nc->global_data;
227 win_pbar->actions |= WA_RECALC;
228 mutt_debug(LL_DEBUG5, "index done, request WA_RECALC\n");
229
230 return 0;
231}
232
237{
238 if (nc->event_type != NT_PAGER)
239 return 0;
240 if (!nc->global_data)
241 return -1;
242
243 struct MuttWindow *win_pbar = nc->global_data;
244
246 {
247 win_pbar->actions |= WA_RECALC;
248 mutt_debug(LL_DEBUG5, "pager done, request WA_RECALC\n");
249 }
250
251 return 0;
252}
253
258{
259 if (nc->event_type != NT_WINDOW)
260 return 0;
261 if (!nc->global_data || !nc->event_data)
262 return -1;
263
264 struct MuttWindow *win_pbar = nc->global_data;
265 struct EventWindow *ev_w = nc->event_data;
266 if (ev_w->win != win_pbar)
267 return 0;
268
270 {
271 win_pbar->actions |= WA_RECALC | WA_REPAINT;
272 mutt_debug(LL_NOTIFY, "window state done, request WA_RECALC\n");
273 }
274 else if (nc->event_subtype == NT_WINDOW_DELETE)
275 {
276 struct PBarPrivateData *pbar_data = win_pbar->wdata;
277 struct IndexSharedData *shared = pbar_data->shared;
278
284
285 mutt_debug(LL_DEBUG5, "window delete done\n");
286 }
287
288 return 0;
289}
290
294static void pbar_data_free(struct MuttWindow *win, void **ptr)
295{
296 if (!ptr || !*ptr)
297 return;
298
299 struct PBarPrivateData *pbar_data = *ptr;
300
301 FREE(&pbar_data->pager_format);
302
303 FREE(ptr);
304}
305
313 struct PagerPrivateData *priv)
314{
315 struct PBarPrivateData *pbar_data = MUTT_MEM_CALLOC(1, struct PBarPrivateData);
316
317 pbar_data->shared = shared;
318 pbar_data->priv = priv;
319
320 return pbar_data;
321}
322
329struct MuttWindow *pbar_new(struct IndexSharedData *shared, struct PagerPrivateData *priv)
330{
334
335 win_pbar->wdata = pbar_data_new(shared, priv);
336 win_pbar->wdata_free = pbar_data_free;
337 win_pbar->recalc = pbar_recalc;
338 win_pbar->repaint = pbar_repaint;
339
345
346 return win_pbar;
347}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
Color and attribute parsing.
void mutt_color_observer_remove(observer_t callback, void *global_data)
Remove an observer.
Definition notify.c:71
void mutt_color_observer_add(observer_t callback, void *global_data)
Add an observer.
Definition notify.c:61
ColorId
List of all coloured objects.
Definition color.h:35
@ MT_COLOR_MAX
Definition color.h:97
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition color.h:78
@ MT_COLOR_NORMAL
Plain text.
Definition color.h:53
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
Pager Display.
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
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition dlg_index.c:802
Parse Expando string.
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
static int pbar_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition pbar.c:257
static int pbar_color_observer(struct NotifyCallback *nc)
Notification that a Color has changed - Implements observer_t -.
Definition pbar.c:171
static int pbar_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition pbar.c:194
static int pbar_pager_observer(struct NotifyCallback *nc)
Notification that the Pager has changed - Implements observer_t -.
Definition pbar.c:236
static int pbar_index_observer(struct NotifyCallback *nc)
Notification that the Index has changed - Implements observer_t -.
Definition pbar.c:221
static int pbar_recalc(struct MuttWindow *win)
Recalculate the Window data - Implements MuttWindow::recalc() -.
Definition pbar.c:90
static int pbar_repaint(struct MuttWindow *win)
Repaint the Window - Implements MuttWindow::repaint() -.
Definition pbar.c:151
static void pbar_data_free(struct MuttWindow *win, void **ptr)
Free the private data - Implements MuttWindow::wdata_free() -.
Definition pbar.c:294
Convenience wrapper for the gui headers.
GUI manage the main index (list of emails)
@ LL_DEBUG5
Log at debug level 5.
Definition logging2.h:49
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
Convenience wrapper for the library headers.
#define _(a)
Definition message.h:28
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:662
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:500
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:583
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
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.
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
#define WA_RECALC
Recalculate the contents of the Window.
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition mutt_window.h:38
@ NT_WINDOW_STATE
Window state has changed, e.g. WN_VISIBLE.
@ NT_WINDOW_DELETE
Window is about to be deleted.
#define WA_REPAINT
Redraw the contents of the Window.
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition mutt_window.h:52
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition mutt_window.h:47
@ 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_PAGER
Pager data has changed, NotifyPager, PagerPrivateData.
Definition notify_type.h:53
@ NT_ALL
Register for all notifications.
Definition notify_type.h:35
GUI display a file/email/help in a viewport with paging.
#define NT_PAGER_VIEW
Pager View has changed.
Definition lib.h:187
@ PAGER_MODE_EMAIL
Pager is invoked via 1st path. The mime part is selected automatically.
Definition lib.h:138
@ PAGER_MODE_ATTACH_E
A special case of PAGER_MODE_ATTACH - attachment is a full-blown email message.
Definition lib.h:140
Private state data for the Pager.
struct MuttWindow * pbar_new(struct IndexSharedData *shared, struct PagerPrivateData *priv)
Create the Pager Bar.
Definition pbar.c:329
static struct PBarPrivateData * pbar_data_new(struct IndexSharedData *shared, struct PagerPrivateData *priv)
Create new private data.
Definition pbar.c:312
Pager Bar.
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 MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition render.h:33
String manipulation buffer.
Definition buffer.h:36
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition subset.h:51
An Event that happened to a Colour.
Definition notify2.h:54
enum ColorId cid
Colour ID that has changed.
Definition notify2.h:55
A config-change event.
Definition subset.h:70
const char * name
Name of config item that changed.
Definition subset.h:72
An Event that happened to a Window.
struct MuttWindow * win
Window that changed.
Parsed Expando trees.
Definition expando.h:41
Data shared between Index, Pager and Sidebar.
Definition shared_data.h:37
struct Email * email
Currently selected Email.
Definition shared_data.h:42
struct Mailbox * mailbox
Current Mailbox.
Definition shared_data.h:41
struct ConfigSubset * sub
Config set to use.
Definition shared_data.h:38
struct MailboxView * mailbox_view
Current Mailbox view.
Definition shared_data.h:40
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition shared_data.h:44
LOFF_T offset
Offset into Email file (PagerPrivateData->fp)
Definition display.h:51
int msg_in_pager
Message currently shown in the pager.
Definition mview.h:45
int(* repaint)(struct MuttWindow *win)
struct WindowState state
Current state of the Window.
void * wdata
Private data.
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
int(* recalc)(struct MuttWindow *win)
void(* wdata_free)(struct MuttWindow *win, void **ptr)
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
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
Data to draw the Pager Bar.
Definition pbar.c:81
struct PagerPrivateData * priv
Private Pager data.
Definition pbar.c:83
char * pager_format
Cached status string.
Definition pbar.c:84
struct IndexSharedData * shared
Shared Index data.
Definition pbar.c:82
Private state data for the Pager.
int cur_line
Current line (last line visible on screen)
int lines_used
Size of lines array (used entries)
struct Line * lines
Array of text lines in pager.
struct Notify * notify
Notifications: NotifyPager, PagerPrivateData.
LOFF_T bytes_read
Number of bytes read from file.
int top_line
First visible line on screen.
struct stat st
Stats about Email file.
struct PagerView * pview
Object to view in the pager.
enum PagerMode mode
Pager mode.
Definition lib.h:174
const char * banner
Title to display in status bar.
Definition lib.h:176
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition mutt_window.h:60