<commit_before>#!/usr/bin/env node

'use strict';

var fs = require('fs');
var getStdin = require('get-stdin');
var ttys = require('ttys');
var argv = require('minimist')(process.argv.slice(2), {
	boolean: ['debug', 'help', 'multiple', 'copy', 'version', 'no-ttys', 'no-trim'],
	alias: {
		d: 'debug',
		e: 'file-encoding',
		h: 'help',
		m: 'multiple',
		c: 'copy',
		s: 'separator',
		t: 'no-trim',
		v: 'version'
	}
});
var filePath = argv._[0];

function startIpt(input) {
	require('./')(process, (argv['no-ttys'] ? process : ttys), console, argv, input, error);
}

function error(e, msg) {
	console.error(argv.debug ? e : msg);
	process.exit(1);
}

if (filePath) {
	fs.readFile(filePath, {
		encoding: argv['file-encoding'] || 'utf8'
	}, function (err, data) {
		if (err) {
			error(err, 'Error reading file from path');
		} else {
			startIpt(data);
		}
	});
} else {
	getStdin().then(function (data) {
		startIpt(data);
	}).catch(function (err) {
		error(err, 'Error while reading stdin');
	});
}
<commit_msg>fixes #6 - exit pressing escape or q<commit_after>#!/usr/bin/env node

'use strict';

var fs = require('fs');
var getStdin = require('get-stdin');
var ttys = require('ttys');
var argv = require('minimist')(process.argv.slice(2), {
	boolean: ['debug', 'help', 'multiple', 'copy', 'version', 'no-ttys', 'no-trim'],
	alias: {
		d: 'debug',
		e: 'file-encoding',
		h: 'help',
		m: 'multiple',
		c: 'copy',
		s: 'separator',
		t: 'no-trim',
		v: 'version'
	}
});
var filePath = argv._[0];

// Exits program execution on ESC or q keypress
process.stdin.on('keypress', function (ch, key) {
	if (key && (key.name === 'escape' || key.name === 'q')) {
		process.exit();
	}
});

function startIpt(input) {
	require('./')(process, (argv['no-ttys'] ? process : ttys), console, argv, input, error);
}

function error(e, msg) {
	console.error(argv.debug ? e : msg);
	process.exit(1);
}

if (filePath) {
	fs.readFile(filePath, {
		encoding: argv['file-encoding'] || 'utf8'
	}, function (err, data) {
		if (err) {
			error(err, 'Error reading file from path');
		} else {
			startIpt(data);
		}
	});
} else {
	getStdin().then(function (data) {
		startIpt(data);
	}).catch(function (err) {
		error(err, 'Error while reading stdin');
	});
}
{'fraction_non_alphanumeric': 0.22038444345105052, 'fraction_numerical': 0.004023245417970496, 'mean_word_length': 4.086363636363636, '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': '6757461', 'n_tokens_mistral': 910, 'n_tokens_neox': 871, 'n_words': 207}