Class: Walnut::Input::Readline

Inherits:
Object
  • Object
show all
Defined in:
lib/walnut/input/readline.rb

Overview

Readline input plugin

Must implement #read, #gets, and #eof?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ Readline

Returns a new instance of Readline.



17
18
19
20
# File 'lib/walnut/input/readline.rb', line 17

def initialize(parent)
  @walnut       = parent
  @input_object = ::Readline
end

Instance Attribute Details

#input_objectObject (readonly)

Returns the value of attribute input_object.



15
16
17
# File 'lib/walnut/input/readline.rb', line 15

def input_object
  @input_object
end

Instance Method Details

#closeObject



41
42
43
# File 'lib/walnut/input/readline.rb', line 41

def close
  @eof = nil
end

#eof?TrueClass, FalseClass

Check if an EOF has been reached

Returns:

  • (TrueClass, FalseClass)


35
36
37
# File 'lib/walnut/input/readline.rb', line 35

def eof?
  (@eof.nil?) ? true : false
end

#getsString, NilClass Also known as: read

Note:

The instance variable @eof is set to nil when EOF has been reached, see #eof?

Read a line from input

Returns:

  • (String, NilClass)

    A line read from the input, or nil if the user canceled the input with C-d



28
29
30
# File 'lib/walnut/input/readline.rb', line 28

def gets
  @eof = @input_object.readline(@walnut[:input].prompt||Walnut[:input].prompt, @walnut[:input].history||[])
end