-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Added documentation for Spinner. (#207)
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
layout: default | ||
title: Spinner | ||
permalink: /terminal-objects/spinner/ | ||
--- | ||
|
||
Spinner | ||
============== | ||
|
||
Spinner displays a running indicator to indicate that a task is being performed. | ||
|
||
~~~php | ||
$spinner = $climate->spinner('Running task...'); | ||
|
||
for ($i = 0; $i < 12; $i++) { | ||
$spinner->advance(); | ||
sleep(1); | ||
} | ||
~~~ | ||
|
||
Which will result in: | ||
|
||
![Spinner](/img/spinner.gif) | ||
|
||
Spinner can be started with a label and with custom characters to display: | ||
|
||
~~~php | ||
$spinner = $climate->spinner('My custom label', '[> ]', '[ > ]', '[ >]', '[ <]', '[ < ]', '[ < ]', '[< ]'); | ||
|
||
for ($i = 0; $i < 12; $i++) { | ||
$spinner->advance(); | ||
sleep(1); | ||
} | ||
~~~ | ||
|
||
$label and $characters are optional. If $label is not provided, no label will be | ||
displayed. If $characters is not provided, the default characters will be used. | ||
|
||
You can also set the spinner characters after creating the instance: | ||
|
||
~~~php | ||
$spinner->characters('[> ]', '[ > ]', '[ >]', '[ <]', '[ < ]', '[ < ]', '[< ]'); | ||
~~~ | ||
|
||
It is also possible to set a waiting time between drawing each stage. | ||
This is useful to avoid frequent redrawing of the screen. | ||
|
||
~~~php | ||
$spinner = $climate->spinner(); | ||
$spinner->timeLimit(2);// Redraws the screen every 2 seconds. | ||
for ($i = 0; $i < 12; $i++) { | ||
$spinner->advance(); | ||
sleep(1); | ||
} | ||
~~~ | ||
|
||
The `Spinner::advance()` method can be given a label: | ||
|
||
~~~php | ||
$spinner = $climate->spinner(); | ||
for ($i = 0; $i < 12; $i++) { | ||
$step = $i + 1; | ||
$spinner->advance("Step $step..."); | ||
sleep(1); | ||
} | ||
~~~ |