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