Termloader is a simple library to add a loading screen to your terminal applications. Termloader will render the loader at the center of your terminal screen. Currently termloader is supported only on *nix operating systems.
go get github.com/bharath-srinivas/termloader
package main
import (
"time"
"github.com/bharath-srinivas/termloader"
)
func main() {
loader := termloader.New(termloader.CharsetConfigs["default"]) // construct a new loader with config
loader.Start() // start the loader
time.Sleep(5 * time.Second) // sleep for sometime to simulate a task
loader.Stop() // stop the loader
}
loader.Color = termloader.Green // provide a color for the loader (white if not provided)
loader.Text = "Loading" // provide a text to show above the loader
loadingText := termloader.ColorString("Now Loading", termloader.Green) // color the string
loader.Text = loadingText // provide the colored string as loading text
loader.Delay = 100 * time.Millisecond // delay in milliseconds
Termloader supports only jpeg
and png
formats as of now. Support for more formats might be added later.
loader.Image.SetPath("/path/to/image") // provide the path of the loading image
loader.Image.SetWidth(55) // set custom width for the image
loader.Image.SetHeight(15) // set custom height for the image
loader.Image.Sharpen(6.5) // sharpens the image
charsetConfig := termloader.CharsetConfig{Charset: []string{"|", "/", "-", "\\"}, Delay: 100 * time.Millisecond}
loader := termloader.New(charsetConfig)
- Loader
- Optional loading text support
- Optional image/icon support
- Add a gif
MIT