Repository

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.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.

$ v install

Usage

The following program is an example of the simplest usage.

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 ".

By passing an array of arbitrary strings to the first argument of spinner.new, you can use a custom character set.

mut spin := spinner.new(['.  ', '.. ', '...'])

Setting Prefixes and Suffixes

You can customize prefixes and suffixes by setting the prefix and suffix attributes.

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 .

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

About

🌀 A library for V to display customizable spinners on the command line.

0
13
1 year ago

Author

koki-develop