joyent/node-triton#183 triton profile create should not use ANSI code styling if stdout isn't a TTY

Reviewed by: Orlando Vazquez <orlando@joyent.com>
Approved by: Orlando Vazquez <orlando@joyent.com>
This commit is contained in:
Trent Mick 2017-02-24 13:13:27 -08:00
parent b66939751d
commit d14ac041f4
3 changed files with 17 additions and 1 deletions

View File

@ -7,6 +7,9 @@ Known issues:
## not yet released ## not yet released
- [joyent/node-triton#183] `triton profile create` will no longer use ANSI
codes for styling if stdout isn't a TTY.
## 5.1.0 ## 5.1.0
- [joyent/node-triton#182] Add `-y, --yes` options to `triton profile create` - [joyent/node-triton#182] Add `-y, --yes` options to `triton profile create`

View File

@ -851,6 +851,18 @@ function ansiStylize(str, color) {
} }
/*
* Style the given string with ANSI style codes *if stdout is a TTY*.
*/
function ansiStylizeTty(str, color) {
if (!process.stdout.isTTY) {
return str;
} else {
return ansiStylize(str, color);
}
}
function indent(s, indentation) { function indent(s, indentation) {
if (!indentation) { if (!indentation) {
indentation = ' '; indentation = ' ';
@ -1096,6 +1108,7 @@ module.exports = {
cliSetupTritonApi: cliSetupTritonApi, cliSetupTritonApi: cliSetupTritonApi,
editInEditor: editInEditor, editInEditor: editInEditor,
ansiStylize: ansiStylize, ansiStylize: ansiStylize,
ansiStylizeTty: ansiStylizeTty,
indent: indent, indent: indent,
chomp: chomp, chomp: chomp,
generatePassword: generatePassword, generatePassword: generatePassword,

View File

@ -357,7 +357,7 @@ function _createProfile(opts, cb) {
return; return;
} }
console.log(common.ansiStylize('\n\n# Docker setup\n', 'bold')); console.log(common.ansiStylizeTty('\n\n# Docker setup\n', 'bold'));
console.log(wrap80('This section will setup authentication to ' + console.log(wrap80('This section will setup authentication to ' +
'Triton DataCenter\'s Docker endpoint using your account ' + 'Triton DataCenter\'s Docker endpoint using your account ' +
'and key information specified above. This is only required ' + 'and key information specified above. This is only required ' +