Skip to content

Commit

Permalink
switch out tables
Browse files Browse the repository at this point in the history
  • Loading branch information
GantMan committed Nov 12, 2017
1 parent bead431 commit 7477316
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 57 deletions.
92 changes: 42 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"dependencies": {
"apisauce": "^0.14.1",
"app-module-path": "^2.2.0",
"ascii-table": "^0.0.9",
"colors": "^1.1.2",
"cross-spawn": "^5.1.0",
"ejs": "^2.5.7",
Expand Down Expand Up @@ -71,6 +70,7 @@
"ramda": "^0.24.1",
"ramdasauce": "^2.1.0",
"semver": "^5.3.0",
"table": "^4.0.2",
"toml": "^2.3.2",
"which": "^1.2.14"
},
Expand Down
40 changes: 35 additions & 5 deletions src/utils/print.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const colors = require('colors')
const AsciiTable = require('ascii-table')
const { table: asciiTable, getBorderCharacters } = require('table')
const ora = require('ora')

/**
Expand Down Expand Up @@ -40,10 +40,40 @@ function divider () {
* @param {{}} object The object to turn into a table.
*/
function table (data, options) {
const t = new AsciiTable()
t.addRowMatrix(data)
t.removeBorder()
console.log(t.toString())
let tableDesign
if (options) {
if (options.markdown) {
// hopefully a new template coming soon
// https://github.com/gajus/table/issues/53
tableDesign = asciiTable(data, {
border: {
topBody: '',
topJoin: '',
topLeft: '',
topRight: '',
bottomBody: '',
bottomJoin: '',
bottomLeft: '',
bottomRight: '',
bodyLeft: '|',
bodyRight: '|',
bodyJoin: '|',
joinBody: '-',
joinLeft: '|',
joinRight: '|',
joinJoin: '|'
},
drawHorizontalLine: (index) => index === 1,
...options
})
} else {
tableDesign = asciiTable(data, options)
}
} else {
// default no frills table
tableDesign = asciiTable(data, {border: getBorderCharacters(`void`), drawHorizontalLine: () => false})
}
console.log(tableDesign)
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/utils/print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ test.serial('table', t => {
['matthew', '2']
]
print.table(data)
t.is(spyLog.args[i++][0], ' liam 5 \n matthew 2 ')
t.is(spyLog.args[i++][0], ' liam 5 \n matthew 2 \n')
print.table(data, {})
t.is(spyLog.args[i++][0], '╔═════════╤═══╗\n║ liam │ 5 ║\n╟─────────┼───╢\n║ matthew │ 2 ║\n╚═════════╧═══╝\n')
print.table(data, {markdown: true})
t.is(spyLog.args[i++][0], '| liam | 5 |\n|---------|---|\n| matthew | 2 |\n')
})

test.serial('spin', t => {
Expand Down

0 comments on commit 7477316

Please sign in to comment.