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
-
#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.
16 17 18 |
# File 'lib/byebug/interface.rb', line 16 def command_queue @command_queue end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
17 18 19 |
# File 'lib/byebug/interface.rb', line 17 def error @error end |
#history ⇒ Object
Returns the value of attribute history.
16 17 18 |
# File 'lib/byebug/interface.rb', line 16 def history @history end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
17 18 19 |
# File 'lib/byebug/interface.rb', line 17 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
17 18 19 |
# File 'lib/byebug/interface.rb', line 17 def output @output end |
Instance Method Details
#autorestore ⇒ Object
Restores history according to autosave
setting.
112 113 114 |
# File 'lib/byebug/interface.rb', line 112 def autorestore history.restore if Setting[:autosave] end |
#autosave ⇒ Object
Saves or clears history according to autosave
setting.
105 106 107 |
# File 'lib/byebug/interface.rb', line 105 def autosave Setting[:autosave] ? history.save : history.clear end |
#close ⇒ Object
99 100 |
# File 'lib/byebug/interface.rb', line 99 def close end |
#confirm(prompt) ⇒ Object
Confirms user introduced an affirmative response to the input stream.
95 96 97 |
# File 'lib/byebug/interface.rb', line 95 def confirm(prompt) readline(prompt) == 'y' end |
#errmsg(message) ⇒ Object
Prints an error message to the error stream.
77 78 79 |
# File 'lib/byebug/interface.rb', line 77 def errmsg() error.print("*** #{}\n") end |
#last_if_empty(input) ⇒ Object
25 26 27 |
# File 'lib/byebug/interface.rb', line 25 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.
67 68 69 70 71 72 |
# File 'lib/byebug/interface.rb', line 67 def prepare_input(prompt) line = readline(prompt) return unless line last_if_empty(line) end |
#print(message) ⇒ Object
88 89 90 |
# File 'lib/byebug/interface.rb', line 88 def print() output.print() end |
#puts(message) ⇒ Object
Prints an output message to the output stream.
84 85 86 |
# File 'lib/byebug/interface.rb', line 84 def puts() output.puts() end |
#read_command(prompt) ⇒ Object
Pops a command from the input stream.
32 33 34 35 36 |
# File 'lib/byebug/interface.rb', line 32 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.
41 42 43 |
# File 'lib/byebug/interface.rb', line 41 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.
51 52 53 54 55 56 57 58 59 |
# File 'lib/byebug/interface.rb', line 51 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 |