From c2872774baeb0750fa23727dc5cc8f40633c650c Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Tue, 26 Jan 2016 00:28:03 +0100 Subject: [PATCH] Add symbol special keyword --- lib/Constants.coffee | 1 + lib/Default.coffee | 27 ++++++++++++++++++++++----- package.json | 1 + test/test.coffee | 4 ++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/Constants.coffee b/lib/Constants.coffee index 5595f84..bcb3671 100644 --- a/lib/Constants.coffee +++ b/lib/Constants.coffee @@ -4,4 +4,5 @@ module.exports = MIN_DIFF_MS: 10000 MUTED: 'silent' UNMUTED: 'all' + SYMBOL_KEYWORD: 'symbol' ENV: do -> process?.env.NODE_ENV?.toLowerCase() or undefined diff --git a/lib/Default.coffee b/lib/Default.coffee index 40a10a8..5957e38 100644 --- a/lib/Default.coffee +++ b/lib/Default.coffee @@ -1,9 +1,11 @@ 'use strict' -chalk = require 'chalk' humanizeMs = require 'ms' +chalk = require 'chalk' +figures = require 'figures' CONST = require './Constants' formatUtil = require 'format-util' + module.exports = print: -> for type of @types @@ -12,6 +14,8 @@ module.exports = outputMessage: (message) -> message outputType: (type) -> align = if @align then "\t" else " " + if @keyword + type = if @keyword is CONST.SYMBOL_KEYWORD then @types[type].symbol else type "#{type}#{align}" transport: console.log @@ -22,8 +26,6 @@ module.exports = colorType = @types[type].color message = @outputMessage message message = @colorize @types.line.color, message - - keyword = if @keyword? then @keyword else type diff = null if @diff @@ -35,7 +37,7 @@ module.exports = @diff[type] = new Date() diff = " +0ms" - messageType = @outputType keyword + messageType = @outputType type messageType = @colorize colorType, messageType output = messageType + message @@ -71,25 +73,40 @@ module.exports = types: line: - color: 'gray' + color : 'gray' + symbol: '' + error: level : 0 color : 'red' + symbol: figures.cross + warn: level : 1 color : 'yellow' + symbol: figures.warning + success: level : 2 color : 'green' + symbol: figures.tick + info: level : 3 color : 'white' + symbol: figures.info + verbose: level : 4 color : 'cyan' + symbol: figures.info + debug: level : 5 color : 'blue' + symbol: figures.info + silly: level : 6 color : 'magenta' + symbol: figures.info diff --git a/package.json b/package.json index 9663609..5f9c7a6 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "chalk": "~1.1.1", "coffee-script": "~1.10.0", "existential-assign": "~1.2.2", + "figures": "~1.4.0", "format-util": "1.0.3", "ms": "~0.7.1" }, diff --git a/test/test.coffee b/test/test.coffee index a03a6e6..0a3c87e 100755 --- a/test/test.coffee +++ b/test/test.coffee @@ -52,11 +52,15 @@ describe 'Acho ::', -> it 'specifying a keyword', -> printLogs Acho level: 'silly', color: true, keyword: 'acho' + it 'specifying a special "symbol" keyword', -> + printLogs Acho level: 'silly', color: true, keyword: 'symbol' + it 'enabling diff between logs', (done) -> acho = Acho level: 'silly' color: true diff: true + align: false printWarn = -> acho.warn 'hello world' printErr = -> acho.error 'oh noes!'