2005-07-17 07:06:05 +00:00
|
|
|
module Rex
|
|
|
|
module Ui
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module provides a subscriber interface to input/output.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
module Subscriber
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Subscribes to the output half of the user interface.
|
|
|
|
#
|
|
|
|
##
|
|
|
|
module Output
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.print_line
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_line(msg='')
|
2007-04-04 02:38:15 +00:00
|
|
|
if (user_output)
|
|
|
|
print_blank_line if user_output.prompting?
|
|
|
|
user_output.print_line(msg)
|
|
|
|
end
|
2005-07-17 07:06:05 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.print_status
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_status(msg='')
|
2007-04-04 02:38:15 +00:00
|
|
|
if (user_output)
|
|
|
|
print_blank_line if user_output.prompting?
|
|
|
|
user_output.print_status(msg)
|
|
|
|
end
|
2005-07-17 07:06:05 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.print_error
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_error(msg='')
|
2007-04-04 02:38:15 +00:00
|
|
|
if (user_output)
|
|
|
|
print_blank_line if user_output.prompting?
|
|
|
|
user_output.print_error(msg)
|
|
|
|
end
|
2005-07-17 07:06:05 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.print_good
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_good(msg='')
|
2007-04-04 02:38:15 +00:00
|
|
|
if (user_output)
|
|
|
|
print_blank_line if user_output.prompting?
|
|
|
|
user_output.print_good(msg)
|
|
|
|
end
|
2005-07-17 07:06:05 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.print
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print(msg='')
|
2005-07-17 07:06:05 +00:00
|
|
|
user_output.print(msg) if (user_output)
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Wraps user_output.flush
|
|
|
|
#
|
2005-07-17 07:06:05 +00:00
|
|
|
def flush
|
|
|
|
user_output.flush if (user_output)
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The user output handle.
|
|
|
|
#
|
2005-07-17 07:06:05 +00:00
|
|
|
attr_accessor :user_output
|
2007-04-04 02:38:15 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints a blank line. Used when the input is prompting.
|
|
|
|
#
|
|
|
|
def print_blank_line
|
|
|
|
user_output.prompting(false)
|
|
|
|
user_output.print_line
|
|
|
|
end
|
2005-07-17 07:06:05 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Subscribes to the input half of the user interface.
|
|
|
|
#
|
|
|
|
##
|
|
|
|
module Input
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Gets a line of input from the user_input handle by calling gets.
|
|
|
|
#
|
2005-07-17 07:06:05 +00:00
|
|
|
def gets
|
|
|
|
user_input.gets if (user_input)
|
|
|
|
end
|
2005-11-15 05:22:13 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The user intput handle.
|
|
|
|
#
|
2005-07-17 07:06:05 +00:00
|
|
|
attr_accessor :user_input
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
include Output
|
|
|
|
include Input
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets the input and output handles.
|
|
|
|
#
|
|
|
|
def init_ui(input = nil, output = nil)
|
|
|
|
self.user_input = input
|
|
|
|
self.user_output = output
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Disables input/output
|
|
|
|
#
|
|
|
|
def reset_ui
|
|
|
|
self.user_input = nil
|
|
|
|
self.user_output = nil
|
|
|
|
end
|
|
|
|
|
2005-12-30 02:38:18 +00:00
|
|
|
#
|
|
|
|
# Copy the user input and output handles from the supplied subscriber.
|
|
|
|
#
|
|
|
|
def copy_ui(subscriber)
|
|
|
|
init_ui(subscriber.user_input, subscriber.user_output)
|
|
|
|
end
|
|
|
|
|
2005-07-17 07:06:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|