-
Notifications
You must be signed in to change notification settings - Fork 1
/
clearscr.go
62 lines (57 loc) · 1.59 KB
/
clearscr.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
/*
*****************************************************
* © 2019 Stefano Peris <xenonlab.develop@gmail.com> *
*****************************************************
*
* Released under the GNU/GPL 3.0 license
*
* github: <https://github.com/XenonLab-Studio/GoZork>
*
*
* :'######::::'#######::'########::'#######::'########::'##:::'##:
* ##... ##::'##.... ##:..... ##::'##.... ##: ##.... ##: ##::'##::
* ##:::..::: ##:::: ##::::: ##::: ##:::: ##: ##:::: ##: ##:'##:::
* ##::'####: ##:::: ##:::: ##:::: ##:::: ##: ########:: #####::::
* ##::: ##:: ##:::: ##::: ##::::: ##:::: ##: ##.. ##::: ##. ##:::
* ##::: ##:: ##:::: ##:: ##:::::: ##:::: ##: ##::. ##:: ##:. ##::
* . ######:::. #######:: ########:. #######:: ##:::. ##: ##::. ##:
* :......:::::.......:::........:::.......:::..:::::..::..::::..::
*
* Textual adventure written in golang inspired by "Zork I"
*/
package main
import (
"os"
"os/exec"
"runtime"
)
// Create a map for storing clear funcs
var clear map[string]func()
func init() {
// Initialize it
clear = make(map[string]func())
clear["linux"] = func() {
// Linux example
cmd := exec.Command("clear")
cmd.Stdout = os.Stdout
cmd.Run()
}
clear["windows"] = func() {
// Windows
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
}
}
func CallClear() {
// runtime.GOOS -> linux, windows, darwin etc.
value, ok := clear[runtime.GOOS]
// if we defined a clear func for that platform:
if ok {
// we execute it
value()
} else {
// unsupported platform
panic("Your platform is unsupported! I can't clear terminal screen :(")
}
}