<commit_before>'use strict';
const electron = require('electron');
const app = electron.app;
const ipcMain = require('electron').ipcMain;
const	BrowserWindow = electron.BrowserWindow;
const pty = require('pty.js');
const net = require('net');
const simpleGit = require('simple-git');

// Require the child_process module so we can communicate with the user's terminal
const exec = require('child_process').exec;

var mainWindow = null;
// What does it mean for a JS object to be garbage collected?

app.on('window-all-closed', function() {
	if (process.platform !== 'darwin') {
		app.quit();
	}
});

app.on('ready', function() {
	mainWindow = new BrowserWindow({width: 1200, height: 700});
	mainWindow.loadURL('file://' + __dirname + '/index.html');

var currDir;
	var ptyTerm = pty.spawn('bash', [], {
		name: 'xterm-color',
		cols: 80,
		rows: 50,
		cwd: process.env.HOME,
		env: process.env
	});

//
	mainWindow.webContents.on('did-finish-load', function() {
	mainWindow.webContents.send('term-start-data', process.env.HOME + ' $ ');
	mainWindow.webContents.send('curr-dir', process.env.HOME)
});

	// sets the terminal prompt to pwd
	ptyTerm.write(`PROMPT_COMMAND='PS1=$(pwd)" $ "'\r`)
	ipcMain.on('command-message', function(event, arg) {
		ptyTerm.write(arg);
		ptyTerm.removeAllListeners('data');
		ptyTerm.on('data', function(data) {
			event.sender.send('terminal-reply', data);
			//crude way to find path, need to improve
			var re = /\s[$]\s/g;
			if (data.match(re)) {
				var temp = data;
				temp = temp.replace(re,'');
				currDir = temp;
				event.sender.send('curr-dir', currDir);
				animationDataSchema(event,currDir)
			}
		});
	});

 

simpleGit().status((err,i) =>{
	console.log(i);
})


// child process that gets all items in a directory
function animationDataSchema(event,pwd){
	var command = 'cd ' + pwd + ';ls -a';
	exec(command, function(err, stdout, stderr) {
			if (err) {
				console.log(err.toString());
			} else {
				var stdoutArr = stdout.split('\n');
				var current = currDir.replace(/(.*[\\\/])/,'')
				var modifiedFiles;
				simpleGit(pwd).status((err, i)=>{
					modifiedFiles = i.modified;
					console.log(modifiedFiles);
					var schema = schemaMaker(stdoutArr,current, modifiedFiles);
					event.sender.send('direc-schema', schema);
				})
			}
	});
}

// makes schema of new directory
function schemaMaker(termOutput, directoryName, modified){
	var schema = {
		"name": directoryName,
		"children": [],
		"value": 15
	};

	termOutput.forEach((index) => {
		// checks if file has any alphanumeric characters
		if (index.substring(0,4) === ".git" || !!index.match(/^\w/)) {
			var elementObj = {"name":index}
			if (index.substring(0,4) === ".git") elementObj.level = "black";
			// console.log(modified);
			for (var i = 0; i < modified.length; i++){
				if (modified[i] === index){
					elementObj.level = "red"
				}
			}
			schema.children.push(elementObj)
		}
	})
	schema = [schema]
	return schema;
}

<commit_msg>Added line of code from Hamza to prevent errors<commit_after>'use strict';
const electron = require('electron');
const app = electron.app;
const ipcMain = require('electron').ipcMain;
const	BrowserWindow = electron.BrowserWindow;
const pty = require('pty.js');
const net = require('net');
const simpleGit = require('simple-git');

// Require the child_process module so we can communicate with the user's terminal
const exec = require('child_process').exec;

var mainWindow = null;
// What does it mean for a JS object to be garbage collected?

app.on('window-all-closed', function() {
	if (process.platform !== 'darwin') {
		app.quit();
	}
});

app.on('ready', function() {
	mainWindow = new BrowserWindow({width: 1200, height: 700});
	mainWindow.loadURL('file://' + __dirname + '/index.html');

var currDir;
	var ptyTerm = pty.spawn('bash', [], {
		name: 'xterm-color',
		cols: 80,
		rows: 50,
		cwd: process.env.HOME,
		env: process.env
	});

//
	mainWindow.webContents.on('did-finish-load', function() {
	mainWindow.webContents.send('term-start-data', process.env.HOME + ' $ ');
	mainWindow.webContents.send('curr-dir', process.env.HOME)
});

	// sets the terminal prompt to pwd
	ptyTerm.write(`PROMPT_COMMAND='PS1=$(pwd)" $ "'\r`)
	ipcMain.on('command-message', function(event, arg) {
		ptyTerm.write(arg);
		ptyTerm.removeAllListeners('data');
		ptyTerm.on('data', function(data) {
			event.sender.send('terminal-reply', data);
			//crude way to find path, need to improve
			var re = /\s[$]\s/g;
			if (data.match(re)) {
				var temp = data;
				temp = temp.replace(re,'');
				currDir = temp;
				event.sender.send('curr-dir', currDir);
				animationDataSchema(event,currDir)
			}
		});
	});



simpleGit().status((err,i) =>{
	console.log(i);
})


// child process that gets all items in a directory
function animationDataSchema(event,pwd){
	var command = 'cd ' + pwd + ';ls -a';
	exec(command, function(err, stdout, stderr) {
			if (err) {
				console.log(err.toString());
			} else {
				var stdoutArr = stdout.split('\n');
				var current = currDir.replace(/(.*[\\\/])/,'')
				var modifiedFiles;
				simpleGit(pwd).status((err, i)=>{
					modifiedFiles = i.modified;
					console.log(modifiedFiles);
					var schema = schemaMaker(stdoutArr,current, modifiedFiles);
					event.sender.send('direc-schema', schema);
				})
			}
	});
}

// makes schema of new directory
function schemaMaker(termOutput, directoryName, modified){
	var schema = {
		"name": directoryName,
		"children": [],
		"value": 15
	};

	termOutput.forEach((index) => {
		// checks if file has any alphanumeric characters
		if (index.substring(0,4) === ".git" || !!index.match(/^\w/)) {
			var elementObj = {"name":index}
			if (index.substring(0,4) === ".git") elementObj.level = "black";
			// console.log(modified);
			if (modified) {
				for (var i = 0; i < modified.length; i++){
					if (modified[i] === index){
						elementObj.level = "red"
					}
				}
			}	
			schema.children.push(elementObj)
		}
	})
	schema = [schema]
	return schema;
}


{'fraction_non_alphanumeric': 0.17887535458034373, 'fraction_numerical': 0.006340730852661438, 'mean_word_length': 3.757142857142857, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 9, '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': '1702334', 'n_tokens_mistral': 2295, 'n_tokens_neox': 2035, 'n_words': 472}