Class: Rereline::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/rereline/terminal.rb

Defined Under Namespace

Modules: Ex Classes: Finish

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prompt, use_history) ⇒ Terminal

Returns a new instance of Terminal.



25
26
27
28
29
30
31
32
33
34
# File 'lib/rereline/terminal.rb', line 25

def initialize(prompt, use_history)
  @editor = LineEditor.new do |editor|
    editor.prompt = prompt
  end
  @key_stroke = KeyStroke.new(KeyActor::MAPPING)
  @key_actor = KeyActor.new(editor)
  @input = $stdin
  @output = $stdout
  @input_key_buffer = []
end

Instance Attribute Details

#editorObject (readonly)

Returns the value of attribute editor.



23
24
25
# File 'lib/rereline/terminal.rb', line 23

def editor
  @editor
end

#inputObject (readonly)

Returns the value of attribute input.



23
24
25
# File 'lib/rereline/terminal.rb', line 23

def input
  @input
end

#key_actorObject (readonly)

Returns the value of attribute key_actor.



23
24
25
# File 'lib/rereline/terminal.rb', line 23

def key_actor
  @key_actor
end

#key_strokeObject (readonly)

Returns the value of attribute key_stroke.



23
24
25
# File 'lib/rereline/terminal.rb', line 23

def key_stroke
  @key_stroke
end

#outputObject (readonly)

Returns the value of attribute output.



23
24
25
# File 'lib/rereline/terminal.rb', line 23

def output
  @output
end

Instance Method Details

#readlineObject



36
37
38
39
40
41
42
43
44
# File 'lib/rereline/terminal.rb', line 36

def readline
  renader_editor
  loop do
    input_key(getkey)
  end
rescue Finish => e
  output.write "\n"
  e.message
end