| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- module.exports = class TableKit {
- titles
- colWidth
- tableCharacter
- constructor(titles, colWidth=30, tableCharacter='#') {
- this.titles = titles
- this.colWidth = colWidth
- this.tableCharacter = tableCharacter
- this.splitLine = ''.padEnd((colWidth + 2) * this.titles.length + 1, this.tableCharacter)
- }
- printTitles() {
- const padTitles = this.titles.map((title) => {
- return title.padEnd(this.colWidth, ' ')
- })
- const titleLine = (() => {
- let titleLine = ''
- for (const padTitle of padTitles) {
- titleLine = titleLine.concat(this.tableCharacter).concat(' ').concat(padTitle)
- }
- return titleLine.concat(this.tableCharacter)
- })()
- console.clear()
- console.info(this.splitLine)
- console.info(titleLine)
- console.info(this.splitLine)
- }
- showLine(rows=[], fileLogger=undefined) {
- const padRows = rows.map((col) => {
- return col.padEnd(this.colWidth, ' ')
- })
- const infoLine = (() => {
- let infoLine = ''
- for (const padRow of padRows) {
- infoLine = infoLine.concat(this.tableCharacter).concat(' ').concat(padRow)
- }
- return infoLine.concat(this.tableCharacter)
- })()
- console.info(infoLine)
- if (fileLogger) fileLogger.info(infoLine)
- }
- printEndLine() {
- console.info(this.splitLine)
- }
- }
|