diff --git a/lib/tty/reader.rb b/lib/tty/reader.rb index c30062b..21fec40 100644 --- a/lib/tty/reader.rb +++ b/lib/tty/reader.rb @@ -221,8 +221,9 @@ def unbufferred(&block) # whether to echo chars back or not, defaults to false # @option [Boolean] raw # whenther raw mode is enabled, defaults to true - # @option [Boolean] nonblock + # @option [Boolean, Numeric] nonblock # whether to wait for input or not, defaults to false + # if it's Numeric, then use that for the timeout # # @return [String] # diff --git a/lib/tty/reader/console.rb b/lib/tty/reader/console.rb index d5d41b9..a2eb172 100644 --- a/lib/tty/reader/console.rb +++ b/lib/tty/reader/console.rb @@ -40,8 +40,9 @@ def initialize(input) # whether to echo input back or not, defaults to true # @param [Boolean] raw # whether to use raw mode or not, defaults to false - # @param [Boolean] nonblock + # @param [Boolean, Numeric] nonblock # whether to wait for input or not, defaults to false + # if it's Numeric, then use that for the timeout # # @return [String] # @@ -50,7 +51,7 @@ def get_char(echo: true, raw: false, nonblock: false) mode.raw(raw) do mode.echo(echo) do if nonblock - input.wait_readable(TIMEOUT) ? input.getc : nil + input.wait_readable(nonblock.is_a?(Numeric) ? nonblock : TIMEOUT) ? input.getc : nil else input.getc end