Skip to content

Commit f553db7

Browse files
committed
fix complie error on windows
1 parent 6bf8afc commit f553db7

11 files changed

+140
-49
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ dist: xenial
33
go:
44
- '1.11'
55
- '1.12'
6+
- '1.13'
7+
- '1.14'
68

79
#env:
810
# - GO111MODULE=on

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
################################################################################
66
### builder image
77
################################################################################
8-
FROM golang:1.13-alpine as Builder
8+
FROM golang:1.14-alpine as Builder
99

1010
# Recompile the standard library without CGO
1111
#RUN CGO_ENABLED=0 go install -a std

Makefile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# link https://github.com/humbug/box/blob/master/Makefile
2+
#SHELL = /bin/sh
3+
.DEFAULT_GOAL := help
4+
# 每行命令之前必须有一个tab键。如果想用其他键,可以用内置变量.RECIPEPREFIX 声明
5+
# mac 下这条声明 没起作用 !!
6+
.RECIPEPREFIX = >
7+
.PHONY: all usage help clean
8+
9+
# 需要注意的是,每行命令在一个单独的shell中执行。这些Shell之间没有继承关系。
10+
# - 解决办法是将两行命令写在一行,中间用分号分隔。
11+
# - 或者在换行符前加反斜杠转义 \
12+
13+
# 接收命令行传入参数 make COMMAND tag=v2.0.4
14+
# TAG=$(tag)
15+
16+
##there some make command for the project
17+
##
18+
19+
help:
20+
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | sed -e 's/: / /'
21+
22+
##Available Commands:
23+
24+
clean: ## Clean all created artifacts
25+
clean:
26+
git clean --exclude=.idea/ -fdx
27+
28+
cs-fix: ## Fix code style for all files
29+
cs-fix:
30+
gofmt -w ./
31+
32+
cs-diff: ## Display code style error files
33+
cs-diff:
34+
gofmt -l ./

_examples/cmd/interact_demo.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ func demoSelect(_ *gcli.Command) {
8282
[]string{"chengdu", "beijing", "shanghai"},
8383
"",
8484
)
85-
color.Comment.Println("your select is: ", ans)
85+
color.Comment.Println("your select is:", ans)
8686
fmt.Println("----------------------------------------------------------")
8787

8888
ans1 := interact.Choice(
8989
"Your age(use int array)?",
9090
[]int{23, 34, 45},
9191
"",
9292
)
93-
color.Comment.Println("your select is: ", ans1)
93+
color.Comment.Println("your select is:", ans1)
9494

9595
fmt.Println("----------------------------------------------------------")
9696

@@ -99,7 +99,7 @@ func demoSelect(_ *gcli.Command) {
9999
map[string]string{"a": "chengdu", "b": "beijing", "c": "shanghai"},
100100
"a",
101101
)
102-
color.Comment.Println("your select is: ", ans2)
102+
color.Comment.Println("your select is:", ans2)
103103
}
104104

105105
func demoMultiSelect(_ *gcli.Command) {
@@ -118,7 +118,7 @@ func demoMultiSelect(_ *gcli.Command) {
118118
map[string]string{"a": "chengdu", "b": "beijing", "c": "shanghai"},
119119
[]string{"a"},
120120
)
121-
color.Comment.Println("your select is: ", ans2)
121+
color.Comment.Println("your select is:", ans2)
122122
}
123123

