<commit_before>/// <reference path="references.ts" />

module BlackScreen {
    export class Terminal extends EventEmitter {
        invocations: Array<Invocation>;
        currentDirectory: string;
        history: History;

        constructor(private dimensions: Dimensions) {
            super();
            this.currentDirectory = process.env.HOME;
            this.history = new History();

            Aliases.initialize();

            this.clearInvocations();
        }

        createInvocation(): void {
            var invocation = new Invocation(this.currentDirectory, this.dimensions, this.history);
            invocation.once('end', () => {
                this.createInvocation();
            }).once('working-directory-changed', (newWorkingDirectory: string) => {
                this.currentDirectory = newWorkingDirectory;
            });
            this.invocations = this.invocations.concat(invocation);
            this.emit('invocation');
        }

        resize(dimensions: Dimensions): void {
            this.dimensions = dimensions;

            this.invocations.forEach((invocation) => {
                invocation.resize(dimensions);
            });
        }

        clearInvocations(): void {
            this.invocations = [];
            this.createInvocation();
        }
    }
}

module.exports = BlackScreen.Terminal;<commit_msg>Restore state.<commit_after>/// <reference path="references.ts" />

var fs = require('fs');

module BlackScreen {
    export class Terminal extends EventEmitter {
        invocations: Array<Invocation>;
        currentDirectory: string;
        history: History;

        private stateFileName = `${process.env.HOME}/.black-screen-state`;

        constructor(private dimensions: Dimensions) {
            super();

            this.restore();

            this.history = new History();
            Aliases.initialize();

            this.clearInvocations();
        }

        createInvocation(): void {
            var invocation = new Invocation(this.currentDirectory, this.dimensions, this.history);
            invocation.once('end', () => {
                this.createInvocation();
            }).once('working-directory-changed', (newWorkingDirectory: string) => {
                this.currentDirectory = newWorkingDirectory;
                this.serialize();
            });
            this.invocations = this.invocations.concat(invocation);
            this.emit('invocation');
        }

        resize(dimensions: Dimensions): void {
            this.dimensions = dimensions;

            this.invocations.forEach((invocation) => {
                invocation.resize(dimensions);
            });
        }

        clearInvocations(): void {
            this.invocations = [];
            this.createInvocation();
        }

        private serialize(): void {
            fs.writeFile(this.stateFileName, JSON.stringify({
                currentDirectory: this.currentDirectory
            }), (error: any) => {
                if (error) debugger;
            })
        }

        private restore(): void {
            try {
                var state = JSON.parse(fs.readFileSync(this.stateFileName));
            } catch (error) {
                state = {currentDirectory: process.env.HOME};
            }

            this.currentDirectory = state.currentDirectory;
        }
    }
}

module.exports = BlackScreen.Terminal;
{'fraction_non_alphanumeric': 0.1149223101729698, 'fraction_numerical': 0.0, 'mean_word_length': 1.8268434134217066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '7081316', 'n_tokens_mistral': 857, 'n_tokens_neox': 804, 'n_words': 148}