diff --git a/Gopkg.lock b/Gopkg.lock index 2fe44c0..51b3d8a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -148,6 +148,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "4829f6ece92cbe976f47abc5c0533a70458ebd2b377c8554bc00b1c915456148" + inputs-digest = "43503937d375a0d8b471fd96e4188dbd900c48649b5e598de86c2774250df6c4" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 667bfe6..a00c04f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -53,10 +53,6 @@ branch = "master" name = "github.com/texttheater/golang-levenshtein" -[[constraint]] - branch = "master" - name = "golang.org/x/sys" - [prune] go-tests = true unused-packages = true diff --git a/core/core.go b/core/core.go index a76b97b..4fee3a6 100644 --- a/core/core.go +++ b/core/core.go @@ -17,7 +17,6 @@ import ( "github.com/HeavyWombat/yaml" "github.com/mitchellh/hashstructure" "github.com/texttheater/golang-levenshtein/levenshtein" - "golang.org/x/sys/unix" ) // Debug log output @@ -132,23 +131,6 @@ func Plural(amount int, text ...string) string { } } -// GetTerminalSize return the current terminal size with width and height (columns and rows) -func GetTerminalSize() (int, int) { - bounds, err := unix.IoctlGetWinsize(0, unix.TIOCGWINSZ) - if err != nil { - // TODO Add debug output that default terminal sizings were returned due to an error - return 80, 25 - } - - return int(bounds.Col), int(bounds.Row) -} - -// GetTerminalWidth return the current terminal width -func GetTerminalWidth() int { - width, _ := GetTerminalSize() - return width -} - func colorEachLine(color *color.Color, text string) string { var buf bytes.Buffer diff --git a/core/terminal_unix.go b/core/terminal_unix.go new file mode 100644 index 0000000..29b9bc9 --- /dev/null +++ b/core/terminal_unix.go @@ -0,0 +1,33 @@ +// +build !windows + +package core + +import ( + "syscall" + "unsafe" +) + +// GetTerminalWidth return the current terminal width +func GetTerminalWidth() int { + const defaultWidth = 80 + + type winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 + } + + ws := &winsize{} + retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL, + uintptr(syscall.Stdin), + uintptr(syscall.TIOCGWINSZ), + uintptr(unsafe.Pointer(ws))) + + if int(retCode) == -1 { + // TODO Add debug output that default terminal sizings were returned due + return defaultWidth + } + + return int(ws.Col) +} diff --git a/core/terminal_windows.go b/core/terminal_windows.go new file mode 100644 index 0000000..df3911f --- /dev/null +++ b/core/terminal_windows.go @@ -0,0 +1,9 @@ +// +build windows + +package core + +// GetTerminalWidth return the current terminal width +func GetTerminalWidth() int { + // TODO Implement Windows terminal width if this is possible at all. + return 80 +}