Class: Byebug::ScriptInterface

Inherits:
Interface show all
Defined in:
lib/byebug/interfaces/script_interface.rb

Overview

Interface class for command execution from script files.

Instance Attribute Summary

Attributes inherited from Interface

#command_queue, #error, #history, #input, #output

Instance Method Summary collapse

Methods inherited from Interface

#autorestore, #autosave, #confirm, #errmsg, #print, #puts, #read_file, #read_input

Methods included from FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Constructor Details

#initialize(file, verbose = false) ⇒ ScriptInterface

Returns a new instance of ScriptInterface.


6
7
8
9
10
11
# File 'lib/byebug/interfaces/script_interface.rb', line 6

def initialize(file, verbose = false)
  super()
  @input = File.open(file)
  @output = verbose ? STDOUT : StringIO.new
  @error = verbose ? STDERR : StringIO.new
end

Instance Method Details

#closeObject


17
18
19
# File 'lib/byebug/interfaces/script_interface.rb', line 17

def close
  input.close
end

#read_command(prompt) ⇒ Object


13
14
15
# File 'lib/byebug/interfaces/script_interface.rb', line 13

def read_command(prompt)
  readline(prompt, false)
end

#readlineObject


21
22
23
24
25
26
27
# File 'lib/byebug/interfaces/script_interface.rb', line 21

def readline(*)
  while (result = input.gets)
    output.puts "+ #{result}"
    next if result =~ /^\s*#/
    return result.chomp
  end
end