Module: Ronin::UI::Console

Defined in:
lib/ronin/ui/console/console.rb,
lib/ronin/ui/console/context.rb,
lib/ronin/ui/console/commands.rb

Overview

An interactive Ruby Console using Ripl.

Defined Under Namespace

Modules: Commands Classes: Context

Constant Summary collapse

HISTORY_FILE =

The history file for the Console session

File.join(Config::PATH,'console.log')
@@color =
!(STDOUT.tty?)
@@short_errors =
!(ENV.has_key?('VERBOSE'))
@@auto_load =
[]
@@setup_blocks =
[]

Class Method Summary collapse

Class Method Details

.auto_loadArray

The list of files to load before starting the Console.



115
116
117
# File 'lib/ronin/ui/console/console.rb', line 115

def Console.auto_load
  @@auto_load
end

.color=(mode) ⇒ Boolean

Enables or disables colorized output.

Since:

  • 1.0.0



71
72
73
# File 'lib/ronin/ui/console/console.rb', line 71

def Console.color=(mode)
  @@color = mode
end

.color?Boolean

Determines whether colorized output will be enabled.

Since:

  • 1.0.0



54
55
56
# File 'lib/ronin/ui/console/console.rb', line 54

def Console.color?
  @@color
end

.completionsArray<String>

The list of completions files to require.

Since:

  • 1.2.0



142
143
144
# File 'lib/ronin/ui/console/console.rb', line 142

def Console.completions
  (Ripl.config[:completion][:gems] ||= [])
end

.setup { ... } ⇒ Object

Adds a block to be ran from within the Console after it is started.

Yields:

  • [] The block to be ran from within the Console.



128
129
130
# File 'lib/ronin/ui/console/console.rb', line 128

def Console.setup(&block)
  @@setup_blocks << block if block
end

.short_errors=(mode) ⇒ Boolean

Enables or disables the printing of one-lin errors.

Since:

  • 1.0.0



103
104
105
# File 'lib/ronin/ui/console/console.rb', line 103

def Console.short_errors=(mode)
  @@short_errors = mode
end

.short_errors?Boolean

Determines whether one-line errors will be printed, instead of full backtraces.

Since:

  • 1.0.0



86
87
88
# File 'lib/ronin/ui/console/console.rb', line 86

def Console.short_errors?
  @@short_errors
end

.start(variables = {}) { ... } ⇒ Console

Starts a Console.

Examples:

Console.start
# >>
Console.start(:var => 'hello')
# >> @var
# # => "hello"
Console.start { @var = 'hello' }
# >> @var
# # => "hello"

Yields:

  • [] The block to be ran within the Console, after it has been setup.



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/ronin/ui/console/console.rb', line 176

def Console.start(variables={},&block)
  require 'ripl/color_result' if @@color
  require 'ripl/short_errors' if @@short_errors

  require 'ronin'
  require 'ronin/repositories'
  require 'pp'

  # append the current directory to $LOAD_PATH for Ruby 1.9.
  $LOAD_PATH << '.' unless $LOAD_PATH.include?('.')

  # require any of the auto-load paths
  @@auto_load.each { |path| require path }

  context = Context.new
  context.instance_variables = variables

  # run any setup-blocks
  @@setup_blocks.each do |setup_block|
    context.instance_eval(&setup_block)
  end

  # run the supplied configuration block is given
  context.instance_eval(&block) if block

  # Start the Ripl console
  Ripl.start(
    :argv => [],
    :name => 'ronin',
    :binding => context.instance_eval('binding'),
    :history => HISTORY_FILE,
    :irbrc => false
  )

  return context
end