-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.go
115 lines (93 loc) · 2.52 KB
/
functions.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* functions.go */
// functions.go contains funcs to import a json file, clear screen, and basic query navigation.
package structfmt
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
)
// Cls() will clear the cli/tui screen
func Cls() {
var clear map[string]func() //create a map for storing clear funcs
clear = make(map[string]func()) //Initialize it
clear["linux"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clear["windows"] = func() {
cmd := exec.Command("cmd", "/c", "cls") //Windows example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
if ok { //if we defined a clear func for that platform:
value() //we execute it
} else { //unsupported platform
panic("Your platform is unsupported! I can't clear terminal screen :(")
}
}
// ReturnByteValue(jsonPath string) will returns a byte[] of the json file input
func ReturnByteValue(jsonPath string) []byte {
// Import and return json file
jsonFile, err := os.Open(jsonPath)
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened", jsonPath)
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
return byteValue
}
// ReturnStartPosition(weekdayNo int) will return an int representing which day of the week it currently is.
// Inputs an int 0-6, where Sunday = 0, and 6 = Saturday
// Outputs and int equivalent to the primary key of the start of a mystery
func ReturnStartPosition(weekdayNo int) int {
var positionNo int = 0
//var weekdayNo int = int(time.Now().Weekday())
switch weekdayNo {
case 0: // Sunday
positionNo = 237
case 1: // Monday
fallthrough
case 5: // Friday
positionNo = 0
case 2: // Tuesday
fallthrough
case 6: // Saturday
positionNo = 158
case 3: // Wednesday
positionNo = 237
case 4: // Thursday
positionNo = 79
default:
positionNo = 0
}
return positionNo
}
// NextBead(accumulator int) will Return an int representing the next bead sequence position
func NextBead(accumulator int) int {
// sequential navigation
if accumulator < 315 {
// forward progress
accumulator++
} else {
// loop back to start
accumulator = 0
}
return accumulator
}
// PreviousBead(accumulator int) will Return an int representing the next bead sequence position
func PreviousBead(accumulator int) int {
// sequential navigation
if accumulator > 0 {
// forward progress
accumulator--
} else {
// loop back to end
accumulator = 315
}
return accumulator
}