-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
38 lines (31 loc) · 862 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"flag"
"log"
"time"
"github.com/esdandreu/tapioca"
"github.com/esdandreu/tapioca/progress"
)
var logger *log.Logger = log.Default()
func main() {
var notapioca bool
flag.BoolVar(¬apioca, "no-tapioca", false, "Do not use tapioca")
flag.Parse()
// Create and start the progress bar
program := tapioca.NewProgram(progress.New()).GoRun()
defer program.QuitAndWait()
if !notapioca {
// Use a logger that works together with bubbletea
defer func(l *log.Logger) { logger = l }(logger)
logger = log.New(program, "", log.LstdFlags)
}
// Do work, log and increase progress bar
for i := 0; i <= 100; i++ {
time.Sleep(10 * time.Millisecond)
logger.Println("Started ", i)
time.Sleep(10 * time.Millisecond)
logger.Println("Finished", i)
program.Send(float64(i) / 100)
}
logger.Println("Finished everything!")
}