Documentation ¶
Overview ¶
Package progress is a small library for creating a progress bar in slack
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMaxPosExceeded is returned when the position passed to Progress.Update // is greater than Progress.Total or DefaultTotal if Progress.Total is 0. ErrMaxPosExceeded = errors.New("Maximum position exceeded") // ErrNegativePos is returned when a negative value is passed to Progress.Update. // All positions should be >= 0. ErrNegativePos = errors.New("Invalid position") )
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { Fill string // The character(s) used to fill in the progress bar Empty string // The character(s) used to indicate empty space at the end of progress bar Width int // How many characters wide the progress bar should be. A value of 10 looks good on slack phone clients. TotalUnits int // Total possible units. Graph will always display 0-100%. Msg string // The message template that will be sent to slack. Uses text/template for creating templates. Task string // Name of the task we are showing progress for. AsUser bool // Whether or not to post as the user. If false posts as a generic bot and doesn't show edited next to messages. If true the opposite of both is true. Defaults to false. ShowEstTime bool // Whether or not to show estimated time remaining }
Options can be used to customize look of the progress bar. DefaultOptions() has pretty good defaults.
func DefaultOptions ¶
DefaultOptions creates an Options struct with decent defaults.
type Progress ¶
type Progress struct { Opts *Options Start time.Time // When the task began running. Initialized to current time when New() is called. // contains filtered or unexported fields }
Progress is a struct that creates the progress bar in slack
Example ¶
package main import ( "log" "github.com/sfreiberg/progress" ) func main() { token := "super-secret-slack-token" channel := "demo" pbar := progress.New(token, channel, nil) for i := 0; i <= pbar.Opts.TotalUnits; i++ { if err := pbar.Update(i); err != nil { log.Printf("Error updating progress bar: %s\n", err) } } }
Output:
func New ¶
New creates a new progress bar. If opts is nil then Progress will be created with DefaultOptions. The timer that is used for calculating time remaining is based on when this is instantiated so if it's not called around the time the task begins running it might report inaccurate results. You can fix this by setting Progress.Start manually.
Click to show internal directories.
Click to hide internal directories.