File: log_unix.go

package info (click to toggle)
golang-github-araddon-gou 0.0~git20180509.7db4be5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 160 kB
  • sloc: makefile: 2
file content (29 lines) | stat: -rw-r--r-- 486 bytes parent folder | download | duplicates (2)
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
// +build !windows

package gou

import (
	"syscall"
	"unsafe"
)

// Determine is this process is running in a Terminal or not?
func IsTerminal() bool {
	ws := &winsize{}
	isTerm := true
	defer func() {
		if r := recover(); r != nil {
			isTerm = false
		}
	}()
	// This blows up on windows
	retCode, _, _ := syscall.Syscall(syscall.SYS_IOCTL,
		uintptr(syscall.Stdin),
		uintptr(_TIOCGWINSZ),
		uintptr(unsafe.Pointer(ws)))

	if int(retCode) == -1 {
		return false
	}
	return isTerm
}