-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.go
83 lines (74 loc) · 1.87 KB
/
init.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
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
)
func init() {
resize = make(map[string]func())
resize["darwin"] = func() {
cmd := exec.Command("resize -s 35 120")
cmd.Stdout = os.Stdout
cmd.Run()
}
resize["linux"] = func() {
cmd := exec.Command("resize -s 35 120")
cmd.Stdout = os.Stdout
cmd.Run()
}
resize["windows"] = func() {
cmd := exec.Command("cmd", "/c", "mode con:cols=80 lines=30") //Windows example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clear = make(map[string]func()) //Initialize it
clear["darwin"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
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()
}
logpath := filepath.Join(".", "logs")
if _, err := os.Stat(logpath); os.IsNotExist(err) {
os.MkdirAll(logpath, os.ModePerm)
}
jobpath := filepath.Join(".", "jobs")
if _, err := os.Stat(jobpath); os.IsNotExist(err) {
os.MkdirAll(jobpath, os.ModePerm)
}
}
func checkErr(err error) {
if err != nil {
// log.Fatalln(err)
log.Println(err)
}
}
func CallClear() {
value, ok := clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
//if we defined a clear func for that platform:
if ok {
value() //we execute it
} else {
panic("Your platform is unsupported! I can't clear terminal screen :(") //unsupported platform
}
}
func ResizeWindow() {
value, ok := resize[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
//if we defined a clear func for that platform:
if ok {
value() //we execute it
} else {
panic("Your platform is unsupported! I can't resize terminal screen :(") //unsupported platform
}
}