Module: Ronin::UI::Output::Helpers

Included in:
Network::Mixins::Mixin, Support, Shell
Defined in:
lib/ronin/ui/output/helpers.rb

Overview

Helper methods for printing output.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.format(arguments) ⇒ String (protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Formats a message to be printed.


286
287
288
289
290
291
292
# File 'lib/ronin/ui/output/helpers.rb', line 286

def Helpers.format(arguments)
  unless arguments.length == 1
    arguments.first % arguments[1..-1]
  else
    arguments.first
  end
end

Instance Method Details

Prints a debug message.

Examples:

Print a formatted message:

print_debug "vars: %p %p", vars[0], vars[1]

Since:

  • 0.3.0


174
175
176
177
178
179
180
181
# File 'lib/ronin/ui/output/helpers.rb', line 174

def print_debug(*message)
  if (Output.verbose? && !(Output.silent?))
    Output.handler.print_debug(Helpers.format(message))
    return true
  end

  return false
end

Prints an error message.

Examples:

print_error "Could not connect!"

Print a formatted message:

print_error "%p: %s", error.class, error.message

Since:

  • 0.3.0


230
231
232
233
234
235
236
237
# File 'lib/ronin/ui/output/helpers.rb', line 230

def print_error(*message)
  unless Output.silent?
    Output.handler.print_error(Helpers.format(message))
    return true
  end

  return false
end

Prints an exception.

Examples:

begin
  socket.write(buffer)
rescue => e
  print_exception(e)
end

Since:

  • 0.4.0


259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/ronin/ui/output/helpers.rb', line 259

def print_exception(exception)
  return false if Output.silent?

  print_error "#{exception.class}: #{exception.message}"

  if Output.verbose?
    exception.backtrace[0,5].each do |line|
      print_error "  #{line}"
    end
  end

  return true
end

Prints an info message.

Examples:

print_info "Connecting ..."

Print a formatted message:

print_info "Connected to %s", host

Since:

  • 0.3.0


149
150
151
152
153
154
155
156
# File 'lib/ronin/ui/output/helpers.rb', line 149

def print_info(*message)
  unless Output.silent?
    Output.handler.print_info(Helpers.format(message))
    return true
  end

  return false
end

Prints a warning message.

Examples:

print_warning "Detecting a restricted character in the buffer"

Print a formatted message:

print_warning "Malformed input detected: %p", user_input

Since:

  • 0.3.0


202
203
204
205
206
207
208
209
# File 'lib/ronin/ui/output/helpers.rb', line 202

def print_warning(*message)
  unless Output.silent?
    Output.handler.print_warning(Helpers.format(message))
    return true
  end
  
  return false
end

#printf(format, *arguments) ⇒ nil

Prints formatted data.

Since:

  • 1.0.0


125
126
127
128
# File 'lib/ronin/ui/output/helpers.rb', line 125

def printf(format,*arguments)
  write(format % arguments)
  return nil
end

#putc(data) ⇒ String, Integer

Prints a character.

Since:

  • 1.0.0


64
65
66
67
68
69
# File 'lib/ronin/ui/output/helpers.rb', line 64

def putc(data)
  char = data.chr if data.kind_of?(Integer)

  write(data)
  return data
end

#puts(*arguments) ⇒ Object

Prints one or more messages.

Examples:

puts 'some data'

Since:

  • 0.3.0


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ronin/ui/output/helpers.rb', line 84

def puts(*arguments)
  if arguments.empty?
    write($/)
    return nil
  end

  arguments.each do |argument|
    if argument.kind_of?(Array)
      argument.each { |element| puts(element) }
    else
      str = case argument
            when nil
              if RUBY_VERSION > '1.9' then ''
              else                         'nil'
              end
            else
              argument.to_s
            end

      write("#{str}#{$/}")
    end
  end

  return nil
end

#write(data) ⇒ Integer?

Writes data unless output has been silenced.

Since:

  • 1.0.0


42
43
44
45
46
47
48
49
# File 'lib/ronin/ui/output/helpers.rb', line 42

def write(data)
  unless Output.silent?
    data = data.to_s

    Output.handler.write(data)
    return data.length
  end
end