-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed code to detect terminal width to be more operating system independent.
- Loading branch information
1 parent
23ffbfa
commit a9456ae
Showing
5 changed files
with
43 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |