ravan

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2025 License: MIT Imports: 4 Imported by: 0

README

🏄 Ravan

minimalist, progress bar library for Go.

the package name(Ravan) means smooth or flowing in persian. Exactly the same as the progress bar.

GitHub Release

Installation 🚀

go get github.com/pooulad/ravan@latest

Usage 📝

package main

import (
    "errors"
    "fmt"
    "time"

    "github.com/pooulad/ravan"
)

func main() {
    files := []string{"file1.txt", "file2.txt", "file3.txt", "file4.txt", "file6.txt"}

    bar, _ := ravan.New(ravan.WithMessage(&ravan.Message{Failed: "error custom message", Success: "success custom message"}))
    for i, file := range files {
        err := processFile(file)
        if err != nil {
            bar.FailMsg(fmt.Errorf("error processing %s: %w", file, err))
            return
        }
        bar.Draw(float64(i+1) / float64(len(files)))
    }

    bar.SuccessMsg()
}

See examples directory that added examples of all versions.also you can read the documentation that is in next section.

Bar characters 🔤

Name Sign
Hash "#"
Asterisk "*"
Equal "="
Plus "+"
Dash "-"
GreaterThan ">"
LessThan "<"
Colon ":"
Exclamation "!"
DollarSign "$"
AtSign "@"
Percent "%"
CircumFlex "^"
And "&"
Empty " "

📌Empty only available in WithIncompleteChar func.it is obvious that completed bar section can't fill with Empty char.

Custom message 💭

in v0.0.3 and above you can set custom Message struct for handling in error and successful situation with WithMessage func.

bar, _ := ravan.New(ravan.WithMessage(&ravan.Message{Failed: "error custom message", Success: "success custom message"}))

See and run this example

Documentation 📋

Go Reference

Check latest version please.

Demo 🖼

ravan_sample_screenshot

License 📏

Distributed under the MIT License. See LICENSE for more information.

👤Author

Created with ❤️ by pooulad.

Documentation

Index

Constants

View Source
const (
	CompleteType   = "complete"
	IncompleteType = "incomplete"
)

Validation categories

Variables

This section is empty.

Functions

This section is empty.

Types

type BarCharacter added in v0.0.2

type BarCharacter string
const (
	Empty       BarCharacter = " "
	Hash        BarCharacter = "#"
	Asterisk    BarCharacter = "*"
	Equal       BarCharacter = "="
	Plus        BarCharacter = "+"
	Dash        BarCharacter = "-"
	GreaterThan BarCharacter = ">"
	LessThan    BarCharacter = "<"
	Colon       BarCharacter = ":"
	Exclamation BarCharacter = "!"
	DollarSign  BarCharacter = "$"
	AtSign      BarCharacter = "@"
	Percent     BarCharacter = "%"
	CircumFlex  BarCharacter = "^"
	And         BarCharacter = "&"
)

type Message added in v0.0.3

type Message struct {
	Failed  string
	Success string
}

Message struct for showing with Ravan progress bar

type Option added in v0.0.2

type Option func(*Ravan) error

Option pattern for configuration You can use:

WithWidth
WithCompleteChar
WithIncompleteChar
WithMessage

func WithCompleteChar added in v0.0.2

func WithCompleteChar(c BarCharacter) Option

Complete character option

func WithIncompleteChar added in v0.0.2

func WithIncompleteChar(c BarCharacter) Option

Incomplete character option

func WithMessage added in v0.0.3

func WithMessage(msg *Message) Option

WithMessage sets the custom messages.

func WithWidth added in v0.0.2

func WithWidth(w int) Option

Width option

type Ravan

type Ravan struct {
	// contains filtered or unexported fields
}

Ravan struct

func New

func New(opts ...Option) (*Ravan, error)

New creates a validated Ravan instance

func (*Ravan) Draw

func (r *Ravan) Draw(progress float64)

Draw renders the progress bar on the terminal. progress should be a value between 0.0 and 1.0. When progress is 1.0 (100%), the bar is printed in green.

func (*Ravan) FailMsg added in v0.0.3

func (r *Ravan) FailMsg(err ...interface{})

FailMsg shows error (if provided) and/or custom failure message Usage: r.FailMsg() // Shows only custom message if set r.FailMsg(err) // Shows error + custom message r.FailMsg(err, customMessage) // Optional: Override default custom message

func (*Ravan) SuccessMsg added in v0.0.3

func (r *Ravan) SuccessMsg()

SuccessMsg prints a success message with successColor.

Directories

Path Synopsis
examples
v0.0.4 command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL