/
common.go
69 lines (60 loc) · 1.1 KB
/
common.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
57
58
59
60
61
62
63
64
65
66
67
68
69
package tableprinters
import (
"fmt"
"math"
"path/filepath"
"strings"
"time"
)
const (
dot = "●"
nbr = " "
)
func depth(path string) uint {
var count uint = 0
for p := filepath.Clean(path); p != "/"; count++ {
p = filepath.Dir(p)
}
return count
}
func humanizeDuration(duration time.Duration) string {
days := int64(duration.Hours() / 24)
hours := int64(math.Mod(duration.Hours(), 24))
minutes := int64(math.Mod(duration.Minutes(), 60))
seconds := int64(math.Mod(duration.Seconds(), 60))
chunks := []struct {
singularName string
amount int64
}{
{"d", days},
{"h", hours},
{"m", minutes},
{"s", seconds},
}
parts := []string{}
for _, chunk := range chunks {
switch chunk.amount {
case 0:
continue
default:
parts = append(parts, fmt.Sprintf("%d%s", chunk.amount, chunk.singularName))
}
}
if len(parts) == 0 {
return "0s"
}
if len(parts) > 2 {
parts = parts[:2]
}
return strings.Join(parts, " ")
}
func getMaxLineCount(ss ...string) int {
max := 0
for _, s := range ss {
c := strings.Count(s, "\n")
if c > max {
max = c
}
}
return max
}