Class: Reline::IO
- Inherits:
-
Object
- Object
- Reline::IO
- Defined in:
- lib/reline/io.rb
Constant Summary collapse
- RESET_COLOR =
"\e[0m"
Class Method Summary collapse
Instance Method Summary collapse
- #dumb? ⇒ Boolean
-
#read_single_char(timeout_second) ⇒ Object
Read a single encoding valid character from the input.
- #reset_color_sequence ⇒ Object
- #win? ⇒ Boolean
Class Method Details
.decide_io_gate ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/reline/io.rb', line 6 def self.decide_io_gate if ENV['TERM'] == 'dumb' Reline::Dumb.new else require 'reline/io/ansi' case RbConfig::CONFIG['host_os'] when /mswin|mingw|bccwin|wince|emc/ require 'reline/io/windows' io = Reline::Windows.new if io.msys_tty? || !STDIN.tty? # In either case stdin is not a console (a Cygwin/MSYS pty pipe such # as mintty, or a redirect), so the Win32 console input API cannot # read it. Reline::ANSI.new else io end else # Ruby built with the msys/cygwin runtime also reaches here. Its tty layer # speaks ANSI in any terminal (mintty pty or Windows console), so the # Win32 console API must not be used. https://github.com/ruby/reline/issues/903 Reline::ANSI.new end end end |
Instance Method Details
#dumb? ⇒ Boolean
33 34 35 |
# File 'lib/reline/io.rb', line 33 def dumb? false end |
#read_single_char(timeout_second) ⇒ Object
Read a single encoding valid character from the input.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/reline/io.rb', line 46 def read_single_char(timeout_second) buffer = String.new(encoding: Encoding::ASCII_8BIT) loop do timeout = buffer.empty? ? Float::INFINITY : timeout_second c = getc(timeout) return unless c buffer << c encoded = buffer.dup.force_encoding(encoding) return encoded if encoded.valid_encoding? end end |
#reset_color_sequence ⇒ Object
41 42 43 |
# File 'lib/reline/io.rb', line 41 def reset_color_sequence self.class::RESET_COLOR end |
#win? ⇒ Boolean
37 38 39 |
# File 'lib/reline/io.rb', line 37 def win? false end |