/
buffer_speed.go
56 lines (53 loc) · 1.08 KB
/
buffer_speed.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
package cli
// Copyright 2016, JuanDeFu.ca. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
import (
"fmt"
"github.com/nsf/termbox-go"
"sabey.co/spoofgo/cli/draw-termbox"
"sabey.co/spoofgo/movement"
)
func BufferSpeed(
frame *Frame,
) []*draw.Buffer {
speed := movement.GetSpeed()
_, mph := frame.Options.Option_Speed_Unit.Get()
if mph {
// mp/h
speed *= movement.SPEED_KMH_TO_MPH
}
s := fmt.Sprintf("%.2f", speed) // 2 precision
buff := make([]*draw.Buffer, 0, len(s)+5) // `.km/h`
for _, c := range s {
buff = append(
buff,
&draw.Buffer{
C: c,
Background: termbox.ColorBlack,
Foreground: termbox.ColorCyan,
},
)
}
if mph {
// mp/h
buff = append(
buff,
&draw.Buffer{
C: 'M',
Background: termbox.ColorBlack,
Foreground: termbox.ColorBlue,
},
)
} else {
// km/h
buff = append(
buff,
&draw.Buffer{
C: 'K',
Background: termbox.ColorBlack,
Foreground: termbox.ColorBlue,
},
)
}
return buff
}