Class: Byebug::Interface
- Inherits:
-
Object
- Object
- Byebug::Interface
- Includes:
- Helpers::FileHelper
- Defined in:
- lib/byebug/interface.rb
Overview
Main Interface class
Contains common functionality to all implemented interfaces.
Direct Known Subclasses
LocalInterface, RemoteInterface, ScriptInterface, TestInterface
Instance Attribute Summary collapse
-
#command_queue ⇒ Object
Returns the value of attribute command_queue.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#history ⇒ Object
Returns the value of attribute history.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#autorestore ⇒ Object
Restores history according to
autosave
setting. -
#autosave ⇒ Object
Saves or clears history according to
autosave
setting. - #close ⇒ Object
-
#confirm(prompt) ⇒ Object
Confirms user introduced an affirmative response to the input stream.
-
#errmsg(message) ⇒ Object
Prints an error message to the error stream.
-
#initialize ⇒ Interface
constructor
A new instance of Interface.
- #last_if_empty(input) ⇒ Object
-
#prepare_input(prompt) ⇒ String
Reads a new line from the interface’s input stream.
-
#print(message) ⇒ Object
Prints an output message to the output stream without a final “n”.
-
#puts(message) ⇒ Object
Prints an output message to the output stream.
-
#read_command(prompt) ⇒ Object
Pops a command from the input stream.
-
#read_file(filename) ⇒ Object
Pushes lines in
filename
to the command queue. -
#read_input(prompt, save_hist = true) ⇒ String
Reads a new line from the interface’s input stream, parses it into commands and saves it to history.
Methods included from Helpers::FileHelper
#get_line, #get_lines, #n_lines, #normalize, #shortpath, #virtual_file?
Constructor Details
Instance Attribute Details
#command_queue ⇒ Object
Returns the value of attribute command_queue.
19 20 21 |
# File 'lib/byebug/interface.rb', line 19 def command_queue @command_queue end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
20 21 22 |
# File 'lib/byebug/interface.rb', line 20 def error @error end |
#history ⇒ Object
Returns the value of attribute history.
19 20 21 |
# File 'lib/byebug/interface.rb', line 19 def history @history end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
20 21 22 |
# File 'lib/byebug/interface.rb', line 20 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
20 21 22 |
# File 'lib/byebug/interface.rb', line 20 def output @output end |
Instance Method Details
#autorestore ⇒ Object
Restores history according to autosave
setting.
118 119 120 |
# File 'lib/byebug/interface.rb', line 118 def autorestore history.restore if Setting[:autosave] end |
#autosave ⇒ Object
Saves or clears history according to autosave
setting.
111 112 113 |
# File 'lib/byebug/interface.rb', line 111 def autosave Setting[:autosave] ? history.save : history.clear end |
#close ⇒ Object
105 106 |
# File 'lib/byebug/interface.rb', line 105 def close end |
#confirm(prompt) ⇒ Object
Confirms user introduced an affirmative response to the input stream.
101 102 103 |
# File 'lib/byebug/interface.rb', line 101 def confirm(prompt) readline(prompt) == "y" end |
#errmsg(message) ⇒ Object
Prints an error message to the error stream.
80 81 82 |
# File 'lib/byebug/interface.rb', line 80 def errmsg() error.print("*** #{}\n") end |
#last_if_empty(input) ⇒ Object
28 29 30 |
# File 'lib/byebug/interface.rb', line 28 def last_if_empty(input) @last_line = input.empty? ? @last_line : input end |
#prepare_input(prompt) ⇒ String
Reads a new line from the interface’s input stream.
read now was empty.
70 71 72 73 74 75 |
# File 'lib/byebug/interface.rb', line 70 def prepare_input(prompt) line = readline(prompt) return unless line last_if_empty(line) end |
#print(message) ⇒ Object
Prints an output message to the output stream without a final “n”.
94 95 96 |
# File 'lib/byebug/interface.rb', line 94 def print() output.print() end |
#puts(message) ⇒ Object
Prints an output message to the output stream.
87 88 89 |
# File 'lib/byebug/interface.rb', line 87 def puts() output.puts() end |
#read_command(prompt) ⇒ Object
Pops a command from the input stream.
35 36 37 38 39 |
# File 'lib/byebug/interface.rb', line 35 def read_command(prompt) return command_queue.shift unless command_queue.empty? read_input(prompt) end |
#read_file(filename) ⇒ Object
Pushes lines in filename
to the command queue.
44 45 46 |
# File 'lib/byebug/interface.rb', line 44 def read_file(filename) command_queue.concat(get_lines(filename)) end |
#read_input(prompt, save_hist = true) ⇒ String
Reads a new line from the interface’s input stream, parses it into commands and saves it to history.
54 55 56 57 58 59 60 61 62 |
# File 'lib/byebug/interface.rb', line 54 def read_input(prompt, save_hist = true) line = prepare_input(prompt) return unless line history.push(line) if save_hist command_queue.concat(split_commands(line)) command_queue.shift end |