Skip to content

Commit

Permalink
docs: Added documentation for Spinner. (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
everton3x authored Nov 18, 2024
1 parent a68758b commit 69ab757
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Binary file added img/spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions terminal-objects/spinner.md
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);
}
~~~

0 comments on commit 69ab757

Please sign in to comment.