NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
progress.c File Reference

Progress bar. More...

#include "config.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.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.

Functions

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.

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 progress.c.

Function Documentation

◆ choose_increment()

static size_t choose_increment ( enum ProgressType  type)
static

Choose the right increment given a ProgressType.

Parameters
typeProgressType
Return values
numIncrement value

Definition at line 52 of file progress.c.

53{
54 switch (type)
55 {
57 return cs_subset_number(NeoMutt->sub, "net_inc");
59 return cs_subset_number(NeoMutt->sub, "read_inc");
61 return cs_subset_number(NeoMutt->sub, "write_inc");
62 default:
63 return 0;
64 }
65}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:81
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:82
@ MUTT_PROGRESS_WRITE
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.

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

82{
83 if (!progress)
84 return false;
85
86 // Decloak an opaque pointer
87 struct MuttWindow *win = (struct MuttWindow *) progress;
88 const bool updated = progress_window_update(win, pos, percent);
89
90 if (SigWinch)
91 {
92 SigWinch = false;
94 window_redraw(NULL);
95 }
96 else
97 {
98 if (updated)
99 {
100 window_redraw(win);
101 }
102 }
103
104 return updated;
105}
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.c:60
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
@ NT_RESIZE
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:272
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.

Parameters
ptrProgress Bar to free

Definition at line 111 of file progress.c.

112{
113 if (!ptr)
114 return;
115
116 if (!*ptr)
117 {
119 return;
120 }
121
122 // Decloak an opaque pointer
123 struct MuttWindow **wptr = (struct MuttWindow **) ptr;
124 struct MuttWindow *win_pop = msgcont_pop_window();
125 if (win_pop != *wptr)
126 return;
127
128 mutt_window_free(wptr);
129}
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 ( enum ProgressType  type,
size_t  size 
)

Create a new Progress Bar.

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

Definition at line 140 of file progress.c.

141{
142 if (OptNoCurses)
143 return NULL;
144
145 const size_t size_inc = choose_increment(type);
146 if (size_inc == 0) // The user has disabled the progress bar
147 return NULL;
148
149 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
150 const bool is_bytes = (type == MUTT_PROGRESS_NET);
151
152 struct MuttWindow *win = progress_window_new(size, size_inc, c_time_inc, is_bytes);
153
155
156 // Return an opaque pointer
157 return (struct Progress *) win;
158}
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:77
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:309
static size_t choose_increment(enum ProgressType type)
Choose the right increment given a ProgressType.
Definition: progress.c:52
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.

Parameters
progressProgress bar
fmtFormat string
...Format parameters

Definition at line 166 of file progress.c.

167{
168 // Decloak an opaque pointer
169 struct MuttWindow *win = (struct MuttWindow *) progress;
170
171 va_list ap;
172 va_start(ap, fmt);
173
174 if (win)
175 {
176 progress_window_set_message(win, fmt, ap);
177 }
178 else
179 {
180 char msg[1024] = { 0 };
181 vsnprintf(msg, sizeof(msg), fmt, ap);
182 mutt_message("%s", msg);
183 }
184
185 va_end(ap);
186}
#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:344
+ 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 191 of file progress.c.

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