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, #last_if_empty, #prepare_input, #print, #puts, #read_file, #read_input

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?

Constructor Details

#initialize(file, verbose = false) ⇒ ScriptInterface

Returns a new instance of ScriptInterface.



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

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

Instance Method Details

#closeObject



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

def close
  input.close
end

#read_command(prompt) ⇒ Object



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

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

#readlineObject



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

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