<commit_before>var _        = require('underscore');
var executor = require('./executor');
var logger   = require('./logger')(__filename);
var Terminal = require('blessings');

var terminal  = new Terminal();
var positions = {};
var maxBuildNameLength = 0;
var restPosition = {};

module.exports.start = function(){
	writeEverything();

	executor.on('statusChanged', function(buildName, status){
		if(status == 'building...'){
			writeEverything();
		} else {
			var position = positions[buildName];
			writeStatus(buildName, status, position.x, position.y);
			goToRestPosition();
		}
	});
};

function writeEverything(){
	terminal.hideCursor();
	terminal.clear();

	var position = { x: 3, y: 2 };

	var initialStatus = executor.getStatus();

	maxBuildNameLength = _.chain(initialStatus)
		.keys()
		.map(function(key){
			return key.length;
		})
		.max()
		.value();

	_.each(initialStatus, function(status, buildName){
		writeStatus(buildName, status, position.x, position.y);

		positions[buildName] = _.extend({}, position);
		position.y += 4;
	});

	restPosition = { x: 0, y : position.y+1 };
	goToRestPosition();
}

function writeStatus(buildName, status, x, y){
	terminal.write(terminal.move(x, y));
	terminal.clearLine();

	var verticalPaddingLine = format(new Array(maxBuildNameLength+3).join(" "), status);
	terminal.write(verticalPaddingLine);
	terminal.write(terminal.move(x, y+1));
	terminal.write(getFormattedBuildStatus(buildName, status));
	terminal.write(terminal.move(x, y+2));
	terminal.write(verticalPaddingLine);
}

function getFormattedBuildStatus(buildName, status){
	var label = center(buildName, maxBuildNameLength+2);
	return format(label, status);
}

function format(label, status){
	switch(status){
		case 'idle':
			return terminal.normal(label);
		case 'building...':
			return terminal.black(terminal.bg.yellow(label));<commit_msg>Animated status when builds are in progress.<commit_after>var _        = require('underscore');
var executor = require('./executor');
var logger   = require('./logger')(__filename);
var Terminal = require('blessings');

var terminal  = new Terminal();
var positions = {};
var maxBuildNameLength = 0;
var restPosition = {};
var animations = {};

module.exports.start = function(){
	writeEverything();

	executor.on('statusChanged', function(buildName, status){
		if(status == 'building...'){
			writeEverything();
		} else {
			var position = positions[buildName];
			writeStatus(buildName, status, position.x, position.y);
			goToRestPosition();
		}
	});
};

function writeEverything(){
	terminal.hideCursor();
	terminal.clear();

	var position = { x: 3, y: 1 };

	var initialStatus = executor.getStatus();

	maxBuildNameLength = _.chain(initialStatus)
		.keys()
		.map(function(key){
			return key.length;
		})
		.max()
		.value();

	_.each(initialStatus, function(status, buildName){
		position.y += 1;
		writeStatus(buildName, status, position.x, position.y);

		positions[buildName] = _.extend({}, position);
		position.y += 3;
	});

	restPosition = { x: 0, y : position.y };
	goToRestPosition();
}

function writeStatus(buildName, status, x, y){
	terminal.write(terminal.move(x, y));
	terminal.clearLine();

	var verticalPaddingLine = format(new Array(maxBuildNameLength+3).join(" "), status);
	terminal.write(verticalPaddingLine);
	terminal.write(terminal.move(x, y+1));
	terminal.write(getFormattedBuildStatus(buildName, status));
	terminal.write(terminal.move(x, y+2));
	terminal.write(verticalPaddingLine);

	if(animations[buildName]){
		clearInterval(animations[buildName]);
		animations[buildName] = null;
	}

	if(status == 'building...'){
		var animationShowText = true;

		animations[buildName] = setInterval(function(){
			var text = (animationShowText ^= 1)
				? buildName
				: "";
			var position = positions[buildName];
			terminal.write(terminal.move(position.x, position.y + 1));
			terminal.write(getFormattedBuildStatus(text, status));
			goToRestPosition();
		}, 750);
	}
}

function getFormattedBuildStatus(buildName, status){
	var label = center(buildName, maxBuildNameLength+2);
	return format(label, status);
}

function format(label, status){
	switch(status){
		case 'idle':
			return terminal.normal(label);
		case 'building...':
			return terminal.black(terminal.bg.yellow(label));
{'fraction_non_alphanumeric': 0.15953216374269005, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 5.091168091168091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1918517', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1326, 'n_words': 279}