<commit_before>#!/usr/bin/env node
'use strict';
var Tail = require('always-tail');
var fs = require('fs');
var clc = require('cli-color');
var program = require('commander');

program
	.version('0.0.3')
	.option('-f, --file [value]', 'Add file path')
	.option('-i, --interval <n>', 'Set interval')
	.option('-r, --regex [value]', 'Set regex')
	.option('-d, --delim [value]', 'Set delimeter')
	.parse(process.argv);

var filename = program.file;
var interval = program.interval || 1000;
var regex = program.regex || '';
var delim = program.delim || '\n';

if (!filename) {
	console.error('no select file');
	program.outputHelp();
	process.exit(1);
}

if (!fs.existsSync(filename)) {
	fs.writeFileSync(filename, '');
}

var tail = new Tail(filename, delim, {interval: interval});

tail.on('line', function (data) {
	var tailReg = new RegExp(regex, 'g');
	var prevCursor = 0;
	var result;

	if ((result = tailReg.exec(data))) {
		var resultColoredString = '';
		do {
			var coloredString = data.substring(result.index, tailReg.lastIndex);

			resultColoredString +=
				(data.substring(prevCursor, result.index) + clc.red(coloredString));
			prevCursor = tailReg.lastIndex;
		} while ((result = tailReg.exec(data)) !== null);

		console.log(resultColoredString + data.substring(prevCursor, data.length));
	} else {
		console.log(data);
	}
});

tail.watch();<commit_msg>bug fix<commit_after>#!/usr/bin/env node
'use strict';
var Tail = require('always-tail');
var fs = require('fs');
var clc = require('cli-color');
var program = require('commander');

program
	.version('0.0.3')
	.option('-f, --file [value]', 'Add file path')
	.option('-i, --interval <n>', 'Set interval')
	.option('-r, --regex [value]', 'Set regex')
	.option('-d, --delim [value]', 'Set delimeter')
	.parse(process.argv);

var filename = program.file;
var interval = program.interval || 1000;
var regex = program.regex;
var delim = program.delim || '\n';

if (!filename) {
	console.error('no select file');
	program.outputHelp();
	process.exit(1);
}

if (!fs.existsSync(filename)) {
	fs.writeFileSync(filename, '');
}

var tail = new Tail(filename, delim, {interval: interval});

tail.on('line', function (data) {
	var tailReg = new RegExp(regex, 'g');
	var prevCursor = 0;
	var result;

	if ((result = tailReg.exec(data)) && regex) {
		var resultColoredString = '';
		do {
			var coloredString = data.substring(result.index, tailReg.lastIndex);

			resultColoredString +=
				(data.substring(prevCursor, result.index) + clc.red(coloredString));
			prevCursor = tailReg.lastIndex;
		} while ((result = tailReg.exec(data)) !== null);

		console.log(resultColoredString + data.substring(prevCursor, data.length));
	} else {
		console.log(data);
	}
});

tail.watch();
{'fraction_non_alphanumeric': 0.1933357744415965, 'fraction_numerical': 0.006590992310508971, 'mean_word_length': 4.508064516129032, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '386489', 'n_tokens_mistral': 988, 'n_tokens_neox': 935, 'n_words': 221}