Class: Byebug::Interface

Inherits:
Object
  • Object
show all
Includes:
Helpers::FileHelper
Defined in:
lib/byebug/interface.rb

Overview

Main Interface class

Contains common functionality to all implemented interfaces.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::FileHelper

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

Constructor Details

#initializeInterface

Returns a new instance of Interface.



20
21
22
23
24
# File 'lib/byebug/interface.rb', line 20

def initialize
  @command_queue = []
  @history = History.new
  @last_line = ''
end

Instance Attribute Details

#command_queueObject

Returns the value of attribute command_queue.



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

def command_queue
  @command_queue
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#historyObject

Returns the value of attribute history.



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

def history
  @history
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#autorestoreObject

Restores history according to autosave setting.



116
117
118
# File 'lib/byebug/interface.rb', line 116

def autorestore
  history.restore if Setting[:autosave]
end

#autosaveObject

Saves or clears history according to autosave setting.



109
110
111
# File 'lib/byebug/interface.rb', line 109

def autosave
  Setting[:autosave] ? history.save : history.clear
end

#closeObject



103
104
# File 'lib/byebug/interface.rb', line 103

def close
end

#confirm(prompt) ⇒ Object

Confirms user introduced an affirmative response to the input stream.



99
100
101
# File 'lib/byebug/interface.rb', line 99

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(message)
  error.print("*** #{message}\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.

Returns:

  • (String)

    New string read or the previous string if the string



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

Prints an output message to the output stream without a final “n”.



92
93
94
# File 'lib/byebug/interface.rb', line 92

def print(message)
  output.print(message)
end

#puts(message) ⇒ Object

Prints an output message to the output stream.



85
86
87
# File 'lib/byebug/interface.rb', line 85

def puts(message)
  output.puts(message)
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.

Returns:

  • (String)

    Representing something to be run by the debugger.



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