Skip to content

Commit

Permalink
add darwin support for verification if shell is interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
xmik committed Apr 22, 2019
1 parent e8ffbe0 commit b1ac511
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* cross compile on Linux and Darwin
* add Darwin support for verification if shell is interactive, thanks to [#2](https://github.com/ai-traders/dojo/pull/2), [@Eiffel-Alpine](https://github.com/Eiffel-Alpine)

### 0.3.1 (2019-Feb-04)

Expand Down
7 changes: 7 additions & 0 deletions os_dependent_utils_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build darwin

package main

import "syscall"

const ioctlReadTermios = syscall.TIOCGETA
7 changes: 7 additions & 0 deletions os_dependent_utils_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build linux

package main

import "syscall"

const ioctlReadTermios = syscall.TCGETS
3 changes: 1 addition & 2 deletions shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ func (bs BashShellService) RunGetOutput(cmdString string, separatePGroup bool) (
func (bs BashShellService) CheckIfInteractive() bool {
// stolen from: https://github.com/mattn/go-isatty/blob/master/isatty_linux.go
fd := os.Stdout.Fd()
const ioctlReadTermios = syscall.TCGETS

var termios syscall.Termios
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(ioctlReadTermios), uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
interactive := (err == 0)
bs.Logger.Log("debug", fmt.Sprintf("Current shell is interactive: %v", interactive))
return interactive
Expand Down

0 comments on commit b1ac511

Please sign in to comment.