NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
progress.c File Reference

Progress bar. More...

#include "config.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 "mutt_logging.h"
#include "options.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. More...
bool progress_update (struct Progress *progress, size_t pos, int percent)
 Update the state of the progress bar. More...
void progress_free (struct Progress **ptr)
 Free a Progress Bar. More...
struct Progress * progress_new (const char *msg, enum ProgressType type, size_t size)
 Create a new Progress Bar. More...

Detailed Description

Progress bar.

  • Richard Russon
  • Pietro Cerutti

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

Definition at line 50 of file progress.c.

52 const short c_read_inc = cs_subset_number(NeoMutt->sub, "read_inc");
53 const short c_write_inc = cs_subset_number(NeoMutt->sub, "write_inc");
54 const short c_net_inc = cs_subset_number(NeoMutt->sub, "net_inc");
55 const short *incs[] = { &c_read_inc, &c_write_inc, &c_net_inc };
56 return (type >= mutt_array_size(incs)) ? 0 : *incs[type];
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
#define mutt_array_size(x)
Definition: memory.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 73 of file progress.c.

75 // Decloak an opaque pointer
76 struct MuttWindow *win = (struct MuttWindow *) progress;
77 const bool updated = progress_window_update(win, pos, percent);
78 window_redraw(win);
79 return updated;
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:604
bool progress_window_update(struct MuttWindow *win, size_t pos, int percent)
Update the Progress Bar Window.
Definition: window.c:233
+ 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 86 of file progress.c.

88 if (!ptr)
89 return;
91 if (!*ptr)
92 {
94 return;
95 }
97 // Decloak an opaque pointer
98 struct MuttWindow **wptr = (struct MuttWindow **) ptr;
99 struct MuttWindow *win_pop = msgcont_pop_window();
100 if (win_pop != *wptr)
101 return;
103 mutt_window_free(wptr);
struct MuttWindow * msgcont_pop_window(void)
Remove the last Window from the Container Stack.
Definition: msgcont.c:56
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:201
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_new()

struct Progress * progress_new ( const char *  msg,
enum ProgressType  type,
size_t  size 

Create a new Progress Bar.

msgMessage to display
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.

msg will be copied

Definition at line 118 of file progress.c.

120 if (OptNoCurses)
121 return NULL;
123 const size_t size_inc = choose_increment(type);
124 if (size_inc == 0) // The user has disabled the progress bar
125 {
126 mutt_message(msg);
127 return NULL;
128 }
130 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
131 const bool is_bytes = (type == MUTT_PROGRESS_NET);
133 struct MuttWindow *win = progress_window_new(msg, size, size_inc, c_time_inc, is_bytes);
137 // Return an opaque pointer
138 return (struct Progress *) win;
#define mutt_message(...)
Definition: logging.h:86
void msgcont_push_window(struct MuttWindow *win)
Add a window to the Container Stack.
Definition: msgcont.c:87
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53
Progress tracks bytes, according to $net_inc
Definition: lib.h:51
struct MuttWindow * progress_window_new(const char *msg, size_t size, size_t size_inc, size_t time_inc, bool is_bytes)
Create a new Progress Bar Window.
Definition: window.c:271
static size_t choose_increment(enum ProgressType type)
Choose the right increment given a ProgressType.
Definition: progress.c:50
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: