Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running inside a bash script causes invisible select navigation #41

Closed
Allendar opened this issue Dec 2, 2017 · 7 comments
Closed

Running inside a bash script causes invisible select navigation #41

Allendar opened this issue Dec 2, 2017 · 7 comments

Comments

@Allendar
Copy link

Allendar commented Dec 2, 2017

I noticed that the select functionality (as shown in the README example) fails to update and give visual feedback when running inside a bash script.

I have this script for my project:

#!/bin/bash

clear

# Do a lot of help tools and automated work

go run $(find . -maxdepth 1 -type f -name '*.go' ! -name '*_test.go' | xargs)

Running the go run line in Bash or ZSH works fine when navigating the list, but inside the script there's no feedback, although in the Select Day: example, if I press down twice for example and hit enter it did choose Wednesday. So it works, but just doesn't visually update.

  • I'm running macOS High Sierra 10.13.1
  • Go version is go1.9.2 darwin/amd64
  • My ZSH version is 5.3 and Bash version is 3.2
@hallazzang
Copy link
Contributor

I'm trying to reproduce this behavior on my machine, but couldn't. I'm on macOS High Sierra, using zsh 5.3, GNU bash 3.2.57, Go 1.9.2 darwin/amd64. For detailed versions, check the last paragraph.

I just copy-pasted the Select example in the READMEas well as the script you've provided.

So my working directory looks like this:

workdir/
    main.go  # Select example here
    run.sh  # Your script here

First, when I run the main.go directly(go run main.go), everything works fine. And then I ran your script(./run.sh, after giving x mode, of course), it worked find too. I've tested `bash run.sh, 'zsh run.sh', even in a tmux environment, everything looks perfectly working. Try latest version of promptui and check if it's still not working.

Detailed outputs of my environments are:

$ sw_vers -productVersion
10.13.2
$ zsh --version
zsh 5.3 (x86_64-apple-darwin17.0)
$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)
Copyright (C) 2007 Free Software Foundation, Inc.
$ go version
go version go1.9.2 darwin/amd64

@louisbranch
Copy link
Contributor

I also didn't have an issue on Linux with bash. At least not if the snippet you posted @Allendar . Maybe your full script is doing something before the go call and interfering with promptui?

@Allendar
Copy link
Author

I wanted to try to test it again with the latest version but got:

vendor/github.com/manifoldco/promptui/prompt.go:88:11: cannot use p.stdin (type io.Reader) as type io.ReadCloser in assignment:
        io.Reader does not implement io.ReadCloser (missing Close method)

In the meantime I'll try to run a previous version and see if I can find out more about the navigational issue.

@hallazzang
Copy link
Contributor

@Allendar That should be fixed by #47. Try run go get -u github.com/manifoldco/promptui(don't forget -u flag) and check it again. But it seems you have promptui in your vendor folder, after go geting, copy and paste entire source code at $GOPATH/src/github.com/manifoldco/promptui to your vendor/github.com/manifoldco/promptui.

@Allendar
Copy link
Author

It works now :). I was using a new style in my bash script already, which also didn't seem to work, but after dissecting it it was the redirecting/piping to https://github.com/maruel/panicparse output like so:

go run main.go -env=$ENV $RESETDB 2>&1 | pp

Without 2>&1 | pp it works fine, but I'll lose the pretty printed stack trace tho. Maybe it's worth researching that too?

@hallazzang
Copy link
Contributor

hallazzang commented Dec 13, 2017

How about using this method instead? It'll redirect stderr to a file and then let pp parse it. I think it's not good idea to redirect stdout to pp directly since promptui things are printed to stdout.

Here's how you can do it in one line:

go run main.go -env=$ENV $RESETDB 2> panic.txt || pp panic.txt && rm panic.txt

And in my case, /usr/bin/pp was already exist so I used $GOPATH/bin/pp instead of just pp in script.

@Allendar
Copy link
Author

That works perfect! Thank you very much 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants