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