-
Notifications
You must be signed in to change notification settings - Fork 10
/
clear.go
40 lines (34 loc) · 877 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
40
package commands
import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"github.com/AbGuthrie/goquery/v2/config"
"github.com/AbGuthrie/goquery/v2/models"
prompt "github.com/c-bata/go-prompt"
)
func clear(api models.GoQueryAPI, config *config.Config, cmdline string) error {
args := strings.Split(cmdline, " ") // Separate command and arguments
if len(args) > 1 {
return fmt.Errorf("This command takes no parameters")
}
// TODO: it may make more sense for the os runtime to be set and retrieved
// via the config/state.go module
currentOS := runtime.GOOS
if currentOS == "windows" {
cmd := exec.Command("cmd", "/c", "cls")
cmd.Stdout = os.Stdout
cmd.Run()
} else {
print("\033[H\033[2J")
}
return nil
}
func clearHelp() string {
return "Clear the terminal screen"
}
func clearSuggest(cmdline string) []prompt.Suggest {
return []prompt.Suggest{}
}