From b0b34276019d7b5525bb05dd6769e39f81a76b48 Mon Sep 17 00:00:00 2001 From: Mark Griffiths Date: Mon, 5 Nov 2018 14:51:56 +0000 Subject: [PATCH] Fix yargs printing --- index.js | 6 +++--- index.mjs | 6 +++--- src/index.js | 9 +++++---- test/obejcts.js | 10 ++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index d9a4d44..29b013c 100644 --- a/index.js +++ b/index.js @@ -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_]; @@ -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'))); } }); diff --git a/index.mjs b/index.mjs index d51647a..1664524 100644 --- a/index.mjs +++ b/index.mjs @@ -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_]; @@ -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'))); } }); diff --git a/src/index.js b/src/index.js index 9089546..b5c12ed 100644 --- a/src/index.js +++ b/src/index.js @@ -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) * @@ -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) * @@ -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_] @@ -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'))) } }) diff --git a/test/obejcts.js b/test/obejcts.js index cbb8dd3..2854b2a 100644 --- a/test/obejcts.js +++ b/test/obejcts.js @@ -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") +})