Class: RCommand::RawIOMethod

Inherits:
IOMethod show all
Defined in:
lib/rcommand/io_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(command_line) ⇒ RawIOMethod

Returns a new instance of RawIOMethod.



42
43
44
# File 'lib/rcommand/io_methods.rb', line 42

def initialize(command_line)
  super(command_line)
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rcommand/io_methods.rb', line 57

def eof?
  begin
    require 'timeout'
    Timeout.timeout(0.01) do
      return $stdin.eof?
    end
  rescue LoadError
    return $stdin.eof?
  rescue Timeout::Error
    return true
  end
end

#readlineObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/rcommand/io_methods.rb', line 46

def readline
  if @command_line.prompt != nil && @command_line.io_write != nil
    @command_line.io_write.print(@command_line.prompt)
  end

  line = @command_line.io_read.gets()
  line = line[0..-1] if line[-1] == "\n"
  line = line[0..-1] if line[-1] == "\r"
  return line + "\n"
end