started new logger output
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Sebastian Frank
2019-03-27 13:52:22 +01:00
parent 5d6d03702e
commit 7695f42e20
4 changed files with 58 additions and 28 deletions

View File

@@ -2,8 +2,10 @@ package progress
import (
"fmt"
"time"
"gitbase.de/apairon/mark2web/pkg/helper"
"gitbase.de/apairon/mark2web/pkg/logger"
"github.com/gosuri/uiprogress"
"github.com/mattn/go-tty"
)
@@ -23,8 +25,12 @@ var OverallTotal = 0
// OverallDone is number of done jobs
var OverallDone = 0
// Init initializes the bar drawing
func Init() {
func init() {
updateLoggerPrefix()
}
// Start initializes the bar drawing
func Start() {
if t, err := tty.Open(); err == nil && t != nil {
terminalWidth, _, _ = t.Size()
t.Close()
@@ -33,9 +39,15 @@ func Init() {
initialized = true
}
func updateLoggerPrefix() {
logger.Prefix = fmt.Sprintf("%3d/%3d: ", OverallDone, OverallTotal)
}
// IncrTotal increases the total jobs for the bar
func IncrTotal(barname string) {
OverallTotal++
updateLoggerPrefix()
if initialized {
_bar := bars[barname]
if _bar == nil {
@@ -60,6 +72,8 @@ func IncrTotal(barname string) {
// IncrDone increases to done jobs counter
func IncrDone(barname string) {
OverallDone++
updateLoggerPrefix()
if initialized {
bars[barname].Bar.Incr()
bars[barname].Description = ""
@@ -72,3 +86,11 @@ func DescribeCurrent(barname, description string) {
bars[barname].Description = description
}
}
// Stop stops the bar drawing
func Stop() {
if initialized {
time.Sleep(time.Millisecond * 200)
uiprogress.Stop()
}
}