Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/ermanimer/progress_bar

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ermanimer/progress_bar

  • v1.0.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

progress_bar

Go Progress Bar

Go Go Report Card

Features

progress_bar creates a single customizable progress bar for Linux terminal.

Installation

go get -u github.com/ermanimer/progress_bar

Functions

DefaultProgressBar(totalValue float64) *ProgressBar

Creates a progress bar with default parameters and given total value.

ParameterDescription
totalValueTotal value of progress bar

Default parameters:

Default ParameterValue
Default Schema[{bar}][{percent}][{current}/{total}][Elapsed: {elapsed}s Remaining:{remaining}s]
Default Filled Character#
Default Blank Character.
Default Length50
NewProgressBar(output io.Writer, schema string, filledCharacter string, blankCharacter string, length float64, totalValue float64) *ProgressBar

Creates a progress bar with default parameters and given total value.

ParameterDescription
outputOutput of progress bar
schemaSchema of progress bar
filledCharacterFilled character of progress bar
blankCharacterBlank character of progress bar
lengthLength of progress bar
totalValueTotal value of progress bar

Schema Variables:

Schema VariableValue
{bar}Bar of progress bar
{percent}Percentage of progress bar
{current}Current value of progress bar
{total}Total value of progress bar
{elapsed}Elapsed duration
{remaining}Estimated remaining duration

Methods

Start() error

Starts progress bar.

Stop() error

Stops progress bar.

Update(value float64) error

Updates progress bar with given value and stops progress bar is total value is reached.

ParameterDescription
valueCurrent value of progress bar

Usage

Default Progress Bar:
package main

import (
	"fmt"
	"time"

	"github.com/ermanimer/progress_bar"
)

func main() {
	//create new progress bar
	pb := progress_bar.DefaultProgressBar(100)
	//start
	err := pb.Start()
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	//update
	for value := 1; value <= 100; value++ {
		time.Sleep(20 * time.Millisecond)
		err := pb.Update(float64(value))
		if err != nil {
			fmt.Println(err.Error())
			break
		}
	}
}

Terminal Output: Default Terminal Output

New Progress Bar:
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/ermanimer/progress_bar"
)

func main() {
	//create parameters
	output := os.Stdout
	schema := "({bar}) ({percent}) ({current} of {total} completed)"
	filledCharacter := "="
	blankCharacter := "-"
	var length float64 = 60
	var totalValue float64 = 80
	//create new progress bar
	pb := progress_bar.NewProgressBar(output, schema, filledCharacter, blankCharacter, length, totalValue)
	//start
	err := pb.Start()
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	//update
	for value := 1; value <= 80; value++ {
		time.Sleep(20 * time.Millisecond)
		err := pb.Update(float64(value))
		if err != nil {
			fmt.Println(err.Error())
			break
		}
	}
}

Terminal Output: New Terminal Output

New Progress Bar Colored With color:
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/ermanimer/color/v2"
	"github.com/ermanimer/progress_bar"
)

func main() {
	//create parameters
	output := os.Stdout
	//create color functions
	orange := (&color.Color{Foreground: 172}).SprintFunction()
	grey := (&color.Color{Foreground: 246}).SprintFunction()
	//create colored schema
	bar := orange("{bar}")
	percent := grey("{percent}")
	schema := fmt.Sprintf("%s %s", bar, percent)
	filledCharacter := "▆"
	blankCharacter := " "
	var length float64 = 50
	var totalValue float64 = 80
	//create new progress bar
	pb := progress_bar.NewProgressBar(output, schema, filledCharacter, blankCharacter, length, totalValue)
	//start
	err := pb.Start()
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	//update
	for value := 1; value <= 80; value++ {
		time.Sleep(20 * time.Millisecond)
		err := pb.Update(float64(value))
		if err != nil {
			fmt.Println(err.Error())
			break
		}
	}
}

Terminal Output: New Terminal Output

References

FAQs

Package last updated on 27 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc