Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Shell hangs when used in $(...) command-substitution #267

Closed
pbnj opened this issue Jan 24, 2020 · 1 comment
Closed

Shell hangs when used in $(...) command-substitution #267

pbnj opened this issue Jan 24, 2020 · 1 comment

Comments

@pbnj
Copy link

pbnj commented Jan 24, 2020

Thank you for this library.

I have run into a reproducible bug when survey is used in a command-substitution, i.e. $(...).

Here is an exmaple using the examples/simple.go in this repo.

This works fine:

$ go run simple.go
? What is your name? Pbnj
? Choose a color: red
Pbnj chose red.

This hangs:

$ TEST=$(go run simple.go)
# shell hangs completely
# ^Z doesn't work
# ^D doesn't work
# ^C doesn't work
# [ENTER] doesn't work

I was expecting to get the same prompts and once answered, echo $TEST would output Pbnj chose red.

I have also tried handling interrupts per the FAQ:

if err == terminal.InterruptErr {
    fmt.Println("interrupted")
    os.Exit(1)
} else if err != nil {
    panic(err)
}

But that didn't work in this case.

Input, Multiline, Password, and Confirm seem to be the most problematic ones as they hang the entire shell session, where as Select and MultiSelect can exit with [ENTER] or terminate with ^C without a problem (although the output is not what I expected, but that can be a separate issue).

What I am trying to accomplish is a CLI utility inspired by this Rust project

@pbnj pbnj changed the title Shell hangs when used in $() command-substitution Shell hangs when used in $(...) command-substitution Jan 24, 2020
@mislav
Copy link
Collaborator

mislav commented Sep 16, 2021

Thanks for reporting. Shell command substitution captures stdout of the command, but Survey only works if both stdin and stdout are attached to a terminal. Right now, what you are describing is not possible.

Follow #328 for updates

@mislav mislav closed this as completed Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants