diff options
author | Keenan Brock <keenan@thebrocks.net> | 2023-04-24 15:33:54 -0400 |
---|---|---|
committer | Keenan Brock <keenan@thebrocks.net> | 2023-04-24 15:51:46 -0400 |
commit | ec1885893dc2bb863b4858a110ad86abf7ee4612 (patch) | |
tree | ce71b221d7f759d2e199a93e61d557905b6c7815 | |
parent | 7ebab0711106a76cace8b81e74f8c540a9a5dc60 (diff) | |
download | highline-ec1885893dc2bb863b4858a110ad86abf7ee4612.tar.gz |
Do not call stty on non-tty
When testing on a non-tty (e.g.: github actions),
either one of these lines produces an error:
```ruby
input.echo = true
ask("question", "y") { |q| q.readline = true }
```
The error is produced by ruby internals:
```bash
echo | rake | cat
......stty: stdin isn't a terminal......
```
This change skips the stty calls if the input is not on a tty, so the
errors will not be produced.
-rw-r--r-- | lib/highline/terminal.rb | 2 | ||||
-rw-r--r-- | lib/highline/terminal/unix_stty.rb | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/highline/terminal.rb b/lib/highline/terminal.rb index 550c0c7..bfa0d08 100644 --- a/lib/highline/terminal.rb +++ b/lib/highline/terminal.rb @@ -176,7 +176,7 @@ class HighLine # Saves terminal state using shell stty command. def save_stty @stty_save = begin - `stty -g`.chomp + `stty -g`.chomp if input.tty? rescue StandardError nil end diff --git a/lib/highline/terminal/unix_stty.rb b/lib/highline/terminal/unix_stty.rb index 1dbed36..df1460b 100644 --- a/lib/highline/terminal/unix_stty.rb +++ b/lib/highline/terminal/unix_stty.rb @@ -20,7 +20,9 @@ class HighLine rescue LoadError end - if /solaris/ =~ RUBY_PLATFORM && + if !@output.tty? + [80, 24] + elsif /solaris/ =~ RUBY_PLATFORM && `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i) elsif `stty size` =~ /^(\d+)\s(\d+)$/ @@ -33,7 +35,7 @@ class HighLine # (see Terminal#raw_no_echo_mode) def raw_no_echo_mode save_stty - system "stty raw -echo -icanon isig" + system "stty raw -echo -icanon isig" if input.tty? end # (see Terminal#restore_mode) |