File: make_spinner.Rd

package info (click to toggle)
r-cran-cli 3.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,288 kB
  • sloc: ansic: 16,412; cpp: 37; sh: 13; makefile: 2
file content (108 lines) | stat: -rw-r--r-- 3,444 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spinner.R
\name{make_spinner}
\alias{make_spinner}
\title{Create a spinner}
\usage{
make_spinner(
  which = NULL,
  stream = "auto",
  template = "{spin}",
  static = c("dots", "print", "print_line", "silent")
)
}
\arguments{
\item{which}{The name of the chosen spinner. If \code{NULL}, then the default
is used, which can be customized via the \code{cli.spinner_unicode},
\code{cli.spinner_ascii} and \code{cli.spinner} options. (The latter applies to
both Unicode and ASCII displays. These options can be set to the name
of a built-in spinner, or to a list that has an entry called \code{frames},
a character vector of frames.}

\item{stream}{The stream to use for the spinner. Typically this is
standard error, or maybe the standard output stream.
It can also be a string, one of \code{"auto"}, \code{"message"}, \code{"stdout"},
\code{"stderr"}. \code{"auto"} will select \code{stdout()} if the session is
interactive and there are no sinks, otherwise it will select
\code{stderr()}.}

\item{template}{A template string, that will contain the spinner. The
spinner itself will be substituted for \code{{spin}}. See example below.}

\item{static}{What to do if the terminal does not support dynamic
displays:
\itemize{
\item \code{"dots"}: show a dot for each \verb{$spin()} call.
\item \code{"print"}: just print the frames of the spinner, one after another.
\item \code{"print_line"}: print the frames of the spinner, each on its own line.
\item \code{"silent"} do not print anything, just the \code{template}.
}}
}
\value{
A \code{cli_spinner} object, which is a list of functions. See
its methods below.

\code{cli_spinner} methods:
\itemize{
\item \verb{$spin()}: output the next frame of the spinner.
\item \verb{$finish()}: terminate the spinner. Depending on terminal capabilities
this removes the spinner from the screen. Spinners can be reused,
you can start calling the \verb{$spin()} method again.
}

All methods return the spinner object itself, invisibly.

The spinner is automatically throttled to its ideal update frequency.
}
\description{
Create a spinner
}
\section{Examples}{

\subsection{Default spinner}{

\if{html}{\out{<div class="sourceCode r">}}\preformatted{sp1 <- make_spinner()
fun_with_spinner <- function() \{
  lapply(1:100, function(x) \{ sp1$spin(); Sys.sleep(0.05) \})
  sp1$finish()
\}
ansi_with_hidden_cursor(fun_with_spinner())
}\if{html}{\out{</div>}}

\if{html}{\figure{make-spinner-default.svg}}
}

\subsection{Spinner with a template}{

\if{html}{\out{<div class="sourceCode r">}}\preformatted{sp2 <- make_spinner(template = "Computing \{spin\}")
fun_with_spinner2 <- function() \{
  lapply(1:100, function(x) \{ sp2$spin(); Sys.sleep(0.05) \})
  sp2$finish()
\}
ansi_with_hidden_cursor(fun_with_spinner2())
}\if{html}{\out{</div>}}

\if{html}{\figure{make-spinner-template.svg}}
}

\subsection{Custom spinner}{

\if{html}{\out{<div class="sourceCode r">}}\preformatted{sp3 <- make_spinner("simpleDotsScrolling", template = "Downloading \{spin\}")
fun_with_spinner3 <- function() \{
  lapply(1:100, function(x) \{ sp3$spin(); Sys.sleep(0.05) \})
  sp3$finish()
\}
ansi_with_hidden_cursor(fun_with_spinner3())
}\if{html}{\out{</div>}}

\if{html}{\figure{make-spinner-custom.svg}}
}
}

\seealso{
Other spinners: 
\code{\link{demo_spinners}()},
\code{\link{get_spinner}()},
\code{\link{list_spinners}()}
}
\concept{spinners}