summaryrefslogtreecommitdiff
path: root/winsize.go
diff options
context:
space:
mode:
authorÖzgür Kesim <oec@codeblau.de>2015-07-28 17:12:26 +0200
committerÖzgür Kesim <oec@codeblau.de>2015-07-28 17:12:26 +0200
commitf251231590b188681b33705feaf5156d88f09197 (patch)
tree51aad5b3f49ba4f8d96b5fc145bc0b17e4cd0384 /winsize.go
parent539175e63919c55c083a0bff3f59ced050bdf6f1 (diff)
added sysctl for terminal-width retrieval
Diffstat (limited to 'winsize.go')
-rw-r--r--winsize.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/winsize.go b/winsize.go
new file mode 100644
index 0000000..1a3bdaf
--- /dev/null
+++ b/winsize.go
@@ -0,0 +1,29 @@
+package main
+
+// +build linux
+
+import (
+ "syscall"
+ "unsafe"
+)
+
+type winsize struct {
+ Row uint16
+ Col uint16
+ Xpixel uint16
+ Ypixel uint16
+}
+
+func init() {
+ ws := &winsize{}
+ retCode, _, errno := syscall.Syscall(syscall.SYS_IOCTL,
+ uintptr(syscall.Stdin),
+ uintptr(syscall.TIOCGWINSZ),
+ uintptr(unsafe.Pointer(ws)))
+
+ if int(retCode) == -1 {
+ panic(errno)
+ }
+
+ Width = int(ws.Col)
+}