forked from zsakvo/dhbooker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear.go
39 lines (35 loc) · 956 Bytes
/
clear.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
package main
import (
"os"
"os/exec"
"runtime"
)
var clearMap map[string]func() //create a map for storing clear funcs
func init() {
clearMap = make(map[string]func()) //Initialize it
clearMap["linux"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clearMap["darwin"] = func() {
cmd := exec.Command("clear") //Linux example, its tested
cmd.Stdout = os.Stdout
cmd.Run()
}
clearMap["windows"] = func() {
cmd := exec.Command("cls") //Windows example it is untested, but I think its working
cmd.Stdout = os.Stdout
cmd.Run()
}
}
//clear 清屏
func clear() {
value, ok := clearMap[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 :(")
}
return
}