forked from olekukonko/ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ts_x.go
46 lines (36 loc) · 959 Bytes
/
ts_x.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// +build !windows,!solaris,!aix
// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
// This module is a Terminal API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems
package ts
import (
"syscall"
"unsafe"
)
// Get Windows Size
func GetSize() (ws Size, err error) {
_, _, ec := syscall.Syscall(syscall.SYS_IOCTL,
uintptr(syscall.Stdout),
uintptr(TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)))
err = getError(ec)
if TIOCGWINSZ == 0 && err != nil {
ws = Size{80, 25, 0, 0}
}
return ws, err
}
func getError(ec interface{}) (err error) {
switch v := ec.(type) {
case syscall.Errno: // Some implementation return syscall.Errno number
if v != 0 {
err = syscall.Errno(v)
}
case error: // Some implementation return error
err = ec.(error)
default:
err = nil
}
return
}