NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
No Matches
progress.c File Reference

Progress bar. More...

#include "config.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "globals.h"
#include "mutt_logging.h"
#include "window.h"
+ Include dependency graph for progress.c:

Go to the source code of this file.


static size_t choose_increment (enum ProgressType type)
 Choose the right increment given a ProgressType.
bool progress_update (struct Progress *progress, size_t pos, int percent)
 Update the state of the progress bar.
void progress_free (struct Progress **ptr)
 Free a Progress Bar.
struct Progress * progress_new (enum ProgressType type, size_t size)
 Create a new Progress Bar.
void progress_set_message (struct Progress *progress, const char *fmt,...)
 Set the progress message.
void progress_set_size (struct Progress *progress, size_t size)
 Set the progress size.

Detailed Description

Progress bar.

  • Pietro Cerutti
  • 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

Definition in file progress.c.

Function Documentation

◆ choose_increment()

static size_t choose_increment ( enum ProgressType  type)

Choose the right increment given a ProgressType.

Return values
numIncrement value

Definition at line 51 of file progress.c.

53 switch (type)
54 {
56 return cs_subset_number(NeoMutt->sub, "net_inc");
58 return cs_subset_number(NeoMutt->sub, "read_inc");
60 return cs_subset_number(NeoMutt->sub, "write_inc");
61 default:
62 return 0;
63 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
Progress tracks bytes, according to $net_inc
Definition: lib.h:81
Progress tracks elements, according to $read_inc
Definition: lib.h:82
Progress tracks elements, according to $write_inc
Definition: lib.h:83
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_update()

bool progress_update ( struct Progress *  progress,
size_t  pos,
int  percent 

Update the state of the progress bar.

progressProgress bar
posPosition, or count
percentPercentage complete
Return values
trueScreen update is needed

If percent is -1, then the percentage will be calculated using pos and the size in progress.

If percent is positive, it is displayed as percentage, otherwise percentage is calculated from size and pos if progress was initialized with positive size, otherwise no percentage is shown

Definition at line 80 of file progress.c.

82 if (!progress)
83 return false;
85 // Decloak an opaque pointer
86 struct MuttWindow *win = (struct MuttWindow *) progress;
87 const bool updated = progress_window_update(win, pos, percent);
89 if (SigWinch)
90 {
91 SigWinch = false;
93 window_redraw(NULL);
94 }
95 else
96 {
97 if (updated)
98 {
99 window_redraw(win);
100 }
101 }
103 return updated;
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
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
Window has been resized.
Definition: notify_type.h:52
bool progress_window_update(struct MuttWindow *win, size_t pos, int percent)
Update the Progress Bar Window.
Definition: window.c:274
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition: signal.c:64
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_free()

void progress_free ( struct Progress **  ptr)

Free a Progress Bar.

ptrProgress Bar to free

Definition at line 110 of file progress.c.

112 if (!ptr)
113 return;
115 if (!*ptr)
116 {
118 return;
119 }
121 // Decloak an opaque pointer
122 struct MuttWindow **wptr = (struct MuttWindow **) ptr;
123 struct MuttWindow *win_pop = msgcont_pop_window();
124 if (win_pop != *wptr)
125 return;
127 mutt_window_free(wptr);
struct MuttWindow * msgcont_pop_window(void)
Remove the last Window from the Container Stack.
Definition: msgcont.c:57
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
void mutt_window_free(struct MuttWindow **ptr)
Free a Window and its children.
Definition: mutt_window.c:202
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_new()

struct Progress * progress_new ( enum ProgressType  type,
size_t  size 

Create a new Progress Bar.

sizeTotal size of expected file / traffic
Return values
ptrNew Progress Bar

If the user has disabled the progress bar, e.g. set read_inc = 0 then a simple message will be displayed instead.

Definition at line 139 of file progress.c.

141 if (OptNoCurses)
142 return NULL;
144 const size_t size_inc = choose_increment(type);
145 if (size_inc == 0) // The user has disabled the progress bar
146 return NULL;
148 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
149 const bool is_bytes = (type == MUTT_PROGRESS_NET);
151 struct MuttWindow *win = progress_window_new(size, size_inc, c_time_inc, is_bytes);
155 // Return an opaque pointer
156 return (struct Progress *) win;
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:72
void msgcont_push_window(struct MuttWindow *win)
Add a window to the Container Stack.
Definition: msgcont.c:93
struct MuttWindow * progress_window_new(size_t size, size_t size_inc, size_t time_inc, bool is_bytes)
Create a new Progress Bar Window.
Definition: window.c:311
static size_t choose_increment(enum ProgressType type)
Choose the right increment given a ProgressType.
Definition: progress.c:51
enum MuttWindowSize size
Type of Window, e.g. MUTT_WIN_SIZE_FIXED.
Definition: mutt_window.h:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_set_message()

void progress_set_message ( struct Progress *  progress,
const char *  fmt,

Set the progress message.

progressProgress bar
fmtFormat string
...Format parameters

Definition at line 165 of file progress.c.

167 // Decloak an opaque pointer
168 struct MuttWindow *win = (struct MuttWindow *) progress;
170 va_list ap;
171 va_start(ap, fmt);
173 if (win)
174 {
175 progress_window_set_message(win, fmt, ap);
176 }
177 else
178 {
179 char msg[1024] = { 0 };
180 vsnprintf(msg, sizeof(msg), fmt, ap);
181 mutt_message("%s", msg);
182 }
184 va_end(ap);
#define mutt_message(...)
Definition: logging2.h:91
void progress_window_set_message(struct MuttWindow *win, const char *fmt, va_list ap)
Set the progress message.
Definition: window.c:346
+ Here is the call graph for this function:

◆ progress_set_size()

void progress_set_size ( struct Progress *  progress,
size_t  size 

Set the progress size.

Definition at line 190 of file progress.c.

192 // Decloak an opaque pointer
193 struct MuttWindow *win = (struct MuttWindow *) progress;
void progress_window_set_size(struct MuttWindow *win, size_t size)
Set the progress size.
Definition: window.c:363
+ Here is the call graph for this function: