<commit_before>var EventEmitter = require('events').EventEmitter;
var fs = require('fs');
var _ = require('lodash');
var termianlMenu = require('terminal-menu');
var chalk = require('chalk');
var BaseTask = require('./libs/BaseTask');
var TaskManager = require('./libs/TaskManager');
var utils = require('./libs/Utils');
var Shell = require('./libs/Shell');
var logger = utils.logger;

var defaults = {
    title: '===============================================',
    subtitle: '-----------------------------------------',
    width: 100,
    x: 3,
    y: 2
};

var exit = function(code) {
    process.exit(code);
};

var createMenu = function(opts) {
    var options = opts || {};
    options = _.defaults(options, defaults);

    var taskMgr = new TaskManager(options);

    var emitter = new EventEmitter();

    var menu = termianlMenu({
        width: options.width,
        x: 3,
        y: 2
    });

    //clean up the terminal
    menu.reset();
    //display the title
    menu.write(chalk.bold(options.title) + '\n');
    //display the subtitle
    menu.write(chalk.italic(options.subtitle) + '\n');
    //display start separator
    menu.write(utils.repeat('-', options.width) + '\n');


    taskMgr.getTaskList().forEach(function(task, index) {
        menu.add(chalk.bold('»') + ' ' + task.name + utils.repeat(' ', options.width - task.name.length - 1));
    });

    //display end separator
    menu.write(utils.repeat('-', options.width) + '\n');
    //display help
    menu.add(chalk.bold('HELP'));
    //display exit
    menu.add(chalk.bold('EXIT'));

    menu.on('select', function(label, index) {
        var name = chalk.stripColor(label).replace(/(^»?\s+)/g, '');

        menu.y = 0;
        menu.reset();
        menu.close();

        if (name === 'EXIT') {
            return emitter.emit('exit');
        }

        if (name === 'HELP') {
            if (fs.existsSync(options.helpFile)) {
                utils.printFile(options.helpFile);
            }
            return;
        }

        var task = taskMgr.getTaskByIndex(index);

        var runner = taskMgr.run(task.id);

        runner.on('finish', function() {
            logger.success('finish: ', task.name);
        });

        runner.on('error', function(err) {
            logger.error('failed: ', err);
            exit(0);
        });

    });

    menu.createStream().pipe(process.stdout);

};

var TaskRunner = {
    Base: BaseTask,
    logger: logger,
    createMenu: createMenu,
    shell: Shell
};


module.exports = TaskRunner;<commit_msg>return emitter in index<commit_after>var EventEmitter = require('events').EventEmitter;
var fs = require('fs');
var _ = require('lodash');
var termianlMenu = require('terminal-menu');
var chalk = require('chalk');
var BaseTask = require('./libs/BaseTask');
var TaskManager = require('./libs/TaskManager');
var utils = require('./libs/Utils');
var Shell = require('./libs/Shell');
var logger = utils.logger;

var defaults = {
    title: '===============================================',
    subtitle: '-----------------------------------------',
    width: 100,
    x: 3,
    y: 2
};

var exit = function(code) {
    process.exit(code);
};

var createMenu = function(opts) {
    var options = opts || {};
    options = _.defaults(options, defaults);

    var taskMgr = new TaskManager(options);

    var emitter = new EventEmitter();

    var menu = termianlMenu({
        width: options.width,
        x: 3,
        y: 2
    });

    //clean up the terminal
    menu.reset();
    //display the title
    menu.write(chalk.bold(options.title) + '\n');
    //display the subtitle
    menu.write(chalk.italic(options.subtitle) + '\n');
    //display start separator
    menu.write(utils.repeat('-', options.width) + '\n');


    taskMgr.getTaskList().forEach(function(task, index) {
        menu.add(chalk.bold('»') + ' ' + task.name + utils.repeat(' ', options.width - task.name.length - 1));
    });

    //display end separator
    menu.write(utils.repeat('-', options.width) + '\n');
    //display help
    menu.add(chalk.bold('HELP'));
    //display exit
    menu.add(chalk.bold('EXIT'));

    menu.on('select', function(label, index) {
        var name = chalk.stripColor(label).replace(/(^»?\s+)/g, '');

        menu.y = 0;
        menu.reset();
        menu.close();

        if (name === 'EXIT') {
            return emitter.emit('exit');
        }

        if (name === 'HELP') {
            if (fs.existsSync(options.helpFile)) {
                utils.printFile(options.helpFile);
            }
            return;
        }

        var task = taskMgr.getTaskByIndex(index);

        var runner = taskMgr.run(task.id);

        runner.on('finish', function() {
            logger.success('finish: ', task.name);
        });

        runner.on('error', function(err) {
            logger.error('failed: ', err);
            exit(0);
        });

    });

    menu.createStream().pipe(process.stdout);
    return emitter;
};

var TaskRunner = {
    Base: BaseTask,
    logger: logger,
    createMenu: createMenu,
    shell: Shell
};


module.exports = TaskRunner;
{'fraction_non_alphanumeric': 0.20125171132407588, 'fraction_numerical': 0.003911597887737141, 'mean_word_length': 2.3057530704589526, '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': '6103279', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1530, 'n_words': 330}