1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/docs.R
\name{progress-c}
\alias{progress-c}
\title{The cli progress C API}
\description{
The cli progress C API
}
\section{The cli progress C API}{
\subsection{\code{CLI_SHOULD_TICK}}{
A macro that evaluates to (int) 1 if a cli progress bar update is due,
and to (int) 0 otherwise. If the timer hasn't been initialized in this
compilation unit yet, then it is always 0. To initialize the timer,
call \code{cli_progress_init_timer()} or create a progress bar with
\code{cli_progress_bar()}.
}
\subsection{\code{cli_progress_add()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_add(SEXP bar, double inc);
}\if{html}{\out{</div>}}
Add a number of progress units to the progress bar. It will also
trigger an update if an update is due.
\itemize{
\item \code{bar}: progress bar object.
\item \code{inc}: progress increment.
}
}
\subsection{\code{cli_progress_bar()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{SEXP cli_progress_bar(double total, SEXP config);
}\if{html}{\out{</div>}}
Create a new progress bar object. The returned progress bar object
must be \code{PROTECT()}-ed.
\itemize{
\item \code{total}: Total number of progress units. Use \code{NA_REAL} if it is not
known.
\item \code{config}: R named list object of additional parameters. May be \code{NULL}
(the C \verb{NULL~) or }R_NilValue\verb{(the R}NULL`) for the defaults.
}
\code{config} may contain the following entries:
\itemize{
\item \code{name}: progress bar name.
\item \code{status}: (initial) progress bar status.
\item \code{type}: progress bar type.
\item \code{total}: total number of progress units.
\item \code{show_after}: show the progress bar after the specified number of
seconds. This overrides the global \code{show_after} option.
\item \code{format}: format string, must be specified for custom progress bars.
\item \code{format_done}: format string for successful termination.
\item \code{format_failed}: format string for unsuccessful termination.
\item \code{clear}: whether to remove the progress bar from the screen after
termination.
\item \code{auto_terminate}: whether to terminate the progress bar when the
number of current units equals the number of total progress units.
}
\subsection{Example}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{#include <cli/progress.h>
SEXP progress_test1() \{
int i;
SEXP bar = PROTECT(cli_progress_bar(1000, NULL));
for (i = 0; i < 1000; i++) \{
cli_progress_sleep(0, 4 * 1000 * 1000);
if (CLI_SHOULD_TICK) cli_progress_set(bar, i);
\}
cli_progress_done(bar);
UNPROTECT(1);
return Rf_ScalarInteger(i);
\}
}\if{html}{\out{</div>}}
}
}
\subsection{\code{cli_progress_done()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_done(SEXP bar);
}\if{html}{\out{</div>}}
Terminate the progress bar.
\itemize{
\item \code{bar}: progress bar object.
}
}
\subsection{\code{cli_progress_init_timer()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_init_timer();
}\if{html}{\out{</div>}}
Initialize the cli timer without creating a progress bar.
}
\subsection{\code{cli_progress_num()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{int cli_progress_num();
}\if{html}{\out{</div>}}
Returns the number of currently active progress bars.
}
\subsection{\code{cli_progress_set()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set(SEXP bar, double set);
}\if{html}{\out{</div>}}
Set the progress bar to the specified number of progress units.
\itemize{
\item \code{bar}: progress bar object.
\item \code{set}: number of current progress progress units.
}
}
\subsection{\code{cli_progress_set_clear()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set_clear(SEXP bar, int clear);
}\if{html}{\out{</div>}}
Set whether to remove the progress bar from the screen. You can call
this any time before \code{cli_progress_done()} is called.
\itemize{
\item \code{bar}: progress bar object.
\item \code{clear}: whether to remove the progress bar from the screen, zero or
one.
}
}
\subsection{\code{cli_progress_set_format()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set_format(SEXP bar, const char *format, ...);
}\if{html}{\out{</div>}}
Set a custom format string for the progress bar. This call does not
try to update the progress bar. If you want to request an update,
call \code{cli_progress_add()}, \code{cli_progress_set()} or
\code{cli_progress_update()}.
\itemize{
\item \code{bar}: progress bar object.
\item \code{format}: format string.
\item \code{...}: values to substitute into \code{format}.
}
\code{format} and \code{...} are passed to \code{vsnprintf()} to create a format
string.
Format strings may contain glue substitutions, referring to
\href{https://cli.r-lib.org/dev/reference/progress-variables.html}{progress variables}, pluralization, and cli
styling.
}
\subsection{\code{cli_progress_set_name()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set_name(SEXP bar, const char *name);
}\if{html}{\out{</div>}}
Set the name of the progress bar.
\itemize{
\item \code{bar}; progress bar object.
\item \code{name}: progress bar name.
}
}
\subsection{\code{cli_progress_set_status()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set_status(SEXP bar, const char *status);
}\if{html}{\out{</div>}}
Set the status of the progress bar.
\itemize{
\item \code{bar}: progress bar object.
\item \code{status }: progress bar status.
}
}
\subsection{\code{cli_progress_set_type()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_set_type(SEXP bar, const char *type);
}\if{html}{\out{</div>}}
Set the progress bar type. Call this function right after creating
the progress bar with \code{cli_progress_bar()}. Otherwise the behavior is
undefined.
\itemize{
\item \code{bar}: progress bar object.
\item \code{type}: progress bar type. Possible progress bar types:
\code{iterator}, \code{tasks}, \code{download} and \code{custom}.
}
}
\subsection{\code{cli_progress_update()}}{
\if{html}{\out{<div class="sourceCode c">}}\preformatted{void cli_progress_update(SEXP bar, double set, double inc, int force);
}\if{html}{\out{</div>}}
Update the progress bar. Unlike the simpler \code{cli_progress_add()} and
\code{cli_progress_set()} function, it can force an update if \code{force} is
set to 1.
\itemize{
\item \code{bar}: progress bar object.
\item \code{set}: the number of current progress units. It is ignored if
negative.
\item \code{inc}: increment to add to the current number of progress units.
It is ignored if \code{set} is not negative.
\item \code{force}: whether to force an update, even if no update is due.
}
To force an update without changing the current number of progress units,
supply \code{set = -1}, \code{inc = 0} and \code{force = 1}.
}
}
|