ui

package
v0.0.0-...-46101f6 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ui contains some simple structs that have nice-looking String() methods for printing console output with unicode characters.

Example
package main

import (
	"fmt"

	"github.com/julz/prettyprogress/ui"
)

func main() {
	fmt.Printf("\n%s", ui.Steps{
		{
			Name:   "Building..",
			Bullet: ui.Complete,
		},
		{
			Name:   "Downloading..",
			Bullet: ui.Downloading,
			Bar:    ui.NewBar(10, 100).String(),
		},
		{
			Name:   "Scanning..",
			Bullet: ui.Running,
			Bar:    ui.NewBar(20, 100).String(),
		},
		{
			Name:   "Waiting to Start..",
			Bullet: ui.Future,
		},
	})

}
Output:

 ✓  Building..
 ↡  Downloading..        [██                  ]
 ►  Scanning..           [████                ]
    Waiting to Start..

Index

Examples

Constants

View Source
const DefaultBarEnd = "]"
View Source
const DefaultBarStart = "["

Variables

View Source
var (
	RunningState  BulletState = "Running"
	CompleteState BulletState = "Complete"
	FailedState   BulletState = "Failed"

	Failed      Bullet = []string{"✗"}
	Future      Bullet = []string{" "}
	Running     Bullet = []string{"►"}
	Downloading Bullet = []string{"↡"}
	Uploading   Bullet = []string{"↟"}
	Complete    Bullet = []string{"✓"}

	AnimatedRunning  Bullet = []string{"⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"}
	AnimatedRunning2 Bullet = []string{"◴", "◷", "◶", "◵"}
	AnimatedRunning3 Bullet = []string{"◐", "◓", "◑", "◒"}
	AnimatedRunning4 Bullet = []string{"▉", "▊", "▋", "▌", "▍", "▎", "▏", "▎", "▍", "▌", "▋", "▊", "▉"}
	AnimatedRunning5 Bullet = []string{"←", "↖", "↑", "↗", "→", "↘", "↓", "↙"}
	AnimatedRunning6 Bullet = []string{"⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"}
)

Functions

func PercentageLabel

func PercentageLabel(progress, total int) string

Types

type Bar

type Bar struct {
	Progress int
	Total    int
	Width    int

	StartChar string
	EndChar   string

	LabelFunc LabelFunc
}

Bar is a simple progress bar struct that knows how to String() itself in a pretty way

Example
package main

import (
	"fmt"

	"github.com/julz/prettyprogress/ui"
)

func main() {
	fmt.Printf("%s", ui.Bar{
		Width:    5,
		Total:    100,
		Progress: 40,
	})

}
Output:

[██   ]

func NewBar

func NewBar(progress, total int) Bar

NewBar creates a new Bar with a default width of 20 characters

func NewBarWithWidth

func NewBarWithWidth(progress, total, width int) Bar

NewBarWithWidth creates a new Bar with the given progress, total and width

func (Bar) String

func (b Bar) String() string

String stringifies the Bar to a nice-looking unicode string

type Bullet

type Bullet []string

Bullet is a unicode status icon for a Step

func (Bullet) WithColor

func (b Bullet) WithColor(color Color) Bullet

type BulletSet

type BulletSet struct {
	Failed      Bullet
	Future      Bullet
	Running     Bullet
	Downloading Bullet
	Uploading   Bullet
	Complete    Bullet
}

type BulletState

type BulletState string

type Color

type Color interface {
	Sprint(a ...interface{}) string
}

type LabelFunc

type LabelFunc func(progress, total int) string

type Step

type Step struct {
	Bullet Bullet

	Name string

	Bar string
	// contains filtered or unexported fields
}

Step represents a single step It is formatted as `$Bullet $Name $Bar` with appropriate spacing

Example
package main

import (
	"fmt"

	"github.com/julz/prettyprogress/ui"
)

func main() {
	fmt.Printf("%s", ui.Step{
		Bullet: ui.Downloading,
		Name:   "Downloading..",
		Bar:    "[██   ]",
	})

}
Output:

↡  Downloading..   [██   ]

func (Step) AnimatedString

func (s Step) AnimatedString(frame int) string

AnimatedString returns the Step's string output for a given frame

func (Step) String

func (s Step) String() string

String outputs the Step as a nicely formatted String

type Steps

type Steps []Step

Steps is a series of steps neccesary to complete the task

func (Steps) AnimatedString

func (p Steps) AnimatedString(frame int) string

AnimatedString outputs the steps as a nicely formatted string with the given frame of any bullets shown

func (Steps) String

func (p Steps) String() string

String outputs the set of steps as a nicely formatted String

Jump to

Keyboard shortcuts

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