Skip to content

Commit

Permalink
Fixing issue on Windows for cygwin terminals
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Shaw committed Mar 11, 2017
1 parent 11cea47 commit 294a8e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
14 changes: 12 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const (

// Handler is a cli input handler.
type Handler struct {
args *Args
args *Args

cygwin bool
interactive bool

u *dburl.URL
Expand Down Expand Up @@ -326,6 +328,9 @@ func (h *Handler) Run() error {
// configure input
var stdin *os.File
stdout, stderr := readline.Stdout, readline.Stderr
if h.cygwin {
stdout, stderr = os.Stdout, os.Stderr
}

// set file as stdin
if h.args.File != "" {
Expand All @@ -352,7 +357,12 @@ func (h *Handler) Run() error {
// set stdin if not set
var r io.ReadCloser = stdin
if stdin == nil {
c := readline.NewCancelableStdin(readline.Stdin)
var c *readline.CancelableStdin
if h.cygwin {
c = readline.NewCancelableStdin(os.Stdin)
} else {
c = readline.NewCancelableStdin(readline.Stdin)
}
defer c.Close()

r = c
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func main() {
}
arg.MustParse(args)

interactive := (isatty.IsTerminal(os.Stdout.Fd()) && isatty.IsTerminal(os.Stdin.Fd())) ||
(isatty.IsCygwinTerminal(os.Stdout.Fd()) && isatty.IsCygwinTerminal(os.Stdin.Fd()))
cygwin := isatty.IsCygwinTerminal(os.Stdout.Fd()) && isatty.IsCygwinTerminal(os.Stdin.Fd())
interactive := isatty.IsTerminal(os.Stdout.Fd()) && isatty.IsTerminal(os.Stdin.Fd())
h := &Handler{
args: args,
interactive: interactive,
cygwin: cygwin,
interactive: interactive || cygwin,
}

// run
Expand Down

0 comments on commit 294a8e4

Please sign in to comment.