From: XhmikosR Date: Wed, 24 Dec 2014 12:32:59 +0000 (+0200) Subject: Switch to chalk for coloring the terminal. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ac950bd3ce5f65c70a572e034c99549dcc618e50;p=html-minifier.git Switch to chalk for coloring the terminal. --- diff --git a/benchmark.js b/benchmark.js index bd4402d..c394ce6 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,10 +1,11 @@ #!/usr/bin/env node -/* jshint strict:false */ +'use strict'; var fs = require('fs'), path = require('path'), exec = require('child_process').exec, + chalk = require('chalk'), Table = require('cli-table'); var fileNames = [ @@ -28,34 +29,32 @@ var table = new Table({ colWidths: [20, 25, 25, 20, 20] }); -console.log(''); - function toKb(size) { return (size / 1024).toFixed(2); } function redSize(size) { - return '\033[91m' + size + '\033[0m (' + toKb(size) + 'KB)'; + return chalk.red.bold(size) + chalk.white(' (' + toKb(size) + ' KB)'); } function greenSize(size) { - return '\033[92m' + size + '\033[0m (' + toKb(size) + 'KB)'; + return chalk.green.bold(size) + chalk.white(' (' + toKb(size) + ' KB)'); } function blueSavings(oldSize, newSize) { var savingsPercent = (1 - newSize / oldSize) * 100; var savings = (oldSize - newSize) / 1024; - return '\033[96m' + savingsPercent.toFixed(2) + '\033[0m% (' + savings.toFixed(2) + 'KB)'; + return chalk.cyan.bold(savingsPercent.toFixed(2)) + chalk.white('% (' + savings.toFixed(2) + ' KB)'); } function blueTime(time) { - return '\033[96m' + time + '\033[0mms'; + return chalk.cyan.bold(time) + chalk.white(' ms'); } function test(fileName, done) { if (!fileName) { - console.log(table.toString()); + console.log('\n' + table.toString()); return; } diff --git a/package.json b/package.json index a45da7d..1915de0 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "relateurl": "0.2.x" }, "devDependencies": { + "chalk": "0.5.x", "cli-table": "0.3.x", "grunt": "0.4.x", "grunt-contrib-concat": "0.5.x",