<commit_before>var extend = require('../utils/extends.js');
var Widget = require('./widget.js');
var $ = require('../../core/libs/jquery-2.1.3.min.js');
var fu = require('../utils/file-utils.js');

function Terminal(gui, manager){
    Widget.call(this);
    this._element = $('<div class="se-terminal"></div>');
    this._focus = false;
    this._lines = [];
    this._treebeard = [];
    this._currentFolder = null;
    this._history = [];
    this._historyIndex = 0;

    var savedHistory = manager.localDb().get('COMMAND_HISTORY');
    if (savedHistory) {
        this._history = savedHistory;
    }

    var me = this;
    manager.registerShortcut('ctrl+c', function(e) {
        if (me.hasFocus()) {
            var lines = me._lines;
            if (lines.length) {
                var line = lines[lines.length - 1];
                line.find('.cursor').removeClass('cursor');
                me.addLine();
            }
            e.preventDefault();
        }
    });

    manager.registerShortcut('shift+ins', function(e) {
        if (me.hasFocus()) {
            var lines = me._lines;
            if (lines.length) {
                var line = lines[lines.length - 1];
                var clipboard = gui.Clipboard.get();
                var text = clipboard.get('text');
                var letters = text.split('');

                var cursor = line.find('.cursor');
                for (var i = 0; i < letters.length; i++) {
                    var letter = letters[i];
                    cursor.before(['<span>', letter, '</span>'].join(''));
                }
            }
            e.preventDefault();
        }
    });
    
    var searchNodeOnTree = function(tree, name) {
        for (var i = 0; i < tree.length; i++) {
            var node = tree[i];
            if (node.name == name) {
                return node;
            }
        }
        return false;
    };
    
    this._commands = {
        echo: function(args, terminal, done){
            terminal.printLine(args.join(' '));
            done();
        },
        openfolder: function(args, terminal, done) {
            if (args.length == 0) {
                terminal.printLine('No folder to open');
            } else {
                try {
                    me._treebeard = manager.action('OPEN_FOLDER', args[0]);
                    me._currentFolder = {name: '~', tree: me._treebeard.tree(), path: args[0]};
                } catch (e) {<commit_msg>exit command<commit_after>var extend = require('../utils/extends.js');
var Widget = require('./widget.js');
var $ = require('../../core/libs/jquery-2.1.3.min.js');
var fu = require('../utils/file-utils.js');

function Terminal(gui, manager){
    Widget.call(this);
    this._element = $('<div class="se-terminal"></div>');
    this._focus = false;
    this._lines = [];
    this._treebeard = [];
    this._currentFolder = null;
    this._history = [];
    this._historyIndex = 0;

    var savedHistory = manager.localDb().get('COMMAND_HISTORY');
    if (savedHistory) {
        this._history = savedHistory;
    }

    var me = this;
    manager.registerShortcut('ctrl+c', function(e) {
        if (me.hasFocus()) {
            var lines = me._lines;
            if (lines.length) {
                var line = lines[lines.length - 1];
                line.find('.cursor').removeClass('cursor');
                me.addLine();
            }
            e.preventDefault();
        }
    });

    manager.registerShortcut('shift+ins', function(e) {
        if (me.hasFocus()) {
            var lines = me._lines;
            if (lines.length) {
                var line = lines[lines.length - 1];
                var clipboard = gui.Clipboard.get();
                var text = clipboard.get('text');
                var letters = text.split('');

                var cursor = line.find('.cursor');
                for (var i = 0; i < letters.length; i++) {
                    var letter = letters[i];
                    cursor.before(['<span>', letter, '</span>'].join(''));
                }
            }
            e.preventDefault();
        }
    });
    
    var searchNodeOnTree = function(tree, name) {
        for (var i = 0; i < tree.length; i++) {
            var node = tree[i];
            if (node.name == name) {
                return node;
            }
        }
        return false;
    };
    
    this._commands = {
        exit: function(args, terminal, done) {
            gui.App.quit();
        },
        echo: function(args, terminal, done){
            terminal.printLine(args.join(' '));
            done();
        },
        openfolder: function(args, terminal, done) {
            if (args.length == 0) {
                terminal.printLine('No folder to open');
            } else {
                try {
                    me._treebeard = manager.action('OPEN_FOLDER', args[0]);
                    me._currentFolder = {name: '~', tree: me._treebeard.tree(), path: args[0]};
                } catch (e) {
{'fraction_non_alphanumeric': 0.1576206689365111, 'fraction_numerical': 0.004406168636090527, 'mean_word_length': 1.5518650996423096, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '3936870', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1397, 'n_words': 294}