"use strict";

var prettyTime = require('pretty-hrtime');
var chalk = require('chalk');
var util = require('util');

module.exports = function (flit) {
    var logger = flit.logger;
    var index = 0;

    flit.on('start', function () {
        index = 0;
        logger.info(chalk.info('Starting')
            , chalk.warn('(' + flit.seq.join(',') + ')'), '->', chalk.warn(flit.ctx.destination || 'localhost')
            , chalk.info('with ') + chalk.magenta(String(flit.seq.length)) + chalk.info(' task(s)'));
        logger.space();
    });

    flit.on('task_start', function (tinfo) {
        index++;
        logger.info(chalk.info('Task'), logger.format(chalk.magenta('%s/%s'), index, flit.seq.length)
            , chalk.warn('[' + tinfo.task + ']'), chalk.info('launched...'));
        logger.space();
    });

    flit.on('task_stop', function (tinfo) {
        logger.success(chalk.success('Task'), index, chalk.success('executed after'), chalk.magenta(prettyTime(tinfo.hrDuration)));
        logger.space();
    });

    flit.on('task_err', function (tinfo) {
        var err = !tinfo.err ? '' : logger.format('when %s', tinfo.err);
        logger.error(chalk.error('Task'), index, chalk.error('aborted after'), chalk.magenta(prettyTime(tinfo.hrDuration)), err);
        logger.space();
    });

    flit.on('err', function (err) {
        if (err && ~err.message.indexOf('failed')) {
            if (util.isError(err.err)) {
                throw err.err;
            }
            logger.error(chalk.error('Execution failed:'), err.err);
        } else {
            logger.error(chalk.error('Execution aborted' + (flit.elapse ? ' after' : '')), chalk.magenta(prettyTime(flit.elapse)));
        }
    });

    flit.on('stop', function () {
        logger.success(chalk.success('Execution finished' + (flit.elapse ? ' after' : '')), chalk.magenta(prettyTime(flit.elapse)));
    });
};
@@ -1407,33 +1407,63 @@
     
-if (util.isError(
+logger.error(chalk.error('Execution failed:'), 
 err.err)
 ) %7B%0A
@@ -1458,19 +1458,17 @@
 err.err)
-) %7B
+;
 %0A       
@@ -1476,41 +1476,43 @@
     
-    throw 
+if (util.isError(
 err.err
-;
+)) %7B
 %0A      
-      %7D%0A
     
@@ -1509,34 +1509,32 @@
                 
-  
 logger.error(cha
@@ -1534,51 +1534,31 @@
 ror(
-chalk.error('Execution failed:'), err.err);
+err.err);%0A            %7D
 %0A   

print errors but not throw when task error