Skip to content

A simple Go library for implementing terminal loading screen

License

Notifications You must be signed in to change notification settings

bharath-srinivas/termloader

Repository files navigation

Termloader

Build Status GoDoc License: MIT

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.

Installation

go get github.com/bharath-srinivas/termloader

Example Usage

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

loader.Color = termloader.Green // provide a color for the loader (white if not provided)

Provide a loading text

loader.Text = "Loading" // provide a text to show above the loader

Loading text color

loadingText := termloader.ColorString("Now Loading", termloader.Green) // color the string
loader.Text = loadingText // provide the colored string as loading text

Custom delay

loader.Delay = 100 * time.Millisecond // delay in milliseconds

Loading image

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

Provide your own character set for loader

charsetConfig := termloader.CharsetConfig{Charset: []string{"|", "/", "-", "\\"}, Delay: 100 * time.Millisecond}
loader := termloader.New(charsetConfig)

Todo

  • Loader
  • Optional loading text support
  • Optional image/icon support
  • Add a gif

License

MIT