console-rs / dialoguer

Rust utility library for nice command line prompts and similar things
MIT License
1.33k stars 143 forks source link

Unable to pipe `yes` into a confirmation #170

Open jgrund opened 2 years ago

jgrund commented 2 years ago

Hi,

When wanting to bypass a confirmation in an automated way, it does not appear possible to use the yes command, I.E:

yes | some_dialoguer_cmd

Will just hang

ip1981 commented 2 years ago

Probably it could have a code path for the case when stdin is not a tty.

sycured commented 2 years ago

@jgrund I used expect and it works

#!/usr/local/bin/expect -f

set timeout -1
spawn ./tests.sh
match_max 100000
expect -exact "Are you sure you want to delete the project key: CITS? \[y/n\] \[?25l"
send -- "y"
expect eof

My biggest problem was finding the ending "[?25l"

LeoDog896 commented 1 year ago

82 using rustyline may be able to solve this issue.