124124
func demoConfirm(_ *gcli.Command) {
@@ -139,7 +139,7 @@ func demoPassword(_ *gcli.Command) {
139139
// color.Comment.Println("you input password is: ", pwd)
140140

141141
pwd := interact.ReadPassword()
142-
color.Comment.Println("Your input password is: ", pwd)
142+
color.Comment.Println("Your input password is:", pwd)
143143
}
144144

145145
func hiddenInputTest() {
@@ -163,5 +163,5 @@ func demoAnswerIsYes(_ *gcli.Command) {
163163

164164
func demoQuestion(_ *gcli.Command) {
165165
ans := interact.Ask("Your name? ", "", nil, 3)
166-
color.Comment.Println("Your answer is: ", ans)
166+
color.Comment.Println("Your answer is:", ans)
167167
}

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ go 1.11
44

55
require (
66
github.com/fsnotify/fsnotify v1.4.7
7-
github.com/gookit/color v1.2.0
8-
github.com/gookit/filter v1.0.10
9-
github.com/gookit/goutil v0.2.4
10-
github.com/json-iterator/go v1.1.9 // indirect
7+
github.com/gookit/color v1.2.5
8+
github.com/gookit/goutil v0.2.7
119
github.com/stretchr/testify v1.4.0
1210
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
1311
)

helper/utils.go

-19
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ package helper
33
import (
44
"bytes"
55
"strings"
6-
"syscall"
76
"text/template"
87

98
"github.com/gookit/goutil/strutil"
10-
"golang.org/x/crypto/ssh/terminal"
119
)
1210

1311
// exec: `stty -a 2>&1`
@@ -25,23 +23,6 @@ var (
2523
// linuxSttyMsgMatch = regexp.MustCompile(linuxSttyMsgPattern)
2624
)
2725

28-
// GetTerminalSize for current console terminal.
29-
func GetTerminalSize(refresh ...bool) (w int, h int) {
30-
if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] {
31-
return terminalWidth, terminalHeight
32-
}
33-
34-
var err error
35-
w, h, err = terminal.GetSize(syscall.Stdin)
36-
if err != nil {
37-
return
38-
}
39-
40-
// cache result
41-
terminalWidth, terminalHeight = w, h
42-
return
43-
}
44-
4526
// RenderText render text template with data
4627
func RenderText(input string, data interface{}, fns template.FuncMap, isFile ...bool) string {
4728
t := template.New("cli")

helper/utils_nonwin.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//+build !windows
2+
3+
package helper
4+
5+
import (
6+
"syscall"
7+
8+
"golang.org/x/crypto/ssh/terminal"
9+
)
10+
11+
// GetTerminalSize for current console terminal.
12+
func GetTerminalSize(refresh ...bool) (w int, h int) {
13+
if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] {
14+
return terminalWidth, terminalHeight
15+
}
16+
17+
var err error
18+
w, h, err = terminal.GetSize(syscall.Stdin)
19+
if err != nil {
20+
return
21+
}
22+
23+
// cache result
24+
terminalWidth, terminalHeight = w, h
25+
return
26+
}

helper/utils_windows.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package helper
2+
3+
import (
4+
"syscall"
5+
6+
"golang.org/x/crypto/ssh/terminal"
7+
)
8+
9+
// GetTerminalSize for current console terminal.
10+
func GetTerminalSize(refresh ...bool) (w int, h int) {
11+
if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] {
12+
return terminalWidth, terminalHeight
13+
}
14+
15+
var err error
16+
w, h, err = terminal.GetSize(int(syscall.Stdin))
17+
if err != nil {
18+
return
19+
}
20+
21+
// cache result
22+
terminalWidth, terminalHeight = w, h
23+
return
24+
}

interact/read.go

-19
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66
"io/ioutil"
77
"os"
88
"strings"
9-
"syscall"
109

1110
"github.com/gookit/color"
1211
"github.com/gookit/goutil/cliutil"
1312
"github.com/gookit/goutil/envutil"
14-
"golang.org/x/crypto/ssh/terminal"
1513
)
1614

1715
// ReadInput read user input form Stdin
@@ -93,23 +91,6 @@ func AnswerIsYes(defVal ...bool) bool {
9391
return AnswerIsYes()
9492
}
9593

96-
// ReadPassword from terminal
97-
func ReadPassword(message ...string) string {
98-
if len(message) > 0 {
99-
print(message[0])
100-
} else {
101-
print("Enter Password: ")
102-
}
103-
104-
bs, err := terminal.ReadPassword(syscall.Stdin)
105-
if err != nil {
106-
return ""
107-
}
108-
109-
println() // new line
110-
return string(bs)
111-
}
112-
11394
// GetHiddenInput interactively prompts for input without echoing to the terminal.
11495
// Usage:
11596
// // askPassword

interact/read_nonwin.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//+build !windows
2+
3+
package interact
4+
5+
// ReadPassword from terminal
6+
func ReadPassword(question ...string) string {
7+
if len(question) > 0 {
8+
print(question[0])
9+
} else {
10+
print("Enter Password: ")
11+
}
12+
13+
bs, err := terminal.ReadPassword(syscall.Stdin)
14+
if err != nil {
15+
return ""
16+
}
17+
18+
println() // new line
19+
return string(bs)
20+
}

interact/read_windows.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package interact
2+
3+
import (
4+
"syscall"
5+
6+
"golang.org/x/crypto/ssh/terminal"
7+
)
8+
9+
// ReadPassword from terminal
10+
func ReadPassword(question ...string) string {
11+
if len(question) > 0 {
12+
print(question[0])
13+
} else {
14+
print("Enter Password: ")
15+
}
16+
17+
// on windows, must convert 'syscall.Stdin' to int
18+
bs, err := terminal.ReadPassword(int(syscall.Stdin))
19+
if err != nil {
20+
return ""
21+
}
22+
23+
println() // new line
24+
return string(bs)
25+
}

0 commit comments

Comments
 (0)