Class: Byebug::Interface

Inherits:
Object
  • Object
show all
Includes:
FileFunctions
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 FileFunctions

#get_line, #get_lines, #n_lines, #normalize

Constructor Details

#initializeInterface

Returns a new instance of Interface.


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

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

Instance Attribute Details

#command_queueObject

Returns the value of attribute command_queue


14
15
16
# File 'lib/byebug/interface.rb', line 14

def command_queue
  @command_queue
end

#errorObject (readonly)

Returns the value of attribute error


15
16
17
# File 'lib/byebug/interface.rb', line 15

def error
  @error
end

#historyObject

Returns the value of attribute history


14
15
16
# File 'lib/byebug/interface.rb', line 14

def history
  @history
end

#inputObject (readonly)

Returns the value of attribute input


15
16
17
# File 'lib/byebug/interface.rb', line 15

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output


15
16
17
# File 'lib/byebug/interface.rb', line 15

def output
  @output
end

Instance Method Details

#autorestoreObject

Restores history according to autosave setting.


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

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

#autosaveObject

Saves or clears history according to autosave setting.


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

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

#closeObject


79
80
# File 'lib/byebug/interface.rb', line 79

def close
end

#confirm(prompt) ⇒ Object

Confirms user introduced an affirmative response to the input stream.


75
76
77
# File 'lib/byebug/interface.rb', line 75

def confirm(prompt)
  readline(prompt) == 'y'
end

#errmsg(message) ⇒ Object

Prints an error message to the error stream.


57
58
59
# File 'lib/byebug/interface.rb', line 57

def errmsg(message)
  error.print("*** #{message}\n")
end

68
69
70
# File 'lib/byebug/interface.rb', line 68

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

#puts(message) ⇒ Object

Prints an output message to the output stream.


64
65
66
# File 'lib/byebug/interface.rb', line 64

def puts(message)
  output.puts(message)
end

#read_command(prompt) ⇒ Object

Pops a command from the input stream.


24
25
26
27
28
29
30
31
32
# File 'lib/byebug/interface.rb', line 24

def read_command(prompt)
  return command_queue.shift unless command_queue.empty?

  cmds = read_input(prompt)
  return unless cmds

  command_queue.concat(cmds)
  command_queue.shift
end

#read_file(filename) ⇒ Object

Pushes lines in filename to the command queue.


38
39
40
# File 'lib/byebug/interface.rb', line 38

def read_file(filename)
  command_queue.concat(get_lines(filename))
end

#read_input(prompt, save_hist = true) ⇒ Object

Reads a new line from the interface's input stream.


45
46
47
48
49
50
51
52
# File 'lib/byebug/interface.rb', line 45

def read_input(prompt, save_hist = true)
  line = readline(prompt)
  return unless line

  history.push(line) if save_hist

  split_commands(line)
end