NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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.
 
struct Progress * progress_new (const char *msg, enum ProgressType type, size_t size)
 Create a new Progress Bar.
 
bool progress_update (struct Progress *progress, size_t pos, int percent)
 Update the state of the progress bar.
 

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 92 of file progress.c.

93{
94 if (!ptr)
95 return;
96
97 if (!*ptr)
98 {
100 return;
101 }
102
103 // Decloak an opaque pointer
104 struct MuttWindow **wptr = (struct MuttWindow **) ptr;
105 struct MuttWindow *win_pop = msgcont_pop_window();
106 if (win_pop != *wptr)
107 return;
108
109 mutt_window_free(wptr);
110}
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:73
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 ( 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 124 of file progress.c.

125{
126 if (OptNoCurses)
127 return NULL;
128
129 const size_t size_inc = choose_increment(type);
130 if (size_inc == 0) // The user has disabled the progress bar
131 {
132 mutt_message("%s", msg);
133 return NULL;
134 }
135
136 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
137 const bool is_bytes = (type == MUTT_PROGRESS_NET);
138
139 struct MuttWindow *win = progress_window_new(msg, size, size_inc, c_time_inc, is_bytes);
140
142
143 // Return an opaque pointer
144 return (struct Progress *) win;
145}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:79
#define mutt_message(...)
Definition: logging2.h:91
void msgcont_push_window(struct MuttWindow *win)
Add a window to the Container Stack.
Definition: msgcont.c:93
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:281
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: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.

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 if (!progress)
76 return false;
77
78 // Decloak an opaque pointer
79 struct MuttWindow *win = (struct MuttWindow *) progress;
80 const bool updated = progress_window_update(win, pos, percent);
81 if (updated)
82 {
83 window_redraw(win);
84 }
85 return updated;
86}
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:634
bool progress_window_update(struct MuttWindow *win, size_t pos, int percent)
Update the Progress Bar Window.
Definition: window.c:243
+ Here is the call graph for this function:
+ Here is the caller graph for this function: