Skip to content

Commit

Permalink
Make warnings more visible by coloring them
Browse files Browse the repository at this point in the history
Warnings are currently easy to miss because they are visually indistinguishable
from other text. It would be better if we write 'Warning:' in bold
and color it in yellow, similar to deprecation warnings from the depd
package.

* If `process.stdout` is a terminal emulator: Use ANSI escape codes
to switch the text weight and color to bold and yellow, write 'Warning:' and
switch text style back to normal.
* Otherwise: Write the string 'Warning:' as usual.

ANSI escape codes are described here:
https://en.wikipedia.org/wiki/ANSI_escape_code
  • Loading branch information
Nawfel BENGHERBIA committed Mar 6, 2018
1 parent 6deedd0 commit cf59b65
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/convict.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,14 @@ let convict = function convict(def) {
let output_err_bufs = [types_err_buf, missing_err_buf];

if (options.allowed === ALLOWED_OPTION_WARN && params_err_buf.length) {
global.console.log('Warning: '+ params_err_buf);
let warning = 'Warning:';
if (process.stdout.isTTY) {
// Write 'Warning:' in bold and in yellow
const SET_BOLD_YELLOW_TEXT = '\x1b[33;1m';
const RESET_ALL_ATTRIBUTES = '\x1b[0m';
warning = SET_BOLD_YELLOW_TEXT + warning + RESET_ALL_ATTRIBUTES;
}
global.console.log(warning + ' ' + params_err_buf);
} else if (options.allowed === ALLOWED_OPTION_STRICT) {
output_err_bufs.push(params_err_buf);
}
Expand Down

0 comments on commit cf59b65

Please sign in to comment.