Skip to content

Commit

Permalink
Merge pull request #79 from hlegendre/hlegendre-patch-tailcolorcycle
Browse files Browse the repository at this point in the history
In console tail, each app gets its own color.
  • Loading branch information
typicode committed Jun 18, 2015
2 parents d0317f0 + 7852216 commit a48a394
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/cli/commands/tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,28 @@ function getHostName(cwd) {
return hostNames[0]
}

var COLORS = ['blue', 'magenta', 'green', 'yellow', 'cyan', 'gray'];
var mappingColors = {};
var idx = 0;

function colorPrefix (prefix) {
if (!mappingColors.hasOwnProperty(prefix)) {
if (idx >= COLORS.length) {
idx = 0;
}
mappingColors[prefix] = COLORS[idx++];
}
return chalk[mappingColors[prefix]](prefix);
}


module.exports = function(args) {
var host = args[0] || getHostName(process.cwd())
var tail = new Tail(host, INITIAL_LINES);
tail
.on('line', function(prefix, line) {
if (prefix)
process.stdout.write(chalk.blue('[' + prefix + '] '))
process.stdout.write(colorPrefix('[' + prefix + '] '))
process.stdout.write(line + '\n')
})
.on('error', function(error) {
Expand Down

0 comments on commit a48a394

Please sign in to comment.