2012-06-29 00:18:28 -05:00
|
|
|
# -*- coding: binary -*-
|
2005-07-07 14:22:47 +00:00
|
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
module Ui
|
|
|
|
|
module Console
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
#
|
|
|
|
|
# Console table display wrapper that allows for stylized tables
|
|
|
|
|
#
|
|
|
|
|
###
|
2016-08-10 13:30:09 -05:00
|
|
|
class Table < Rex::Text::Table
|
2005-07-07 14:22:47 +00:00
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
|
# Default table styles.
|
|
|
|
|
#
|
2005-07-07 14:22:47 +00:00
|
|
|
module Style
|
|
|
|
|
Default = 0
|
|
|
|
|
end
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2020-07-07 13:46:41 +01:00
|
|
|
def self.new(*args, &block)
|
|
|
|
|
style, opts = args
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2020-07-07 13:46:41 +01:00
|
|
|
if style == Style::Default
|
2005-07-07 14:22:47 +00:00
|
|
|
opts['Indent'] = 3
|
2005-07-07 23:11:03 +00:00
|
|
|
if (!opts['Prefix'])
|
2005-07-10 08:36:53 +00:00
|
|
|
opts['Prefix'] = "\n"
|
2005-07-07 23:11:03 +00:00
|
|
|
end
|
|
|
|
|
if (!opts['Postfix'])
|
2005-07-14 20:18:36 +00:00
|
|
|
opts['Postfix'] = "\n"
|
2005-07-07 23:11:03 +00:00
|
|
|
end
|
2020-07-07 13:46:41 +01:00
|
|
|
end
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2020-07-07 13:46:41 +01:00
|
|
|
instance = super(opts, &block)
|
|
|
|
|
if style == Style::Default
|
|
|
|
|
instance.extend(DefaultStyle)
|
2005-07-07 14:22:47 +00:00
|
|
|
end
|
2020-07-07 13:46:41 +01:00
|
|
|
instance
|
2005-07-07 14:22:47 +00:00
|
|
|
end
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2020-07-07 13:46:41 +01:00
|
|
|
module DefaultStyle
|
|
|
|
|
#
|
|
|
|
|
# Print nothing if there are no rows if the style is default.
|
|
|
|
|
#
|
|
|
|
|
def to_s
|
2005-07-07 23:11:03 +00:00
|
|
|
return '' if (rows.length == 0)
|
2013-08-30 16:28:33 -05:00
|
|
|
|
2020-07-07 13:46:41 +01:00
|
|
|
super
|
|
|
|
|
end
|
2005-07-07 23:11:03 +00:00
|
|
|
end
|
2005-07-07 14:22:47 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-04-15 23:35:38 -05:00
|
|
|
end
|