1 .\" Copyright (c) 2013-2014 Devin Teske
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Nd dialog progress view library
39 .Fa "struct dpv_config *config, struct dpv_file_node *file_list"
48 library provides an interface for creating complex
50 widgets for displaying progress on various actions.
53 library can display progress with one of
58 .Pq x11/xdialog from the ports tree .
63 argument contains the following properties for configuring global display
65 .Bd -literal -offset indent
67 enum dpv_display display_type; /* Def. DPV_DISPLAY_LIBDIALOG */
68 enum dpv_output output_type; /* Default DPV_OUTPUT_NONE */
69 int debug; /* Enable debug on stderr */
70 int display_limit; /* Files/page. Default -1 */
71 int label_size; /* Label size. Default 28 */
72 int pbar_size; /* Mini-progress size */
73 int dialog_updates_per_second; /* Default 16 */
74 int status_updates_per_second; /* Default 2 */
75 uint16_t options; /* Default 0 (none) */
76 char *title; /* Widget title */
77 char *backtitle; /* Widget backtitle */
78 char *aprompt; /* Append. Default NULL */
79 char *pprompt; /* Prefix. Default NULL */
80 char *msg_done; /* Default `Done' */
81 char *msg_fail; /* Default `Fail' */
82 char *msg_pending; /* Default `Pending' */
83 char *output; /* Output format string */
84 const char *status_solo; /* dialog(3) solo-status format.
85 * Default DPV_STATUS_SOLO */
86 const char *status_many; /* dialog(3) many-status format.
87 * Default DPV_STATUS_MANY */
90 * Function pointer; action to perform data transfer
92 int (*action)(struct dpv_file_node *file, int out);
96 DPV_DISPLAY_LIBDIALOG = 0, /* Use dialog(3) (default) */
97 DPV_DISPLAY_STDOUT, /* Use stdout */
98 DPV_DISPLAY_DIALOG, /* Use spawned dialog(1) */
99 DPV_DISPLAY_XDIALOG, /* Use spawned Xdialog(1) */
103 DPV_OUTPUT_NONE = 0, /* No output (default) */
104 DPV_OUTPUT_FILE, /* Read `output' member as file path */
105 DPV_OUTPUT_SHELL, /* Read `output' member as shell cmd */
114 argument is a mask of bit fields indicating various processing options.
115 Possible flags are as follows:
116 .Bl -tag -width DPV_NO_OVERRUN
123 argument is not called but instead simulated-data is used to drive progress.
135 .Dv DPV_STATUS_DEFAULT
139 In wide mode, the length of the
146 argument will bump the width of the gauge widget.
147 Prompts wider than the maximum width will wrap
151 see BUGS section below
154 Disables the display of labels associated with each transfer
163 Force the use of color even if the
165 does not support color
168 environment variable is ignored
170 .It Dv DPV_NO_OVERRUN
171 When enabled, callbacks for the current
175 returns 100 or greater
177 alleviates the need to change the
181 but may also cause file truncation if the stream exceeds expected length
191 described as follows in
193 .Bd -literal -offset indent
194 struct dpv_file_node {
195 enum dpv_status status; /* status of read operation */
196 char *msg; /* display instead of "Done/Fail" */
197 char *name; /* name of file to read */
198 char *path; /* path to file */
199 long long length; /* expected size */
200 long long read; /* number units read (e.g., bytes) */
201 struct dpv_file_node *next;/* pointer to next (end with NULL) */
205 For each of the items in the
210 callback member of the
216 function should perform a
218 action on the file and return.
221 represents the current progress percentage
223 for the current file.
227 callback provides two variables for each call.
229 provides a reference to the current
233 provides a file descriptor where the data should go.
240 argument was set to DPV_OUTPUT_NONE
241 .Pq default ; when invoking Fn dpv ,
246 will be zero and should be ignored.
249 was set to DPV_OUTPUT_FILE,
251 will be an open file descriptor to a file.
254 was set to DPV_OUTPUT_SHELL,
256 will be an open file descriptor to a pipe for a spawned shell program.
259 is greater than zero, you should write any data you have read back to
266 callback or asynchronously from a signal handler, two globals are provided via
268 .Bd -literal -offset indent
269 extern int dpv_interrupt; /* Set to TRUE in interrupt handler */
270 extern int dpv_abort; /* Set to true in callback to abort */
273 These globals are not automatically reset and must be manually maintained.
274 Don't forget to reset these globals before subsequent invocations of
276 when making multiple calls from the same program.
283 argument can be used to control callbacks for the current file.
286 member can be set to any of the following from
288 .Bd -literal -offset indent
290 DPV_STATUS_RUNNING = 0, /* Running (default) */
291 DPV_STATUS_DONE, /* Completed */
292 DPV_STATUS_FAILED, /* Oops, something went wrong */
298 is zero, DPV_STATUS_RUNING, which keeps the callbacks coming for the current
302 to anything other than DPV_STATUS_RUNNING will cause
304 to loop to the next file, effecting the next callback, if any.
308 callback is responsible for calculating percentages and
314 can display throughput statistics.
315 Percentages are reported through the
320 Throughput statistics are calculated from the following global
324 .Bd -literal -offset indent
325 extern int dpv_overall_read;
328 This should be set to the number of bytes that have been read for all files.
329 Throughput information is displayed in the status line
330 .Pq only available when using Xr dialog 3
331 at the bottom of the screen.
332 See DPV_DISPLAY_LIBDIALOG above.
336 does not have to represent bytes.
337 For example, you can change the
339 to display something other than
344 .Pq e.g., counting lines .
348 is processing the current file, the
355 argument are used for calculating the display of mini progress bars
363 member of the current
366 .Pq indicating an unknown file length ,
368 .Xr humanize_number 3
371 member is used instead of a traditional progress bar.
372 Otherwise a progress bar is calculated as percentage read to file length.
374 callback must maintain these member values for mini-progress bars.
380 on private global variables initialized by
383 The following environment variables are referenced by
385 .Bl -tag -width ".Ev USE_COLOR"
387 Override command string used to launch
389 .Pq requires Dv DPV_DISPLAY_DIALOG
392 .Pq requires Dv DPV_DISPLAY_XDIALOG ;
395 .Pq for Dv DPV_DISPLAY_DIALOG
398 .Pq for Dv DPV_DISPLAY_XDIALOG .
400 If set and non-NULL, path to
406 is either not set or NULL, used as a prefix to
408 .Pq i.e., Ql $HOME/.dialogrc .
410 If set and NULL, disables the use of color when using
412 .Pq does not apply to Xr Xdialog 1 .
413 .It Ev msg_done Ev msg_fail Ev msg_pending
414 Internationalization strings for overriding the default English strings
420 To prevent their usage, explicitly set the
428 argument to default macros
429 .Pq DPV_DONE_DEFAULT, DPV_FAIL_DEFAULT, and DPV_PENDING_DEFAULT
433 .Bl -tag -width ".Pa $HOME/.dialogrc" -compact
434 .It Pa $HOME/.dialogrc
443 library first appeared in
446 .An Devin Teske Aq dteske@FreeBSD.org
450 .Ql Fl -title Ar title
455 .Va struct dpv_config
458 .Ql Fl -backtitle Ar backtitle
463 .Va struct dpv_config
465 displays the backtitle in place of the title and vice-versa.
468 does not wrap long prompt texts received after initial launch.
469 This is a known issue with the
473 Embed escaped newlines within prompt text(s) to force line breaks.
476 does not display the first character after a series of escaped escape-sequences
477 (e.g., ``\\\\n'' produces ``\\'' instead of ``\\n'').
478 This is a known issue with
485 If your application ignores
487 when set and NULL before calling
489 with color escape sequences anyway,
493 may not render properly.
494 Workaround is to detect when
496 is set and NULL and either not use color escape sequences at that time or use
500 forcing interpretation of color sequences.
503 which renders the color escape sequences as plain text.
506 embedded "\\Z" sequences
510 for additional information.