Skip to content

Commit

Permalink
Fix for windows building (#42)
Browse files Browse the repository at this point in the history
This PR contains the fixes for building on windows
  • Loading branch information
ericfialkowski committed Jan 25, 2022
1 parent b630d37 commit a73545a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
.idea
18 changes: 0 additions & 18 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ package goterm
import (
"bufio"
"bytes"
"errors"
"fmt"
"math"
"os"
"strings"

"golang.org/x/sys/unix"
)

// Reset all custom styles
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions terminal_nosysioctl.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build plan9 || solaris
// +build plan9 solaris

package goterm
Expand All @@ -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)
}
17 changes: 17 additions & 0 deletions terminal_sysioctl.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//go:build !windows && !plan9 && !solaris
// +build !windows,!plan9,!solaris

package goterm

import (
"errors"
"math"
"os"

"golang.org/x/sys/unix"
Expand All @@ -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)
}
17 changes: 17 additions & 0 deletions terminal_windows.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//go:build windows
// +build windows

package goterm

import (
"errors"
"math"
"os"

"golang.org/x/sys/windows"
Expand All @@ -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)
}

0 comments on commit a73545a

Please sign in to comment.