https://github.com/koki-develop/v-spinner
🌀 A library for V to display customizable spinners on the command line.
https://github.com/koki-develop/v-spinner
v vlang
Last synced: 11 days ago
JSON representation
🌀 A library for V to display customizable spinners on the command line.
- Host: GitHub
- URL: https://github.com/koki-develop/v-spinner
- Owner: koki-develop
- License: mit
- Created: 2023-10-14T00:48:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-14T03:31:18.000Z (over 2 years ago)
- Last Synced: 2025-04-15T20:07:40.345Z (10 months ago)
- Topics: v, vlang
- Language: V
- Homepage: https://vpm.vlang.io/packages/koki-develop.spinner
- Size: 117 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# v-spinner
🌀 A library for V to display customizable spinners on the command line.

## Installation
Add v-spinner to the `dependencies` in your `v.mod`.
```v
// v.mod
Module {
// ...
dependencies: [
// Install from VPM
'koki-develop.spinner'
// To install from GitHub
// 'https://github.com/koki-develop/v-spinner.git'
]
}
```
By running v install in this state, v-spinner will be installed.
```console
$ v install
```
## Usage
The following program is an example of the simplest usage.
```v
module main
import time
import koki_develop.spinner // When installed from VPM
// import spinner // When installed from GitHub
fn main() {
mut spin := spinner.new(spinner.slash_1)
spin.start() // Display the spinner
time.sleep(3 * time.second)
spin.stop()
}
```

### Customizing the Character Set
Several character sets are provided by v-spinner. For details, please refer to "[Character Sets Provided by v-spinner](#character-sets-provided-by-v-spinner)".
By passing an array of arbitrary strings to the first argument of spinner.new, you can use a custom character set.
```v
mut spin := spinner.new(['. ', '.. ', '...'])
```

### Setting Prefixes and Suffixes
You can customize prefixes and suffixes by setting the `prefix` and `suffix` attributes.
```v
module main
import time
import koki_develop.spinner // When installed from VPM
// import spinner // When installed from GitHub
fn main() {
mut spin := spinner.new(spinner.slash_1,
prefix: '[PREFIX] ', // optional
suffix: ' starting up...' // optional
)
spin.start() // Display the spinner
time.sleep(2 * time.second)
// It's also possible to change in the middle
spin.suffix = ' shutting down...'
time.sleep(2 * time.second)
spin.stop()
}
```

### Setting the Speed
You can set the interval at which the spinner characters change using the `duration`.
```v
module main
import time
import koki_develop.spinner // When installed from VPM
// import spinner // When installed from GitHub
fn main() {
mut spin := spinner.new(spinner.slash_1,
duration: 500 * time.millisecond // Default is 100ms
)
spin.start() // Display the spinner
time.sleep(2 * time.second)
// It's also possible to change in the middle
spin.duration = 50 * time.millisecond
time.sleep(2 * time.second)
spin.stop()
}
```

## Character Sets Provided by v-spinner
Several character sets are provided by v-spinner as constants.
| Index | Character Set |
| ------------------ | ---------------------------------------------------- |
| `spinner.slash_1` | `['\|', '/', '-', '\']` |
| `spinner.circle_1` | `['◐', '◓', '◑', '◒']` |
| `spinner.circle_2` | `['◴', '◷', '◶', '◵']` |
| `spinner.dots_1` | `['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']` |
## LICENSE
[MIT](./LICENSE)