/*!
 * 在控制台支持多彩日志显示
 * https://github.com/aui/tmodjs
 * Released under the MIT, BSD, and GPL Licenses
 */

'use strict';

var styles = {
    // styles
    'bold'      : ['\x1B[1m',  '\x1B[22m'],
    'italic'    : ['\x1B[3m',  '\x1B[23m'],
    'underline' : ['\x1B[4m',  '\x1B[24m'],
    'inverse'   : ['\x1B[7m',  '\x1B[27m'],
    // colors
    'white'     : ['\x1B[37m', '\x1B[39m'],
    'grey'      : ['\x1B[90m', '\x1B[39m'],
    'black'     : ['\x1B[30m', '\x1B[39m'],
    'blue'      : ['\x1B[34m', '\x1B[39m'],
    'cyan'      : ['\x1B[36m', '\x1B[39m'],
    'green'     : ['\x1B[32m', '\x1B[39m'],
    'magenta'   : ['\x1B[35m', '\x1B[39m'],
    'red'       : ['\x1B[31m', '\x1B[39m'],
    'yellow'    : ['\x1B[33m', '\x1B[39m']
};


styles['b'] = styles['bold'];
styles['i'] = styles['italic'];
styles['u'] = styles['underline'];

module.exports = function (message) {
    message = message.replace(/\[([^\]]*?)\]/igm, function ($1, $2) {
        return $2.indexOf('/') === 0
        ? styles[$2.slice(1)][1]
        : styles[$2][0];
    });


    process.stdout.write(message);
};

