JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

Do not call stty on non-tty #262

Closed kbrock closed 1 year ago

kbrock commented 1 year ago

Thanks for this great project

Before

Both of these cause a warning:

input.echo = true
ask("question", "y") { |q| q.readline = true }

The warning:

echo | rake | cat

......stty: stdin isn't a terminal......

Solution

It no longer calls stty for a non-tty. The reasoning being that if you do call stty, then it will just throw an error and skip the stty call in the first place. So why call it?

This is following the precedence for the terminal size portion that checked @output.tty? There are other cases that call the stty methods and catch errors, but those cases have a request to fix them.

It looks like many of these use cases are not under test. Please let me know what I can do to help you feel comfortable with these changes

Fryguy commented 1 year ago

One comment to add here is that we are testing our highline interface in CI where stdin is not a tty. The true | rake 2>&1 | cat trick lets you simulate that locally. I also found you can do the same trick with https://github.com/nektos/act if you want to even more simulate GitHub actions' tty.

abinoam commented 1 year ago

Thanks @kbrock @Fryguy !

abinoam commented 1 year ago

Since "io/console" some "hacks" are not even necessary. I have to take some time to clean up the whole code as we did for v2 release. (Yes, highline exists from a time when there was no "io/console" in Ruby.