Remove ANSI color codes when --tsv is defined
When TSV output is requested, the output should not contain the ANSI color codes. This appears to be a "feature" of the table generation library but it is quite simple to work around.
This commit is contained in:
@ -92,6 +92,15 @@ module.exports = function() {
|
|||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.tableToString = function(table) {
|
||||||
|
str = table.toString()
|
||||||
|
if (this.argv.tsv) {
|
||||||
|
// Based on the regex found in: https://github.com/jonschlinkert/strip-color
|
||||||
|
str = str.replace( /\x1B\[[(?);]{0,2}(;?\d)*./g, '')
|
||||||
|
}
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
// Get a resource as raw collection; a matrix of strings
|
// Get a resource as raw collection; a matrix of strings
|
||||||
this.getRawCollection = function (host, resource, fields) {
|
this.getRawCollection = function (host, resource, fields) {
|
||||||
return getJson(host, resource)
|
return getJson(host, resource)
|
||||||
@ -110,7 +119,7 @@ module.exports = function() {
|
|||||||
arr.forEach((row) => {
|
arr.forEach((row) => {
|
||||||
table.push(row)
|
table.push(row)
|
||||||
})
|
})
|
||||||
return table.toString()
|
return tableToString(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request a resource collection and format it as a table
|
// Request a resource collection and format it as a table
|
||||||
@ -148,7 +157,7 @@ module.exports = function() {
|
|||||||
table.push(row)
|
table.push(row)
|
||||||
})
|
})
|
||||||
|
|
||||||
return table.toString()
|
return tableToString(table)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +183,7 @@ module.exports = function() {
|
|||||||
table.push(o)
|
table.push(o)
|
||||||
})
|
})
|
||||||
|
|
||||||
return table.toString()
|
return tableToString(table)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user