Skip to content

Commit

Permalink
up: builtin, helper - update some helper util func
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 2, 2022
1 parent 189e253 commit 02e21bc
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 49 deletions.
4 changes: 2 additions & 2 deletions builtin/gen_gcli_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
1 change: 1 addition & 0 deletions builtin/genac/gen_bash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package genac
1 change: 1 addition & 0 deletions builtin/genac/gen_zsh.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package genac
1 change: 1 addition & 0 deletions builtin/genac/genac.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package genac
19 changes: 19 additions & 0 deletions helper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"fmt"
"regexp"
"strings"
"syscall"
"text/template"

"github.com/gookit/goutil/strutil"
"golang.org/x/term"
)

const (
Expand Down Expand Up @@ -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...))
Expand Down
25 changes: 1 addition & 24 deletions helper/utils_nonwin.go
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 0 additions & 23 deletions helper/utils_windows.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 02e21bc

Please sign in to comment.