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

Constructor Details

#initializeInterface

Returns a new instance of Interface.



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

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

Instance Attribute Details

#command_queueObject

Returns the value of attribute command_queue.



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

def command_queue
  @command_queue
end

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#historyObject

Returns the value of attribute history.



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

def history
  @history
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#autorestoreObject

Restores history according to autosave setting.



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

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

#autosaveObject

Saves or clears history according to autosave setting.



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

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

#closeObject



81
82
# File 'lib/byebug/interface.rb', line 81

def close
end

#confirm(prompt) ⇒ Object

Confirms user introduced an affirmative response to the input stream.



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

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

#errmsg(message) ⇒ Object

Prints an error message to the error stream.



59
60
61
# File 'lib/byebug/interface.rb', line 59

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


70
71
72
# File 'lib/byebug/interface.rb', line 70

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

#puts(message) ⇒ Object

Prints an output message to the output stream.



66
67
68
# File 'lib/byebug/interface.rb', line 66

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

#read_command(prompt) ⇒ Object

Pops a command from the input stream.



27
28
29
30
31
32
33
34
35
# File 'lib/byebug/interface.rb', line 27

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.



40
41
42
# File 'lib/byebug/interface.rb', line 40

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.



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

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

  history.push(line) if save_hist

  split_commands(line)
end