Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rhygg/spinners
Spinners in the Terminal for vlang
https://github.com/rhygg/spinners
cli cli-spinner cli-spinners spinners v vlang
Last synced: about 1 month ago
JSON representation
Spinners in the Terminal for vlang
- Host: GitHub
- URL: https://github.com/rhygg/spinners
- Owner: rhygg
- License: mit
- Created: 2021-11-16T17:31:57.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-22T09:03:49.000Z (over 2 years ago)
- Last Synced: 2024-12-10T11:48:17.599Z (about 1 month ago)
- Topics: cli, cli-spinner, cli-spinners, spinners, v, vlang
- Language: V
- Homepage:
- Size: 35.2 KB
- Stars: 20
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-v - spinners - Create spinners in your terminal! (Libraries / Command line interface (CLI) / Terminal / Shell)
README
# Terminal Spinners in Vlang
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/0a49195147f54df9841a18abd6e07b66)](https://www.codacy.com/gh/rhygg/spinners/dashboard?utm_source=github.com&utm_medium=referral&utm_content=rhygg/spinners&utm_campaign=Badge_Grade)`spinners` is a cross-platform V library written in C and V to create spinner animations in your terminal. Useful for creating CLIs in V. Sample output:
![cast](cast.svg)
## Installation
With the **default** v cli:
```bash
v install --git https://github.com/rhygg/spinners
```
or with [vpkg](https://vpkg-project.github.io/):
```bash
vpkg get spinners
```
### Quick example
```v
import spinners { Spinner }
import timefn main() {
mut sp := Spinner{}
sp.start("please wait...") ?
time.sleep(1000 * time.millisecond)
sp.stop()
println("done!")
}
```
### Other default animation types
```v
import spinners { Spinner, AnimationType }
import timefn main() {
mut sp := Spinner {
animation: AnimationType.simple_dots
}
sp.start("please wait...") ?
time.sleep(3000 * time.millisecond)
// you can change text while it's running!
sp.set_text("almost there! hang tight...")
time.sleep(1000 * time.millisecond)
sp.stop()
println("done!")
}
```
### Customizing it's frames and interval
```v
import spinners { Spinner }
import timefn main() {
mut sp := Spinner {
frames: [ 'a', 'b', 'c', 'd' ] // string length must be consistent
interval: 80 // in ms
}
sp.start("please wait...") ?
time.sleep(1000 * time.millisecond)
sp.stop()
println("done!")
}
```
### Adding colors to the spinner
```v
import spinners { Spinner, Color }
import timefn main() {
mut sp := Spinner {
color: Color.magenta
}sp.start("please wait...")
time.sleep(1000 * time.millisecond)
sp.stop()
println("done!")
}
```
### Spinner with custom messages
```v
import spinners { Spinner, Color }
import timefn main() {
mut sp := Spinner {
color: Color.magenta
}sp.start("please wait...") ?
time.sleep(1000 * time.millisecond)
// instead of stop we can use success, warning, error, or info.
// sends a success message
sp.success("done!")
// sends an error message
sp.error("error!")// sends a warning message
sp.warning("warning!")// sends a info message
sp.info("info!")
}
```