DPV(3)
π DPV(3) β dialog progress view library β¨
πΈ NAME πΈ
dpv β dialog progress view library π
π LIBRARY π
library βlibdpvβ π«Ά
β¨ SYNOPSIS β¨
#include <dpv.h>
int
dpv(struct dpv_config *config, struct dpv_file_node *file_list);
void
dpv_free(void);
π DESCRIPTION π
okay so bestie, the dpv library is what you use when you want to create those fancy βgaugeβ widgets that show progress for all kinds of actions. It can display progress with one of dialog(3), dialog(1), or Xdialog(1) (ports/x11/xdialog). π
The dpv() config argument properties configure the global display features. Hereβs the struct dpv_config in all its glory, with every member and comment intact:
struct dpv_config {
uint8_t keep_tite; /* Cleaner exit for scripts */
enum dpv_display display_type; /* Def. DPV_DISPLAY_LIBDIALOG */
enum dpv_output output_type; /* Default DPV_OUTPUT_NONE */
int debug; /* Enable debug on stderr */
int display_limit; /* Files/page. Default -1 */
int label_size; /* Label size. Default 28 */
int pbar_size; /* Mini-progress size */
int dialog_updates_per_second; /* Default 16 */
int status_updates_per_second; /* Default 2 */
uint16_t options; /* Default 0 (none) */
char *title; /* Widget title */
char *backtitle; /* Widget backtitle */
char *aprompt; /* Append. Default NULL */
char *pprompt; /* Prefix. Default NULL */
char *msg_done; /* Default `Done' */
char *msg_fail; /* Default `Fail' */
char *msg_pending; /* Default `Pending' */
char *output; /* Output format string */
const char *status_solo; /* dialog(3) solo-status format.
* Default DPV_STATUS_SOLO */
const char *status_many; /* dialog(3) many-status format.
* Default DPV_STATUS_MANY */
/*
* Function pointer; action to perform data transfer
*/
int (*action)(struct dpv_file_node *file, int out);
};
And the enums, bestie β no details skipped:
enum dpv_display {
DPV_DISPLAY_LIBDIALOG = 0, /* Use dialog(3) (default) */
DPV_DISPLAY_STDOUT, /* Use stdout */
DPV_DISPLAY_DIALOG, /* Use spawned dialog(1) */
DPV_DISPLAY_XDIALOG, /* Use spawned Xdialog(1) */
};
enum dpv_output {
DPV_OUTPUT_NONE = 0, /* No output (default) */
DPV_OUTPUT_FILE, /* Read `output' member as file path */
DPV_OUTPUT_SHELL, /* Read `output' member as shell cmd */
};
The options member of the dpv() config argument is a mask of bit fields that flags various processing options. Possible flags are:
DPV_TEST_MODEβ turns on test mode. In test mode, theaction()callback of theconfigargument is not called; instead simulated-data is used to drive progress. It appends β[TEST MODE]β to the status line (to override, set thestatus_formatmember of thedpv()configargument; for example, toDPV_STATUS_DEFAULT). π§ͺDPV_WIDE_MODEβ turns on wide mode. In wide mode, the length of theapromptandppromptmembers of thedpv()configargument will bump the width of the gauge widget. Prompts wider than the maximum width will wrap (unless usingXdialog(1)(ports/x11/xdialog); see BUGS section below). π¦DPV_NO_LABELSβ disables the display of labels associated with each transfer (thelabel_sizemember of thedpv()configargument is ignored). πDPV_USE_COLORβ forces the use of color even if thedisplay_typedoes not support color (USE_COLORenvironment variable is ignored). πDPV_NO_OVERRUNβ when enabled, callbacks for the currentdpv_file_nodeare terminated whenaction()returns100or greater. This alleviates the need to change the status of the currentdpv_file_node, but it may also cause file truncation if the stream exceeds expected length. β οΈ
The file_list argument to dpv() is a pointer to a βlinked-listβ, described in <dpv.h>:
struct dpv_file_node {
enum dpv_status status; /* status of read operation */
char *msg; /* display instead of "Done/Fail" */
char *name; /* name of file to read */
char *path; /* path to file */
long long length; /* expected size */
long long read; /* number units read (e.g., bytes) */
struct dpv_file_node *next;/* pointer to next (end with NULL) */
};
For each of the items in the file_list βlinked-listβ argument, the action() callback member of the dpv() config argument is called. The action() function performs a βnominalβ action on the file and then returns. The return value of int represents the current progress percentage (0-100) for the current file. π―
The action() callback provides two variables for each call. file provides a reference to the current dpv_file_node being processed. out provides a file descriptor where the data goes.
If the output member of the dpv() config argument was set to DPV_OUTPUT_NONE (default; when invoking dpv()), the out file descriptor of action() will be zero and can be ignored. If output was set to DPV_OUTPUT_FILE, out will be an open file descriptor to a file. If output was set to DPV_OUTPUT_SHELL, out will be an open file descriptor to a pipe for a spawned shell program. When out is greater than zero, write data that has been read back to out. π«Ά
To abort dpv(), either from the action() callback or asynchronously from a signal handler, two globals are provided via <dpv.h>:
extern int dpv_interrupt; /* Set to TRUE in interrupt handler */
extern int dpv_abort; /* Set to true in callback to abort */
β οΈ These globals are not automatically reset and must be manually maintained. Do not forget to reset these globals before subsequent invocations of dpv() when making multiple calls from the same program. π
In addition, the status member of the action() file argument can be used to control callbacks for the current file. The status member can be set to any of the below from <dpv.h>:
enum dpv_status {
DPV_STATUS_RUNNING = 0, /* Running (default) */
DPV_STATUS_DONE, /* Completed */
DPV_STATUS_FAILED, /* Oops, something went wrong */
};
The default status is zero, DPV_STATUS_RUNNING, which keeps the callbacks coming for the current file(). Setting βfile->statusβ to anything other than DPV_STATUS_RUNNING will cause dpv() to loop to the next file, effecting the next callback, if any. π
The action() callback is responsible for calculating percentages and (recommended) maintaining a dpv global counter so dpv() can display throughput statistics. Percentages are reported through the int return value of the action() callback. Throughput statistics are calculated from the below global int in <dpv.h>:
extern int dpv_overall_read;
Set this to the number of bytes that have been read for all files. Throughput information is displayed in the status line (only available when using dialog(3)) at the bottom of the screen. See DPV_DISPLAY_LIBDIALOG above. π
Note that dpv_overall_read does not have to represent bytes. For example, the status_format can be changed to display something other than βbytesβ and increment dpv_overall_read accordingly (for example, counting lines). π
When dpv() is processing the current file, the length and read members of the action() file argument are used for calculating the display of mini progress bars (if enabled; see pbar_size above). If the length member of the current file is less than zero (indicating an unknown file length), a humanize_number(3) version of the read member is used instead of a traditional progress bar. Otherwise a progress bar is calculated as percentage read to file length. action() callback must maintain these member values for mini-progress bars. π
The dpv_free() function performs free(3) on private global variables initialized by dpv(). π§Ή
πΏ ENVIRONMENT πΏ
The below environment variables are referenced by dpv:
DIALOGβ override command string used to launchdialog(1)(requiresDPV_DISPLAY_DIALOG) orXdialog(1)(ports/x11/xdialog) (requiresDPV_DISPLAY_XDIALOG); default is either βdialogβ (forDPV_DISPLAY_DIALOG) or βXdialogβ (forDPV_DISPLAY_XDIALOG). ποΈDIALOGRCβ if set and non-NULL, path to β.dialogrcβ file.HOMEβ if β$DIALOGRCβ is either not set orNULL, used as a prefix to β.dialogrcβ (that is, β$HOME/.dialogrcβ). πUSE_COLORβ if set andNULL, disables the use of color when usingdialog(1). Does not apply toXdialog(1)(ports/x11/xdialog). πmsg_done,msg_fail,msg_pendingβ internationalization strings for overriding the default English strings βDoneβ, βFailβ, and βPendingβ respectively. To prevent their usage, explicitly set themsg_done,msg_fail, andmsg_pendingmembers ofdpv()configargument to default macros (DPV_DONE_DEFAULT,DPV_FAIL_DEFAULT, andDPV_PENDING_DEFAULT) or desired values. π
ποΈ FILES ποΈ
$HOME/.dialogrc
π SEE ALSO π
dialog(1)Xdialog(1)(ports/x11/xdialog)dialog(3)
π°οΈ HISTORY π°οΈ
The dpv library first appeared in FreeBSD 10.2. β
π AUTHORS π
Devin Teske <dteske@FreeBSD.org>
π BUGS (the receipts, bestie) π
Okay so these are the known little gremlins β no cap, read them before you come for the code:
Xdialog(1)(ports/x11/xdialog) has a whole identity crisis when you give it both--title title(thetitlemember ofstruct dpv_config, obvi) and--backtitle backtitle(thebacktitlemember ofstruct dpv_config) β it displays the backtitle in place of the title and vice-versa. Literally swapping them. Iconic? No. πXdialog(1)(ports/x11/xdialog) does not wrap long prompt texts received after initial launch. This is a known issue with the--gaugewidget inXdialog(1)(ports/x11/xdialog). If you need line breaks, embed escaped newlines within the prompt text to force them. π«dialog(1)does not display the first character after a series of escaped escape-sequences (for example,\\nproduces\instead of\n). This is a known issue withdialog(1)and does not affectdialog(3)orXdialog(1)(ports/x11/xdialog). π- If an application ignores
USE_COLORwhen set andNULLbefore callingdpv()with color escape sequences anyway, thendialog(3)anddialog(1)may not render properly. π The workaround is to detect whenUSE_COLORis set andNULLand either not use color escape sequences at that time, or useunsetenv(3)to unsetUSE_COLOR, forcing interpretation of color sequences. This does not affectXdialog(1)(ports/x11/xdialog), which renders the color escape sequences as plain text. See βembedded"\Z"sequencesβ indialog(1)for additional information. β¨
Thatβs the tea from Debian, dated March 13, 2018 β page DPV(3), signing off ππ¦β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- Copyright (c) 2013-2018 Devin Teske
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms