-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.go
98 lines (86 loc) · 1.75 KB
/
util.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"image"
"time"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/private/canvas"
"github.com/mum4k/termdash/private/canvas/buffer"
)
func clamp(value int, min int, max int) int {
if value < min {
return min
} else if value > max {
return max
}
return value
}
func valmap(x, in_min, in_max, out_min, out_max int) int {
return (x-in_min)*(out_max-out_min)/(in_max-in_min) + out_min
}
// TODO: alias time.Duration to our own type, and make this the String() function for that type
func Timestamp(t *time.Duration) string {
return fmt.Sprintf("%02d:%02d:%02d.%03d", int32(t.Hours()), int32(t.Minutes())%60, int32(t.Seconds())%60, t.Milliseconds()%1000)
}
func DrawCells(cvs *canvas.Canvas, cells []*buffer.Cell, x, y int) {
for i, c := range cells {
cvs.SetCell(image.Point{
X: x + i,
Y: y,
}, c.Rune, c.Opts)
}
}
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func markdownFontModifiers(cells []*buffer.Cell) []*buffer.Cell {
var mdcells []*buffer.Cell
mode := 0
stars := 0
for _, c := range cells {
if c.Rune == '`' {
if mode == 0 {
mode = 3
} else {
mode = 0
}
continue
} else if c.Rune == '*' {
stars++
continue
} else {
if mode == 0 {
mode = stars
} else if stars == mode {
mode = 0
}
stars = 0
}
if mode == 1 {
c.Opts.Italic = true
} else if mode == 2 {
c.Opts.Bold = true
} else if mode == 3 {
c.Opts.Bold = true
c.Opts.FgColor = cell.ColorNumber(57)
}
mdcells = append(mdcells, c)
}
return mdcells
}
func indexOfMaxInt32(arr []int32) int {
var idx int
var m int32
for i, e := range arr {
if i == 0 || e > m {
idx = i
m = e
}
}
return idx
}