Method: Inspec::UI#table
- Defined in:
- lib/inspec/ui.rb
#table(opts = { print: true }) {|the_table| ... } ⇒ Object
Makes a table. Call with a block; block arg will be a TTY::Table object, with an extension for setting the header. Typical use: ui.table do |t|
t.header = ['Name', 'Rank', 'Cereal Number']
t << ['Crunch', 'Captain', 1]
t << ['', '', 1]
end
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/inspec/ui.rb', line 168 def table(opts = { print: true }) require "inspec/ui_table_helper" the_table = TableHelper.new yield(the_table) colorizer = proc do |data, row, _col| if color? && row == 0 ANSI_CODES[:bold] + ANSI_CODES[:color][:white] + data.to_s + ANSI_CODES[:reset] else data end end render_mode = color? ? :unicode : :ascii padding = [0, 1, 0, 1] # T R B L result = the_table.render(render_mode, filter: colorizer, padding: padding) + "\n" print_or_return(result, opts[:print]) end |