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.



22
23
24
25
26
# File 'lib/byebug/interface.rb', line 22

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

Instance Attribute Details

#command_queueObject

Returns the value of attribute command_queue.



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

def command_queue
  @command_queue
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#historyObject

Returns the value of attribute history.



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

def history
  @history
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#autorestoreObject

Restores history according to autosave setting.



118
119
120
# File 'lib/byebug/interface.rb', line 118

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

#autosaveObject

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

#closeObject



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

Returns:

  • (String)

    New string read or the previous string if the string



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

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



94
95
96
# File 'lib/byebug/interface.rb', line 94

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

#puts(message) ⇒ Object

Prints an output message to the output stream.



87
88
89
# File 'lib/byebug/interface.rb', line 87

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

Returns:

  • (String)

    Representing something to be run by the debugger.



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