balena-cli/lib/ui/widgets/table/table.coffee
2014-12-05 12:00:15 -04:00

24 lines
870 B
CoffeeScript

cliff = require('cliff')
tableHelpers = require('./table-helpers')
# TODO: Maybe there is a (sane) way to test this, given
# that the result is not automatically printed by cliff?
exports.horizontal = (contents, map, ordering, colours) ->
return if not contents?
contents = tableHelpers.processTableContents(contents, map)
ordering = tableHelpers.normaliseOrdering(ordering, contents)
return cliff.stringifyObjectRows(contents, ordering, colours)
exports.vertical = (contents, map, ordering) ->
return if not contents?
contents = tableHelpers.processTableContents(contents, map)
ordering = tableHelpers.normaliseOrdering(ordering, contents)
# TODO: Add some kind of separator to make clear
# when we're printing another content item
result = []
for item in contents
for next in ordering
result.push("#{next}: #{item[next]}")
return result.join('\n')