Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
8a0c9ccffc | |||
51f7259fe9 | |||
99773d353a | |||
466dc76306 | |||
8b4ae386a7 | |||
2e7c49e299 |
29
README.md
29
README.md
@ -4,7 +4,26 @@ Spinners for the console.
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Install using composer.
|
Recommended is to install using composer. Add the repository to your global
|
||||||
|
`~/.config/composer/config.json` file:
|
||||||
|
|
||||||
|
```
|
||||||
|
{
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "composer",
|
||||||
|
"url": "https://dev.noccylabs.info/api/packages/noccy/composer"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add the package as a dependency:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ composer require noccylabs/spinner
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -32,3 +51,11 @@ while(true) {
|
|||||||
usleep(10000);
|
usleep(10000);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Included styles
|
||||||
|
|
||||||
|
Style | Width | Notes
|
||||||
|
---|---|---
|
||||||
|
`BrailleDotStyle` | 1 | A snake chasing its tail, new "docker compose" style
|
||||||
|
`RollingBallStyle` | 1 | A rolling ball, "symfony new" style
|
||||||
|
`SpinnerStyle` | 2 | four-part spinner, 2 characters wide
|
||||||
|
@ -19,10 +19,19 @@ $spinner7 = new Spinner(fps:5);
|
|||||||
$spinner8 = new Spinner(fps:10);
|
$spinner8 = new Spinner(fps:10);
|
||||||
$spinner9 = new Spinner(fps:20);
|
$spinner9 = new Spinner(fps:20);
|
||||||
|
|
||||||
|
$spinner10 = new Spinner(fps:10, style:NoccyLabs\Spinner\Style\SpinningBarStyle::class);
|
||||||
|
|
||||||
|
$spinner11 = new Spinner(fps:10, style:NoccyLabs\Spinner\Style\BrailleBounceStyle::class);
|
||||||
|
|
||||||
|
$spinner12 = new Spinner(fps:10, style:NoccyLabs\Spinner\Style\BrailleTallDotsStyle::class);
|
||||||
|
|
||||||
|
$spinner13 = new Spinner(fps:10, style:NoccyLabs\Spinner\Style\BrailleWideDotsStyle::class);
|
||||||
|
|
||||||
|
$spinner14 = new Spinner(fps:20, style:NoccyLabs\Spinner\Style\BrailleWideSpinnerStyle::class);
|
||||||
|
|
||||||
// And blast them out every 10ms!
|
// And blast them out every 10ms!
|
||||||
while(true) {
|
while(true) {
|
||||||
echo "\r $spinner1 $spinner2 $spinner3 $spinner4 $spinner5 $spinner6 $spinner7 $spinner8 $spinner9 ";
|
echo "\r $spinner1 $spinner2 $spinner3 $spinner4 $spinner5 $spinner6 $spinner7 $spinner8 $spinner9 $spinner10 $spinner11 $spinner12 $spinner13 $spinner14";
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
src/Style/BrailleBounceStyle.php
Normal file
23
src/Style/BrailleBounceStyle.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Spinner\Style;
|
||||||
|
|
||||||
|
class BrailleBounceStyle implements StyleInterface
|
||||||
|
{
|
||||||
|
public function getFrames(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
mb_chr(0x2809),
|
||||||
|
mb_chr(0x2812),
|
||||||
|
mb_chr(0x2824),
|
||||||
|
mb_chr(0x28c0),
|
||||||
|
mb_chr(0x2824),
|
||||||
|
mb_chr(0x2812),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -15,4 +15,9 @@ class BrailleDotsStyle implements StyleInterface
|
|||||||
mb_chr(0x281b),
|
mb_chr(0x281b),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
47
src/Style/BrailleTallDotsStyle.php
Normal file
47
src/Style/BrailleTallDotsStyle.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Spinner\Style;
|
||||||
|
|
||||||
|
class BrailleTallDotsStyle implements StyleInterface
|
||||||
|
{
|
||||||
|
public function getFrames(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
mb_chr(0x2839),
|
||||||
|
mb_chr(0x28b0),
|
||||||
|
mb_chr(0x28f0),
|
||||||
|
mb_chr(0x28e4),
|
||||||
|
mb_chr(0x28c6),
|
||||||
|
mb_chr(0x2847),
|
||||||
|
mb_chr(0x280f),
|
||||||
|
mb_chr(0x281b),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
| xxx0 xxx1 xxx2 xxx3 xxx4 xxx5 xxx6 xxx7 xxx8 xxx9 xxxA xxxB xxxC xxxD xxxE xxxF
|
||||||
|
280x | ⠀ ⠁ ⠂ ⠃ ⠄ ⠅ ⠆ ⠇ ⠈ ⠉ ⠊ ⠋ ⠌ ⠍ ⠎ ⠏
|
||||||
|
281x | ⠐ ⠑ ⠒ ⠓ ⠔ ⠕ ⠖ ⠗ ⠘ ⠙ ⠚ ⠛ ⠜ ⠝ ⠞ ⠟
|
||||||
|
282x | ⠠ ⠡ ⠢ ⠣ ⠤ ⠥ ⠦ ⠧ ⠨ ⠩ ⠪ ⠫ ⠬ ⠭ ⠮ ⠯
|
||||||
|
283x | ⠰ ⠱ ⠲ ⠳ ⠴ ⠵ ⠶ ⠷ ⠸ ⠹ ⠺ ⠻ ⠼ ⠽ ⠾ ⠿
|
||||||
|
284x | ⡀ ⡁ ⡂ ⡃ ⡄ ⡅ ⡆ ⡇ ⡈ ⡉ ⡊ ⡋ ⡌ ⡍ ⡎ ⡏
|
||||||
|
285x | ⡐ ⡑ ⡒ ⡓ ⡔ ⡕ ⡖ ⡗ ⡘ ⡙ ⡚ ⡛ ⡜ ⡝ ⡞ ⡟
|
||||||
|
286x | ⡠ ⡡ ⡢ ⡣ ⡤ ⡥ ⡦ ⡧ ⡨ ⡩ ⡪ ⡫ ⡬ ⡭ ⡮ ⡯
|
||||||
|
287x | ⡰ ⡱ ⡲ ⡳ ⡴ ⡵ ⡶ ⡷ ⡸ ⡹ ⡺ ⡻ ⡼ ⡽ ⡾ ⡿
|
||||||
|
288x | ⢀ ⢁ ⢂ ⢃ ⢄ ⢅ ⢆ ⢇ ⢈ ⢉ ⢊ ⢋ ⢌ ⢍ ⢎ ⢏
|
||||||
|
289x | ⢐ ⢑ ⢒ ⢓ ⢔ ⢕ ⢖ ⢗ ⢘ ⢙ ⢚ ⢛ ⢜ ⢝ ⢞ ⢟
|
||||||
|
28Ax | ⢠ ⢡ ⢢ ⢣ ⢤ ⢥ ⢦ ⢧ ⢨ ⢩ ⢪ ⢫ ⢬ ⢭ ⢮ ⢯
|
||||||
|
28Bx | ⢰ ⢱ ⢲ ⢳ ⢴ ⢵ ⢶ ⢷ ⢸ ⢹ ⢺ ⢻ ⢼ ⢽ ⢾ ⢿
|
||||||
|
28Cx | ⣀ ⣁ ⣂ ⣃ ⣄ ⣅ ⣆ ⣇ ⣈ ⣉ ⣊ ⣋ ⣌ ⣍ ⣎ ⣏
|
||||||
|
28Dx | ⣐ ⣑ ⣒ ⣓ ⣔ ⣕ ⣖ ⣗ ⣘ ⣙ ⣚ ⣛ ⣜ ⣝ ⣞ ⣟
|
||||||
|
28Ex | ⣠ ⣡ ⣢ ⣣ ⣤ ⣥ ⣦ ⣧ ⣨ ⣩ ⣪ ⣫ ⣬ ⣭ ⣮ ⣯
|
||||||
|
28Fx | ⣰ ⣱ ⣲ ⣳ ⣴ ⣵ ⣶ ⣷ ⣸ ⣹ ⣺ ⣻ ⣼ ⣽ ⣾ ⣿
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
51
src/Style/BrailleWideDotsStyle.php
Normal file
51
src/Style/BrailleWideDotsStyle.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Spinner\Style;
|
||||||
|
|
||||||
|
class BrailleWideDotsStyle implements StyleInterface
|
||||||
|
{
|
||||||
|
public function getFrames(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
" ⠹",
|
||||||
|
" ⢸",
|
||||||
|
" ⣰",
|
||||||
|
"⢀⣠",
|
||||||
|
"⣀⣀",
|
||||||
|
"⣄ ",
|
||||||
|
"⣆⡀",
|
||||||
|
"⡇ ",
|
||||||
|
"⠏ ",
|
||||||
|
"⠋⠁",
|
||||||
|
"⠉⠉",
|
||||||
|
"⠈⠙",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
| xxx0 xxx1 xxx2 xxx3 xxx4 xxx5 xxx6 xxx7 xxx8 xxx9 xxxA xxxB xxxC xxxD xxxE xxxF
|
||||||
|
280x | ⠀ ⠁ ⠂ ⠃ ⠄ ⠅ ⠆ ⠇ ⠈ ⠉ ⠊ ⠋ ⠌ ⠍ ⠎ ⠏
|
||||||
|
281x | ⠐ ⠑ ⠒ ⠓ ⠔ ⠕ ⠖ ⠗ ⠘ ⠙ ⠚ ⠛ ⠜ ⠝ ⠞ ⠟
|
||||||
|
282x | ⠠ ⠡ ⠢ ⠣ ⠤ ⠥ ⠦ ⠧ ⠨ ⠩ ⠪ ⠫ ⠬ ⠭ ⠮ ⠯
|
||||||
|
283x | ⠰ ⠱ ⠲ ⠳ ⠴ ⠵ ⠶ ⠷ ⠸ ⠹ ⠺ ⠻ ⠼ ⠽ ⠾ ⠿
|
||||||
|
284x | ⡀ ⡁ ⡂ ⡃ ⡄ ⡅ ⡆ ⡇ ⡈ ⡉ ⡊ ⡋ ⡌ ⡍ ⡎ ⡏
|
||||||
|
285x | ⡐ ⡑ ⡒ ⡓ ⡔ ⡕ ⡖ ⡗ ⡘ ⡙ ⡚ ⡛ ⡜ ⡝ ⡞ ⡟
|
||||||
|
286x | ⡠ ⡡ ⡢ ⡣ ⡤ ⡥ ⡦ ⡧ ⡨ ⡩ ⡪ ⡫ ⡬ ⡭ ⡮ ⡯
|
||||||
|
287x | ⡰ ⡱ ⡲ ⡳ ⡴ ⡵ ⡶ ⡷ ⡸ ⡹ ⡺ ⡻ ⡼ ⡽ ⡾ ⡿
|
||||||
|
288x | ⢀ ⢁ ⢂ ⢃ ⢄ ⢅ ⢆ ⢇ ⢈ ⢉ ⢊ ⢋ ⢌ ⢍ ⢎ ⢏
|
||||||
|
289x | ⢐ ⢑ ⢒ ⢓ ⢔ ⢕ ⢖ ⢗ ⢘ ⢙ ⢚ ⢛ ⢜ ⢝ ⢞ ⢟
|
||||||
|
28Ax | ⢠ ⢡ ⢢ ⢣ ⢤ ⢥ ⢦ ⢧ ⢨ ⢩ ⢪ ⢫ ⢬ ⢭ ⢮ ⢯
|
||||||
|
28Bx | ⢰ ⢱ ⢲ ⢳ ⢴ ⢵ ⢶ ⢷ ⢸ ⢹ ⢺ ⢻ ⢼ ⢽ ⢾ ⢿
|
||||||
|
28Cx | ⣀ ⣁ ⣂ ⣃ ⣄ ⣅ ⣆ ⣇ ⣈ ⣉ ⣊ ⣋ ⣌ ⣍ ⣎ ⣏
|
||||||
|
28Dx | ⣐ ⣑ ⣒ ⣓ ⣔ ⣕ ⣖ ⣗ ⣘ ⣙ ⣚ ⣛ ⣜ ⣝ ⣞ ⣟
|
||||||
|
28Ex | ⣠ ⣡ ⣢ ⣣ ⣤ ⣥ ⣦ ⣧ ⣨ ⣩ ⣪ ⣫ ⣬ ⣭ ⣮ ⣯
|
||||||
|
28Fx | ⣰ ⣱ ⣲ ⣳ ⣴ ⣵ ⣶ ⣷ ⣸ ⣹ ⣺ ⣻ ⣼ ⣽ ⣾ ⣿
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
51
src/Style/BrailleWideSpinnerStyle.php
Normal file
51
src/Style/BrailleWideSpinnerStyle.php
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Spinner\Style;
|
||||||
|
|
||||||
|
class BrailleWideSpinnerStyle implements StyleInterface
|
||||||
|
{
|
||||||
|
public function getFrames(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
" ⠒",
|
||||||
|
" ⠤",
|
||||||
|
" ⢄",
|
||||||
|
" ⡄",
|
||||||
|
"⢠ ",
|
||||||
|
"⡠ ",
|
||||||
|
"⠤ ",
|
||||||
|
"⠒ ",
|
||||||
|
"⠑ ",
|
||||||
|
"⠘ ",
|
||||||
|
" ⠃",
|
||||||
|
" ⠊",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
| xxx0 xxx1 xxx2 xxx3 xxx4 xxx5 xxx6 xxx7 xxx8 xxx9 xxxA xxxB xxxC xxxD xxxE xxxF
|
||||||
|
280x | ⠀ ⠁ ⠂ ⠃ ⠄ ⠅ ⠆ ⠇ ⠈ ⠉ ⠊ ⠋ ⠌ ⠍ ⠎ ⠏
|
||||||
|
281x | ⠐ ⠑ ⠒ ⠓ ⠔ ⠕ ⠖ ⠗ ⠘ ⠙ ⠚ ⠛ ⠜ ⠝ ⠞ ⠟
|
||||||
|
282x | ⠠ ⠡ ⠢ ⠣ ⠤ ⠥ ⠦ ⠧ ⠨ ⠩ ⠪ ⠫ ⠬ ⠭ ⠮ ⠯
|
||||||
|
283x | ⠰ ⠱ ⠲ ⠳ ⠴ ⠵ ⠶ ⠷ ⠸ ⠹ ⠺ ⠻ ⠼ ⠽ ⠾ ⠿
|
||||||
|
284x | ⡀ ⡁ ⡂ ⡃ ⡄ ⡅ ⡆ ⡇ ⡈ ⡉ ⡊ ⡋ ⡌ ⡍ ⡎ ⡏
|
||||||
|
285x | ⡐ ⡑ ⡒ ⡓ ⡔ ⡕ ⡖ ⡗ ⡘ ⡙ ⡚ ⡛ ⡜ ⡝ ⡞ ⡟
|
||||||
|
286x | ⡠ ⡡ ⡢ ⡣ ⡤ ⡥ ⡦ ⡧ ⡨ ⡩ ⡪ ⡫ ⡬ ⡭ ⡮ ⡯
|
||||||
|
287x | ⡰ ⡱ ⡲ ⡳ ⡴ ⡵ ⡶ ⡷ ⡸ ⡹ ⡺ ⡻ ⡼ ⡽ ⡾ ⡿
|
||||||
|
288x | ⢀ ⢁ ⢂ ⢃ ⢄ ⢅ ⢆ ⢇ ⢈ ⢉ ⢊ ⢋ ⢌ ⢍ ⢎ ⢏
|
||||||
|
289x | ⢐ ⢑ ⢒ ⢓ ⢔ ⢕ ⢖ ⢗ ⢘ ⢙ ⢚ ⢛ ⢜ ⢝ ⢞ ⢟
|
||||||
|
28Ax | ⢠ ⢡ ⢢ ⢣ ⢤ ⢥ ⢦ ⢧ ⢨ ⢩ ⢪ ⢫ ⢬ ⢭ ⢮ ⢯
|
||||||
|
28Bx | ⢰ ⢱ ⢲ ⢳ ⢴ ⢵ ⢶ ⢷ ⢸ ⢹ ⢺ ⢻ ⢼ ⢽ ⢾ ⢿
|
||||||
|
28Cx | ⣀ ⣁ ⣂ ⣃ ⣄ ⣅ ⣆ ⣇ ⣈ ⣉ ⣊ ⣋ ⣌ ⣍ ⣎ ⣏
|
||||||
|
28Dx | ⣐ ⣑ ⣒ ⣓ ⣔ ⣕ ⣖ ⣗ ⣘ ⣙ ⣚ ⣛ ⣜ ⣝ ⣞ ⣟
|
||||||
|
28Ex | ⣠ ⣡ ⣢ ⣣ ⣤ ⣥ ⣦ ⣧ ⣨ ⣩ ⣪ ⣫ ⣬ ⣭ ⣮ ⣯
|
||||||
|
28Fx | ⣰ ⣱ ⣲ ⣳ ⣴ ⣵ ⣶ ⣷ ⣸ ⣹ ⣺ ⣻ ⣼ ⣽ ⣾ ⣿
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
@ -13,4 +13,9 @@ class RollingBallStyle implements StyleInterface
|
|||||||
mb_chr(0x25d2),
|
mb_chr(0x25d2),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,9 @@ class SpinnerStyle implements StyleInterface
|
|||||||
mb_chr(0x25df).' ',
|
mb_chr(0x25df).' ',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
21
src/Style/SpinningBarStyle.php
Normal file
21
src/Style/SpinningBarStyle.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace NoccyLabs\Spinner\Style;
|
||||||
|
|
||||||
|
class SpinningBarStyle implements StyleInterface
|
||||||
|
{
|
||||||
|
public function getFrames(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"/",
|
||||||
|
"-",
|
||||||
|
"\\",
|
||||||
|
"|",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidth(): int
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
@ -4,5 +4,13 @@ namespace NoccyLabs\Spinner\Style;
|
|||||||
|
|
||||||
interface StyleInterface
|
interface StyleInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Returns an array of frames used to render the spinner
|
||||||
|
*/
|
||||||
public function getFrames(): array;
|
public function getFrames(): array;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the width of this spinner in characters
|
||||||
|
*/
|
||||||
|
public function getWidth(): int;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user