NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
window.h File Reference

Progress Bar Window. More...

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

Go to the source code of this file.

Functions

struct MuttWindowprogress_window_new (size_t size, size_t size_inc, size_t time_inc, bool is_bytes)
 Create a new Progress Bar Window.
 
void progress_window_set_message (struct MuttWindow *win, const char *fmt, va_list ap)
 Set the progress message.
 
void progress_window_set_size (struct MuttWindow *win, size_t size)
 Set the progress size.
 
bool progress_window_update (struct MuttWindow *win, size_t pos, int percent)
 Update the Progress Bar Window.
 

Detailed Description

Progress Bar Window.

Authors
  • 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 window.h.

Function Documentation

◆ progress_window_new()

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.

Parameters
sizeExpected number of records or size of traffic
size_incSize increment (step size)
time_incTime increment
is_bytestrue if measuring bytes
Return values
ptrNew Progress Window

Definition at line 316 of file window.c.

318{
319 if (size_inc == 0) // The user has disabled the progress bar
320 return NULL;
321
327
328 struct ProgressWindowData *wdata = progress_wdata_new();
329 wdata->win = win;
330 wdata->size = size;
331 wdata->size_inc = size_inc;
332 wdata->time_inc = time_inc;
333 wdata->is_bytes = is_bytes;
334
335 if (is_bytes)
336 {
337 struct Buffer *pretty = buf_pool_get();
338 mutt_str_pretty_size(pretty, size);
339 mutt_str_copy(wdata->pretty_size, buf_string(pretty), sizeof(wdata->pretty_size));
340 buf_pool_release(&pretty);
341 }
342
343 win->wdata = wdata;
345
346 return win;
347}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
static int progress_window_recalc(struct MuttWindow *win)
Recalculate the Progress Bar - Implements MuttWindow::recalc() -.
Definition: window.c:135
static int progress_window_repaint(struct MuttWindow *win)
Repaint the Progress Bar - Implements MuttWindow::repaint() -.
Definition: window.c:164
void progress_wdata_free(struct MuttWindow *win, void **ptr)
Free Progress Bar Window data - Implements MuttWindow::wdata_free() -.
Definition: wdata.c:45
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:582
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:182
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ MUTT_WIN_ORIENT_VERTICAL
Window uses all available vertical space.
Definition: mutt_window.h:39
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_FIXED
Window has a fixed size.
Definition: mutt_window.h:48
int mutt_str_pretty_size(struct Buffer *buf, size_t num)
Display an abbreviated size, like 3.4K.
Definition: muttlib.c:1003
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
struct ProgressWindowData * progress_wdata_new(void)
Create new Progress Bar Window Data.
Definition: wdata.c:37
String manipulation buffer.
Definition: buffer.h:36
int(* repaint)(struct MuttWindow *win)
Definition: mutt_window.h:187
void * wdata
Private data.
Definition: mutt_window.h:145
int(* recalc)(struct MuttWindow *win)
Definition: mutt_window.h:173
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
Progress Bar Window Data.
Definition: wdata.h:36
size_t size
Total expected size.
Definition: wdata.h:42
size_t time_inc
Time increment.
Definition: wdata.h:44
size_t size_inc
Size increment.
Definition: wdata.h:43
bool is_bytes
true if measuring bytes
Definition: wdata.h:45
struct MuttWindow * win
Window to draw on.
Definition: wdata.h:37
char pretty_size[24]
Pretty string for size.
Definition: wdata.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ progress_window_set_message()

void progress_window_set_message ( struct MuttWindow win,
const char *  fmt,
va_list  ap 
)

Set the progress message.

Parameters
winWindow to draw on
fmtprintf format string
apprintf arguments

Definition at line 355 of file window.c.

356{
357 if (!win || !win->wdata || !fmt)
358 return;
359
360 struct ProgressWindowData *wdata = win->wdata;
361
362 vsnprintf(wdata->msg, sizeof(wdata->msg), fmt, ap);
363
365}
#define WA_RECALC
Recalculate the contents of the Window.
Definition: mutt_window.h:110
WindowActionFlags actions
Actions to be performed, e.g. WA_RECALC.
Definition: mutt_window.h:132
char msg[1024]
Message to display.
Definition: wdata.h:40
+ Here is the caller graph for this function:

◆ progress_window_set_size()

void progress_window_set_size ( struct MuttWindow win,
size_t  size 
)

Set the progress size.

Parameters
winWindow to draw on
sizeNew size

Definition at line 372 of file window.c.

373{
374 if (!win || !win->wdata)
375 return;
376
377 struct ProgressWindowData *wdata = win->wdata;
378
379 wdata->size = size;
380 wdata->display_pos = 0;
381 wdata->display_percent = 0;
382 wdata->display_time = 0;
384}
int display_percent
Displayed percentage complete.
Definition: wdata.h:49
size_t display_pos
Displayed position.
Definition: wdata.h:48
uint64_t display_time
Time of last display.
Definition: wdata.h:50
+ Here is the caller graph for this function:

◆ progress_window_update()

bool progress_window_update ( struct MuttWindow win,
size_t  pos,
int  percent 
)

Update the Progress Bar Window.

Parameters
winWindow to draw on
posPosition, or count
percentPercentage complete
Return values
trueScreen update is needed

Definition at line 279 of file window.c.

280{
281 if (!win || !win->wdata)
282 return false;
283
284 struct ProgressWindowData *wdata = win->wdata;
285
286 if (percent >= 0)
287 {
288 if (!percent_needs_update(wdata, percent))
289 return false;
290 }
291 else
292 {
293 if (!pos_needs_update(wdata, pos))
294 return false;
295 }
296
297 const uint64_t now = mutt_date_now_ms();
298 if (!time_needs_update(wdata, now))
299 return false;
300
301 wdata->update_pos = pos;
302 wdata->update_percent = percent;
303 wdata->update_time = now;
305 return true;
306}
uint64_t mutt_date_now_ms(void)
Return the number of milliseconds since the Unix epoch.
Definition: date.c:465
static bool percent_needs_update(const struct ProgressWindowData *wdata, int percent)
Do we need to update, given the current percentage?
Definition: window.c:237
static bool time_needs_update(const struct ProgressWindowData *wdata, size_t now)
Do we need to update, given the current time?
Definition: window.c:260
static bool pos_needs_update(const struct ProgressWindowData *wdata, long pos)
Do we need to update, given the current pos?
Definition: window.c:248
int update_percent
Updated percentage complete.
Definition: wdata.h:55
uint64_t update_time
Time of last update.
Definition: wdata.h:56
size_t update_pos
Updated position.
Definition: wdata.h:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function: