diff --git a/.gitignore b/.gitignore index 1377554..986544f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +.idea \ No newline at end of file diff --git a/terminal.go b/terminal.go index 566fec8..d1e8208 100644 --- a/terminal.go +++ b/terminal.go @@ -16,13 +16,9 @@ package goterm import ( "bufio" "bytes" - "errors" "fmt" - "math" "os" "strings" - - "golang.org/x/sys/unix" ) // Reset all custom styles @@ -203,20 +199,6 @@ func Width() int { return int(ws.Col) } -// Height gets console height -func Height() int { - ws, err := getWinsize() - if err != nil { - // returns math.MinInt32 if we could not retrieve the height of console window, - // like VSCode debugging console - if errors.Is(err, unix.EOPNOTSUPP) { - return math.MinInt32 - } - return -1 - } - return int(ws.Row) -} - // CurrentHeight gets current height. Line count in Screen buffer. func CurrentHeight() int { return strings.Count(Screen.String(), "\n") diff --git a/terminal_nosysioctl.go b/terminal_nosysioctl.go index 9b988ff..f4f4d5e 100644 --- a/terminal_nosysioctl.go +++ b/terminal_nosysioctl.go @@ -1,3 +1,4 @@ +//go:build plan9 || solaris // +build plan9 solaris package goterm @@ -10,3 +11,12 @@ func getWinsize() (*winsize, error) { return ws, nil } + +// Height gets console height +func Height() int { + ws, err := getWinsize() + if err != nil { + return -1 + } + return int(ws.Row) +} diff --git a/terminal_sysioctl.go b/terminal_sysioctl.go index 33148ed..8b48b40 100644 --- a/terminal_sysioctl.go +++ b/terminal_sysioctl.go @@ -1,8 +1,11 @@ +//go:build !windows && !plan9 && !solaris // +build !windows,!plan9,!solaris package goterm import ( + "errors" + "math" "os" "golang.org/x/sys/unix" @@ -17,3 +20,17 @@ func getWinsize() (*unix.Winsize, error) { return ws, nil } + +// Height gets console height +func Height() int { + ws, err := getWinsize() + if err != nil { + // returns math.MinInt32 if we could not retrieve the height of console window, + // like VSCode debugging console + if errors.Is(err, unix.EOPNOTSUPP) { + return math.MinInt32 + } + return -1 + } + return int(ws.Row) +} diff --git a/terminal_windows.go b/terminal_windows.go index 37c56ae..e8236b6 100644 --- a/terminal_windows.go +++ b/terminal_windows.go @@ -1,8 +1,11 @@ +//go:build windows // +build windows package goterm import ( + "errors" + "math" "os" "golang.org/x/sys/windows" @@ -21,3 +24,17 @@ func getWinsize() (*winsize, error) { return ws, nil } + +// Height gets console height +func Height() int { + ws, err := getWinsize() + if err != nil { + // returns math.MinInt32 if we could not retrieve the height of console window, + // like VSCode debugging console + if errors.Is(err, windows.WSAEOPNOTSUPP) { + return math.MinInt32 + } + return -1 + } + return int(ws.Row) +}