Skip to content

Commit

Permalink
Merge pull request sirupsen#594 from sirupsen/sys_unix
Browse files Browse the repository at this point in the history
Use x/sys/unix instead of syscall
  • Loading branch information
Damien Mathieu authored Jul 26, 2017
2 parents 3114d6f + 8a90bf3 commit 259b4b7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ env:
install:
- go get github.com/stretchr/testify/assert
- go get gopkg.in/gemnasium/logrus-airbrake-hook.v2
- go get golang.org/x/sys/unix
- go get golang.org/x/sys/windows
script:
- go test -race -v ./...
6 changes: 3 additions & 3 deletions terminal_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

package logrus

import "syscall"
import "golang.org/x/sys/unix"

const ioctlReadTermios = syscall.TIOCGETA
const ioctlReadTermios = unix.TIOCGETA

type Termios syscall.Termios
type Termios unix.Termios
6 changes: 3 additions & 3 deletions terminal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

package logrus

import "syscall"
import "golang.org/x/sys/unix"

const ioctlReadTermios = syscall.TCGETS
const ioctlReadTermios = unix.TCGETS

type Termios syscall.Termios
type Termios unix.Termios
5 changes: 3 additions & 2 deletions terminal_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ package logrus
import (
"io"
"os"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
)

// IsTerminal returns true if stderr's file descriptor is a terminal.
func IsTerminal(f io.Writer) bool {
var termios Termios
switch v := f.(type) {
case *os.File:
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
_, _, err := unix.Syscall6(unix.SYS_IOCTL, uintptr(v.Fd()), ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
return err == 0
default:
return false
Expand Down
11 changes: 6 additions & 5 deletions terminal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"os/exec"
"strconv"
"strings"
"syscall"
"unsafe"

"golang.org/x/sys/windows"
)

var kernel32 = syscall.NewLazyDLL("kernel32.dll")
var kernel32 = windows.NewLazyDLL("kernel32.dll")

var (
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
Expand All @@ -41,7 +42,7 @@ func getVersion() (float64, error) {
if err != nil {
return -1, err
}

// The output should be like "Microsoft Windows [Version XX.X.XXXXXX]"
version := strings.Replace(stdout.String(), "\n", "", -1)
version = strings.Replace(version, "\r\n", "", -1)
Expand All @@ -64,7 +65,7 @@ func init() {
// Activate Virtual Processing for Windows CMD
// Info: https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
if ver >= 10 {
handle := syscall.Handle(os.Stderr.Fd())
handle := windows.Handle(os.Stderr.Fd())
procSetConsoleMode.Call(uintptr(handle), enableProcessedOutput|enableWrapAtEolOutput|enableVirtualTerminalProcessing)
}
}
Expand All @@ -74,7 +75,7 @@ func IsTerminal(f io.Writer) bool {
switch v := f.(type) {
case *os.File:
var st uint32
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(v.Fd()), uintptr(unsafe.Pointer(&st)), 0)
r, _, e := windows.Syscall(procGetConsoleMode.Addr(), 2, uintptr(v.Fd()), uintptr(unsafe.Pointer(&st)), 0)
return r != 0 && e == 0
default:
return false
Expand Down

0 comments on commit 259b4b7

Please sign in to comment.