diff --git a/lib/rex/ui/text/table.rb b/lib/rex/ui/text/table.rb index 56ca8a61a7..a7fc917082 100644 --- a/lib/rex/ui/text/table.rb +++ b/lib/rex/ui/text/table.rb @@ -212,6 +212,24 @@ class Table rows << '__hr__' end + # + # Returns new sub-table with headers and rows maching column names submitted + # + def [](*colnames) + tbl = self.class.new('Indent' => self.indent,'Header' => self.header,'Columns' => colnames) + idx = [] + colnames.each do |colname| + idx << self.columns.index(colname) + end + self.rows.each do |oldrow| + newrow = [] + idx.map {|i| newrow << oldrow[i]} + tbl << newrow + end + return tbl + end + + alias p print attr_accessor :header, :headeri # :nodoc: