NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

Progress bar. More...

#include <stdbool.h>
#include <stdio.h>
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  ProgressType { MUTT_PROGRESS_READ , MUTT_PROGRESS_WRITE , MUTT_PROGRESS_NET }
 What kind of operation is this progress tracking? More...
 

Functions

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...
 
bool progress_update (struct Progress *progress, size_t pos, int percent)
 Update the state of the progress bar. More...
 

Detailed Description

Progress bar.

Authors
  • 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 http://www.gnu.org/licenses/.

Definition in file lib.h.

Enumeration Type Documentation

◆ ProgressType

What kind of operation is this progress tracking?

Enumerator
MUTT_PROGRESS_READ 

Progress tracks elements, according to $read_inc

MUTT_PROGRESS_WRITE 

Progress tracks elements, according to $write_inc

MUTT_PROGRESS_NET 

Progress tracks bytes, according to $net_inc

Definition at line 47 of file lib.h.

48{
52};
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:51
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:49
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
Definition: lib.h:50

Function Documentation

◆ progress_free()

void progress_free ( struct Progress **  ptr)

Free a Progress Bar.

Parameters
ptrProgress Bar to free

Definition at line 86 of file progress.c.

87{
88 if (!ptr)
89 return;
90
91 if (!*ptr)
92 {
94 return;
95 }
96
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;
102
103 mutt_window_free(wptr);
104}
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.

Parameters
msgMessage to display
typeType, e.g. MUTT_PROGRESS_READ
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.

Note
msg will be copied

Definition at line 118 of file progress.c.

119{
120 if (OptNoCurses)
121 return NULL;
122
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 }
129
130 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
131 const bool is_bytes = (type == MUTT_PROGRESS_NET);
132
133 struct MuttWindow *win = progress_window_new(msg, size, size_inc, c_time_inc, is_bytes);
134
136
137 // Return an opaque pointer
138 return (struct Progress *) win;
139}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
#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
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
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.

Parameters
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.

74{
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;
80}
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: