-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
49 lines (39 loc) · 1006 Bytes
/
utils.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
package main
import (
"bufio"
"fmt"
"path"
"runtime"
"strings"
"os"
)
func colorPrintField(label, str string) {
fmt.Printf("\033[1;35m%s\033[0m: %s\n", label, str)
}
func compareStringsCaseInsensitive(a, b string) bool {
return strings.ToLower(a) == strings.ToLower(b)
}
func containsCaseInsensitive(str, substr string) bool {
return strings.Contains(strings.ToLower(str), strings.ToLower(substr))
}
func removeReturnChars(s string) string {
// Windows uses \r\n
// MacOS uses \n
s = strings.TrimSuffix(s, "\n")
s = strings.TrimSuffix(s, "\r")
return s
}
func getInput(label string) string {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s", label)
input, _ := reader.ReadString('\n')
return removeReturnChars(input)
}
func getCallDirectory() string {
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("No caller information")
}
var pathname string = path.Dir(filename)
return pathname
}