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

Included in:
Shell
Defined in:
lib/ronin/ui/output/helpers.rb

Overview

Helper methods for printing output.

Instance Method Summary collapse

Instance Method Details

#format_message(message) ⇒ 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.

Parameters:

  • message (Array)

    The message and additional Objects to format.

Returns:

  • (String)

    The formatted message.

Since:

  • 1.0.0



238
239
240
241
242
243
244
# File 'lib/ronin/ui/output/helpers.rb', line 238

def format_message(message)
  if message.length == 1
    message[0]
  else
    message[0] % message[1..-1]
  end
end

Prints a debug message.

Examples:

Print a formatted message.

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

Parameters:

Returns:

  • (Boolean)

    Specifies whether the messages were successfully printed.

Since:

  • 0.3.0



158
159
160
161
162
163
164
165
# File 'lib/ronin/ui/output/helpers.rb', line 158

def print_debug(*message)
  if (Output.verbose? && !(Output.silent?))
    Output.handler.print_debug(format_message(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

Parameters:

Returns:

  • (Boolean)

    Specifies whether the messages were successfully printed.

Since:

  • 0.3.0



214
215
216
217
218
219
220
221
# File 'lib/ronin/ui/output/helpers.rb', line 214

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

  return false
end

Prints an info message.

Examples:

print_info "Connecting ..."

Print a formatted message.

print_info "Connected to %s", host

Parameters:

  • message (Array)

    The message to print.

Returns:

  • (Boolean)

    Specifies whether the messages were successfully printed.

Since:

  • 0.3.0



133
134
135
136
137
138
139
140
# File 'lib/ronin/ui/output/helpers.rb', line 133

def print_info(*message)
  unless Output.silent?
    Output.handler.print_info(format_message(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

Parameters:

Returns:

  • (Boolean)

    Specifies whether the messages were successfully printed.

Since:

  • 0.3.0



186
187
188
189
190
191
192
193
# File 'lib/ronin/ui/output/helpers.rb', line 186

def print_warning(*message)
  if (Output.verbose? && !(Output.silent?))
    Output.handler.print_warning(format_message(message))
    return true
  end
  
  return false
end

#printf(format, *data) ⇒ nil

Prints formatted data.

Parameters:

  • format (String)

    The format string.

  • data (Array)

    The data to format.

Returns:

  • (nil)

Since:

  • 1.0.0



109
110
111
112
# File 'lib/ronin/ui/output/helpers.rb', line 109

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

#putc(data) ⇒ String, Integer

Prints a character.

Parameters:

Returns:

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(*messages) ⇒ Object

Prints one or more messages.

Examples:

puts 'some data'

Parameters:

  • messages (Array)

    The messages to print.

Since:

  • 0.3.0



84
85
86
87
88
89
90
91
92
# File 'lib/ronin/ui/output/helpers.rb', line 84

def puts(*messages)
  unless messages.empty?
    messages.each { |message| write("#{message}#{$/}") }
  else
    write($/)
  end

  return nil
end

#write(data) ⇒ Integer?

Writes data unless output has been silenced.

Parameters:

Returns:

  • (Integer, nil)

    The number of bytes written.

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