NeoMutt  2024-11-14-138-ge5ca67
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_NET , MUTT_PROGRESS_READ , MUTT_PROGRESS_WRITE }
 What kind of operation is this progress tracking? More...
 

Functions

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.
 
bool progress_update (struct Progress *progress, size_t pos, int percent)
 Update the state of the progress bar.
 
void progress_set_message (struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
 
void void progress_set_size (struct Progress *progress, size_t size)
 Set the progress size.
 

Detailed Description

Progress Bar.

Authors
  • 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 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_NET 

Progress tracks bytes, according to $net_inc

MUTT_PROGRESS_READ 

Progress tracks elements, according to $read_inc

MUTT_PROGRESS_WRITE 

Progress tracks elements, according to $write_inc

Definition at line 80 of file lib.h.

81{
85};
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:82
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
Definition: lib.h:83
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
Definition: lib.h:84

Function Documentation

◆ progress_free()

void progress_free ( struct Progress **  ptr)

Free a Progress Bar.

Parameters
ptrProgress Bar to free

Definition at line 110 of file progress.c.

111{
112 if (!ptr)
113 return;
114
115 if (!*ptr)
116 {
118 return;
119 }
120
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;
126
127 mutt_window_free(wptr);
128}
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.

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

140{
141 if (OptNoCurses)
142 return NULL;
143
144 const size_t size_inc = choose_increment(type);
145 if (size_inc == 0) // The user has disabled the progress bar
146 return NULL;
147
148 const short c_time_inc = cs_subset_number(NeoMutt->sub, "time_inc");
149 const bool is_bytes = (type == MUTT_PROGRESS_NET);
150
151 struct MuttWindow *win = progress_window_new(size, size_inc, c_time_inc, is_bytes);
152
154
155 // Return an opaque pointer
156 return (struct Progress *) win;
157}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: globals.c:69
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
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 80 of file progress.c.

81{
82 if (!progress)
83 return false;
84
85 // Decloak an opaque pointer
86 struct MuttWindow *win = (struct MuttWindow *) progress;
87 const bool updated = progress_window_update(win, pos, percent);
88
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 }
102
103 return updated;
104}
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:274
volatile sig_atomic_t SigWinch
true after SIGWINCH is received
Definition: signal.c:67
struct Notify * notify_resize
Window resize notifications handler.
Definition: neomutt.h:44
+ 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,
  ... 
)
+ Here is the caller graph for this function:

◆ progress_set_size()

void void progress_set_size ( struct Progress *  progress,
size_t  size 
)

Set the progress size.

Definition at line 190 of file progress.c.

191{
192 // Decloak an opaque pointer
193 struct MuttWindow *win = (struct MuttWindow *) progress;
194
196}
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: