diff --git a/builtin/gen_gcli_command.go b/builtin/gen_gcli_command.go index 77a2f1b..7e8cc96 100644 --- a/builtin/gen_gcli_command.go +++ b/builtin/gen_gcli_command.go @@ -2,8 +2,8 @@ package builtin import "github.com/gookit/gcli/v3" -// GenGcliCmdCode command -var GenGcliCmdCode = &gcli.Command{ +// GenCmdCode command +var GenCmdCode = &gcli.Command{ Name: "gen-cmd", Desc: "quick generate gcli command code", } diff --git a/builtin/genac/gen_bash.go b/builtin/genac/gen_bash.go new file mode 100644 index 0000000..6784853 --- /dev/null +++ b/builtin/genac/gen_bash.go @@ -0,0 +1 @@ +package genac diff --git a/builtin/genac/gen_zsh.go b/builtin/genac/gen_zsh.go new file mode 100644 index 0000000..6784853 --- /dev/null +++ b/builtin/genac/gen_zsh.go @@ -0,0 +1 @@ +package genac diff --git a/builtin/genac/genac.go b/builtin/genac/genac.go new file mode 100644 index 0000000..6784853 --- /dev/null +++ b/builtin/genac/genac.go @@ -0,0 +1 @@ +package genac diff --git a/helper/utils.go b/helper/utils.go index beebfd2..333529e 100644 --- a/helper/utils.go +++ b/helper/utils.go @@ -5,9 +5,11 @@ import ( "fmt" "regexp" "strings" + "syscall" "text/template" "github.com/gookit/goutil/strutil" + "golang.org/x/term" ) const ( @@ -60,6 +62,23 @@ var ( // linuxSttyMsgMatch = regexp.MustCompile(linuxSttyMsgPattern) ) +// GetTerminalSize for current console terminal. +func GetTerminalSize(refresh ...bool) (w int, h int) { + if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] { + return terminalWidth, terminalHeight + } + + var err error + w, h, err = term.GetSize(syscall.Stdin) + if err != nil { + return + } + + // cache result + terminalWidth, terminalHeight = w, h + return +} + // Panicf message func Panicf(format string, v ...any) { panic(fmt.Sprintf("GCli: "+format, v...)) diff --git a/helper/utils_nonwin.go b/helper/utils_nonwin.go index eff9b86..9a3d43f 100644 --- a/helper/utils_nonwin.go +++ b/helper/utils_nonwin.go @@ -1,26 +1,3 @@ -// +build !windows +//go:build !windows package helper - -import ( - "syscall" - - "golang.org/x/crypto/ssh/terminal" -) - -// GetTerminalSize for current console terminal. -func GetTerminalSize(refresh ...bool) (w int, h int) { - if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] { - return terminalWidth, terminalHeight - } - - var err error - w, h, err = terminal.GetSize(syscall.Stdin) - if err != nil { - return - } - - // cache result - terminalWidth, terminalHeight = w, h - return -} diff --git a/helper/utils_windows.go b/helper/utils_windows.go index 8202f92..947317d 100644 --- a/helper/utils_windows.go +++ b/helper/utils_windows.go @@ -1,24 +1 @@ package helper - -import ( - "syscall" - - "golang.org/x/crypto/ssh/terminal" -) - -// GetTerminalSize for current console terminal. -func GetTerminalSize(refresh ...bool) (w int, h int) { - if terminalWidth > 0 && len(refresh) > 0 && !refresh[0] { - return terminalWidth, terminalHeight - } - - var err error - w, h, err = terminal.GetSize(int(syscall.Stdin)) - if err != nil { - return - } - - // cache result - terminalWidth, terminalHeight = w, h - return -}