-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.go
63 lines (53 loc) · 1.67 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"os"
"runtime"
"unicode"
"github.com/fatih/color"
)
var (
version = "1.2"
logo = `
██╗ ██╗██████╗ █████╗ ██████╗
╚██╗ ██╔╝██╔══██╗██╔══██╗██╔═══██╗
╚████╔╝ ██║ ██║███████║██║ ██║
╚██╔╝ ██║ ██║██╔══██║██║ ██║
██║ ██████╔╝██║ ██║╚██████╔╝
╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝
ydao V%s 好好学学英语吧...
`
)
func displayUsage() {
logo = fmt.Sprintf(logo, version)
color.Cyan(logo)
color.Cyan("Usage:")
color.Cyan("ydao <option> <word> Query the word(s)")
color.Cyan("ydao -v <word(s) to query> Query with speech")
color.Cyan("ydao -m <word(s) to query> Query with more example phrases and sentences")
color.Cyan("ydao -w <word(s) to query> Query and open browser to get detail")
color.Cyan("ydao -list List query word histor")
color.Cyan("ydao -clean Clean query word histor")
color.Cyan("ydao -dump Dump query word histor")
}
func isChinese(str string) bool {
for _, r := range str {
if unicode.Is(unicode.Scripts["Han"], r) {
return true
}
}
return false
}
func isAvailablesOS() bool {
return runtime.GOOS == "darwin" || runtime.GOOS == "linux"
}
func userHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}
return os.Getenv("HOME")
}