Skip to content

Commit

Permalink
Fix yargs printing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkGriffiths committed Nov 5, 2018
1 parent 4db5237 commit b0b3427
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const consoleFactory = function (options = {}) {
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
},

yargs(obj) {
yargs(obj, color = true) {
const parsed = {};
Object.keys(obj).forEach(key_ => {
const val = obj[key_];
Expand All @@ -211,8 +211,8 @@ const consoleFactory = function (options = {}) {
}
});
sOut.write(format('Options (yargs):\n %s\n', inspect(parsed, {
colors: termNG.color.basic
}).slice(2, -1).replace(/:/g, ' ▸').replace(/,\n/g, '\n')));
colors: color && termNG.color.basic
}).slice(2, -1).replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
}

});
Expand Down
6 changes: 3 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const consoleFactory = function (options = {}) {
}).slice(0, -1).replace(/^{/, 'Object\n ').replace(/^\[/, 'Array\n ').replace(/^(\w+) {/, '$1').replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
},

yargs(obj) {
yargs(obj, color = true) {
const parsed = {};
Object.keys(obj).forEach(key_ => {
const val = obj[key_];
Expand All @@ -205,8 +205,8 @@ const consoleFactory = function (options = {}) {
}
});
sOut.write(format('Options (yargs):\n %s\n', inspect(parsed, {
colors: termNG.color.basic
}).slice(2, -1).replace(/:/g, ' ▸').replace(/,\n/g, '\n')));
colors: color && termNG.color.basic
}).slice(2, -1).replace(/(\w+):/g, '$1 ▸').replace(/,\n/g, '\n')));
}

});
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const consoleFactory = function (options = {}) {
* Pretty prints object, similar to OS X's plutil -p. Defaults to zero depth.
* @param {Object} obj The Object to print.
* @param {Number} depth How many object levels to print.
* @param {Boolean} color Print output in color, of supported.
* @param {Boolean} color Print output in color, if supported.
* @example
* console.pretty(console)
*
Expand Down Expand Up @@ -322,6 +322,7 @@ const consoleFactory = function (options = {}) {
*
* Only prints 'long options', `._` as 'arguments' and `$0` as 'self'.
* @param {Object} obj The Yargs argv object to print.
* @param {Boolean} color Print output in color, if supported.
* @example
* console.yargs(yargs)
*
Expand All @@ -334,7 +335,7 @@ const consoleFactory = function (options = {}) {
* ...
* self ▸ '/usr/local/bin/truwrap'
*/
yargs(obj) {
yargs(obj, color = true) {
const parsed = {}
Object.keys(obj).forEach(key_ => {
const val = obj[key_]
Expand All @@ -354,10 +355,10 @@ const consoleFactory = function (options = {}) {
}
})
sOut.write(format('Options (yargs):\n %s\n', inspect(parsed, {
colors: termNG.color.basic
colors: color && termNG.color.basic
})
.slice(2, -1)
.replace(/:/g, ' ▸')
.replace(/(\w+):/g, '$1 ▸')
.replace(/,\n/g, '\n')))
}
})
Expand Down
10 changes: 10 additions & 0 deletions test/obejcts.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ test('Object dir print', t => {
const result = StreamProxy.read()
t.is(result, "{ test: 'Testing', another: { level: 'deep' } }")
})

test('Object yargs print', t => {
testConsole.yargs({
_: ['one', 'two', 'three'],
$0: 'self',
test: 'Testing'
}, false)
const result = StreamProxy.read()
t.is(result, "Options (yargs):\n arguments ▸ 'one two three', self ▸ 'self', test ▸ 'Testing' \n")
})

0 comments on commit b0b3427

Please sign in to comment.