-
Notifications
You must be signed in to change notification settings - Fork 4
/
runner.go
56 lines (45 loc) · 976 Bytes
/
runner.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// The runner is the primary process of the tool
package runner
import (
"fmt"
"os"
"time"
"github.com/Brum3ns/encode/pkg/config"
)
type Runner struct {
conf *config.Configure
}
func NewRunner(conf *config.Configure) error {
runner := &Runner{
conf: conf,
}
total := len(runner.conf.Option.Stdin)
jobs := make(chan string)
results := make(chan string, total)
for t := 0; t <= runner.conf.Option.Threads; t++ {
go runner.worker(jobs, results)
}
//Give job to workers
runner.job(jobs)
//Super cool loading bar ^-^
if total > 10000 {
go loadingbar()
}
//Listener
for i := 0; i < len(runner.conf.Option.Stdin); i++ {
fmt.Println(<-results)
}
close(jobs)
close(results)
return nil
}
func loadingbar() {
l := []string{"⠁", "⠃", "⠇", "⠧", "⠷", "⠿", "⠾", "⠼", "⠸", "⠘", "⠈", "⠉"}
for i := 0; true; i++ {
if i >= len(l) {
i = 0
}
fmt.Fprint(os.Stderr, (l[i] + "\r"))
time.Sleep(42 * time.Millisecond)
}
}