Skip to content

Commit

Permalink
In console tail, each app gets its own color.
Browse files Browse the repository at this point in the history
Instead of coloring all the prefix (the app name) in blue, we assign a different color to each app. If more than 6, we might assign the same color to two apps.

Useful for me anyway. You might want to pull it.
  • Loading branch information
hlegendre committed Jun 18, 2015
1 parent d0317f0 commit 7852216
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 7852216

Please sign in to comment.