提交 e0596caa 编写于 作者: Z zhaoke

Support win and mac .

上级 6e09eae9
......@@ -66,7 +66,7 @@ func GenZTFTestReport(report commDomain.ZtfReport, pathMaxWidth int,
divider := "--------------------------------"
window := shellUtils.WindowSize()
if window.Col != 0 {
divider = strings.Repeat("-", int(window.Col))
divider = strings.Repeat("-", window.Col)
}
msgFail += divider
......@@ -93,7 +93,7 @@ func GenZTFTestReport(report commDomain.ZtfReport, pathMaxWidth int,
failStr := fmt.Sprintf(fmtStr, i118Utils.Sprintf("fail_num"), report.Fail, float32(failRate))
skipStr := fmt.Sprintf(fmtStr, i118Utils.Sprintf("skip_num"), report.Skip, float32(skipRate))
if commConsts.ExecFrom == commConsts.FromCmd{
if commConsts.ExecFrom == commConsts.FromCmd {
passStr = fmt.Sprintf(fmtStr, color.New(color.FgGreen).Sprint(i118Utils.Sprintf("pass_num")), report.Pass, float32(passRate))
failStr = fmt.Sprintf(fmtStr, color.New(color.FgRed).Sprint(i118Utils.Sprintf("fail_num")), report.Fail, float32(failRate))
skipStr = fmt.Sprintf(fmtStr, color.New(color.FgYellow).Sprint(i118Utils.Sprintf("skip_num")), report.Skip, float32(skipRate))
......@@ -144,7 +144,7 @@ func appendFailedStepResult(cs commDomain.FuncResult, failedSteps *[]string) (pa
step.Id = strings.TrimRight(step.Id, ".")
status := i118Utils.Sprintf(string(step.Status))
if commConsts.ExecFrom == commConsts.FromCmd{
if commConsts.ExecFrom == commConsts.FromCmd {
if step.Status == commConsts.FAIL {
status = color.New(color.FgRed).Sprint(status)
} else if step.Status == commConsts.PASS {
......
//go:build darwin
// +build darwin
package shellUtils
import (
"runtime"
"syscall"
"unsafe"
)
type window struct {
Row uint16
Col uint16
Row int
Col int
}
func WindowSize() window {
win := window{0, 0}
tio := syscall.TIOCGWINSZ_OSX
res, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(syscall.TIOCGWINSZ), //此参数,不同的操作系统可能不一样,例如:TIOCGWINSZ_OSX
uintptr(tio),
uintptr(unsafe.Pointer(&win)),
)
if int(res) == -1 {
......
//go:build linux
// +build linux
package shellUtils
import (
"syscall"
"unsafe"
)
type window struct {
Row int
Col int
}
func WindowSize() window {
win := window{0, 0}
tio := syscall.TIOCGWINSZ
res, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdin),
uintptr(tio),
uintptr(unsafe.Pointer(&win)),
)
if int(res) == -1 {
return window{0, 0}
}
return win
}
//go:build windows
// +build windows
package execHelper
import (
"fmt"
"os/exec"
"strings"
"syscall"
)
type window struct {
Row int
Col int
}
func WindowSize(uuid string) window {
win := window{0, 0}
cmd1 := exec.Command("cmd")
cmd1.SysProcAttr = &syscall.SysProcAttr{CmdLine: "/c mode con", HideWindow: true}
out, _ := cmd1.Output()
lines := strings.Split(string(out), "\n")
for index, line := range lines {
if win.Row > 0 && win.Col > 0 {
return win
}
line = strings.TrimSpace(line)
if strings.Contain("行") || strings.Contain("Row") {
re := regexp.MustCompile(`\d+`)
rs := re.FindAllString(out.String(), -1)
win.Row, _ = strconv.Atoi(rs[1])
}
if strings.Contain("列") || strings.Contain("Col") {
re := regexp.MustCompile(`\d+`)
rs := re.FindAllString(out.String(), -1)
win.Col, _ = strconv.Atoi(rs[1])
}
}
return win
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册