<commit_before>var sgr = require('./sgr');

var CSI_PATTERN = /^\x1b\[([?!>]?)([0-9;]*)([@A-Za-z`]?)/;

function parseCsi(data) {
	var match = CSI_PATTERN.exec(data)
	if(match === null)
		return null
	return {
		args: match[2] === "" ? [] : match[2].split(';'),
		mod: match[1],
		cmd: match[3],
		offset: match[0].length
	};
}

exports.chr = "[";
exports.exec = function(term, data) {
	var match = parseCsi(data);
	if(match === null || (match.offset != data.length && match.cmd === '')) {
		console.log("Garbaged CSI: " + (match ? data.slice(0, match.offset+1) : "unknown"));
		// Consume escape character.
		return 1;
	}
	var n = match.args[0], m = match.args[1];
	switch(match.cmd) {
	case '': // Unfinished sequence.
		return 0;
	case '@': // ICH
		term.insertBlanks(n || 1);
		break;
	case 'A': // CUU
		term.mvCur(0, -(n || 1));
		break;
	case 'B': // CUD
		term.mvCur(0, n || 1);
		break;
	case 'C': // CUF
	case 'a': // HPR
		term.mvCur(n || 1, 0);
		break;
	case 'D': // CUB
		term.mvCur(-(n || 1), 0);
		break;
	case 'E': // CNL
		term.mvCur(0, n || 1).setCur({x: 0});
		break;
	case 'F': // CPL
		term.mvCur(0, -(n || 1)).setCur({x: 0});
		break;
	case '`': // HPA
	case 'G': // CHA
		term.setCur({x: (n || 1) - 1});
		break;
	case 'f': // HVP
	case 'H': // CUP
		term.setCur({y: (n || 1) - 1, x: (m || 1) - 1});
		break;
	case 'I': // CHT
		term.mvTab(n || 1);
		break;
	case 'J': // ED / DECSED
		term.eraseInDisplay(n);
		break;
	case 'K': // EL / DECSEL
		term.eraseInLine(n);
		break;
	case 'L': // IL
		term.insertLines(n || 1);
		break;
	case 'P': // DCH
		term.deleteCharacter(n || 1);
		break;
	case 'S': // SU
		term.scroll('up');
		break
	case 'T': // SD / Initiate highlight mouse tracking
		if(match.args === 0)
			term.scroll('down');<commit_msg>Correctly cast csi-args to number<commit_after>var sgr = require('./sgr');

var CSI_PATTERN = /^\x1b\[([?!>]?)([0-9;]*)([@A-Za-z`]?)/;

function parseCsi(data) {
	var match = CSI_PATTERN.exec(data)
	if(match === null)
		return null
	return {
		args: match[2] === "" ? [] : match[2].split(';'),
		mod: match[1],
		cmd: match[3],
		offset: match[0].length
	};
}

exports.chr = "[";
exports.exec = function(term, data) {
	var match = parseCsi(data);
	if(match === null || (match.offset != data.length && match.cmd === '')) {
		console.log("Garbaged CSI: " + (match ? data.slice(0, match.offset+1) : "unknown"));
		// Consume escape character.
		return 1;
	}
	var n = +match.args[0], m = +match.args[1];
	switch(match.cmd) {
	case '': // Unfinished sequence.
		return 0;
	case '@': // ICH
		term.insertBlanks(n || 1);
		break;
	case 'A': // CUU
		term.mvCur(0, -n || 1);
		break;
	case 'B': // CUD
		term.mvCur(0, n || 1);
		break;
	case 'C': // CUF
	case 'a': // HPR
		term.mvCur(n || 1, 0);
		break;
	case 'D': // CUB
		term.mvCur(-n || 1, 0);
		break;
	case 'E': // CNL
		term.mvCur(0, n || 1).setCur({x: 0});
		break;
	case 'F': // CPL
		term.mvCur(0, -n || 1).setCur({x: 0});
		break;
	case '`': // HPA
	case 'G': // CHA
		term.setCur({x: (n || 1) - 1});
		break;
	case 'f': // HVP
	case 'H': // CUP
		term.setCur({y: (n || 1) - 1, x: (m || 1) - 1});
		break;
	case 'I': // CHT
		term.mvTab(n || 1);
		break;
	case 'J': // ED / DECSED
		term.eraseInDisplay(n);
		break;
	case 'K': // EL / DECSEL
		term.eraseInLine(n);
		break;
	case 'L': // IL
		term.insertLines(n || 1);
		break;
	case 'P': // DCH
		term.deleteCharacter(n || 1);
		break;
	case 'S': // SU
		term.scroll('up');
		break
	case 'T': // SD / Initiate highlight mouse tracking
		if(match.args === 0)
			term.scroll('down');
{'fraction_non_alphanumeric': 0.24311410905002812, 'fraction_numerical': 0.021922428330522766, 'mean_word_length': 2.7861702127659576, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3972219', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1535, 'n_words': 365}