Git Product home page Git Product logo

spinners's Introduction

Terminal Spinners in Vlang

Codacy Badge

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

Installation

With the default v cli:

v install --git https://github.com/rhygg/spinners

or with vpkg:

vpkg get spinners

Quick example

import spinners { Spinner }
import time

fn main() {
    mut sp := Spinner{}
    sp.start("please wait...") ?
    
    time.sleep(1000 * time.millisecond)
    
    sp.stop()
    println("done!")
}

Other default animation types

import spinners { Spinner, AnimationType }
import time

fn 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

import spinners { Spinner }
import time

fn 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

import spinners { Spinner, Color }
import time

fn main() {
    mut sp := Spinner {
        color: Color.magenta
    }

    sp.start("please wait...")
    time.sleep(1000 * time.millisecond)
    
    sp.stop()
    println("done!")
}

Spinner with custom messages

import spinners { Spinner, Color }
import time

fn 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!")
}

spinners's People

Contributors

null8626 avatar sksmta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spinners's Issues

spinner error when i tried to run it

OS:WIndows 11

Error message:
error: expected type is not an enum (string)
124 | // all panics shouldn't happen, so they are suppressed
125 | fn (mut self Spinner) set_animation(index int) {
126 | spinners_data := read_file(.json_path) or { return }
| ~~~~~~~~~~
127 | mp_obj := raw_decode(spinners_data) or { return }
128 | mp := mp_obj.arr()[index].as_map()
C:/Users/OjanRN/.vmodules/spinners/spinner.v:207:44: error: expected type is not an enum (int)
205 | } else {
206 | if self.animation == AnimationType.@none {
207 | self.set_animation(.default_index)
| ~~~~~~~~~~~~~~
208 | } else {
209 | self.set_animation(int(self.animation) - 1)

Feature request: Implement use of term.control so spinners don't interfer with eachother.

Right now if you launch two threads of the same method both using spinners they'll "overlap" each other until one of them is done.

With the implementation of the terminal controls from term.control I believe you should be able to make so each spinner keeps track of it's own position to then move the cursor to its own row before updating itself. After a spinner has updated the cursor should probably be moved to the end of terminal in case anything else needs to write.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.