<commit_before>var shellView = Backbone.View.extend({
  el: '#content',
  events: {
    'click #editor-run'     : 'submitEditor',
    'mouseleave .vsplitbar' : 'renderEditor'
  },

  template: new EJS({url: '/_admin/html/js/templates/shellView.ejs'}),

  render: function() {
    $(this.el).html(this.template.text);
    this.replShell();
    this.editor();
    $("#shell_workspace").splitter({
      dock: true
    });
    $("#shell_workspace").trigger("resize", [ 200 ]);
    $('.vsplitbar').append('<div id="editor-run"><img src="img/right_icon.png"></img></div>');
    $.gritter.removeAll();
    return this;
  },
  renderEditor: function () {
    var editor = ace.edit("editor");
    editor.resize()
  },
  editor: function () {
    var editor = ace.edit("editor");
    editor.getSession().setMode("ace/mode/javascript");
  },
  executeJs: function (data) {
    try {
      var internal = require("internal");
      var result = window.eval(data);

      if (result !== undefined) {
        internal.browserOutputBuffer = "";
        internal.printShell.apply(internal.printShell, [ result ]);
        jqconsole.Write('==> ' + internal.browserOutputBuffer + '\n', 'jssuccess');
      }
      internal.browserOutputBuffer = "";

    } catch (e) {
      jqconsole.Write('ReferenceError: ' + e.message + '\n', 'jserror');
    }
  },
  submitEditor: function () {
    var editor = ace.edit("editor");
    var data = editor.getValue();
    
    this.executeJs(data);
    jqconsole.Focus();
  },
  replShell: function () {
    // Creating the console.
    var header = 'Welcome to arangosh Copyright (c) 2012 triAGENS GmbH.\n';
    window.jqconsole = $('#replShell').jqconsole(header, 'JSH> ', "...>");

    // Abort prompt on Ctrl+Z.
    jqconsole.RegisterShortcut('Z', function() {
      jqconsole.AbortPrompt();
      handler();
    });
    // Move to line end Ctrl+E.
    jqconsole.RegisterShortcut('E', function() {
      jqconsole.MoveToEnd();
      handler();
    });
    jqconsole.RegisterMatching('{', '}', 'brace');
    jqconsole.RegisterMatching('(', ')', 'paren');
    jqconsole.RegisterMatching('[', ']', 'bracket');

    var that = this;
    // Handle a command.
    var handler = function(command) {
      if (command === 'help') {
        command = "require(\"arangosh\").HELP";
      }
      if (command === "exit") {
        location.reload();
      }

      that.executeJs(command);<commit_msg>fixes #448<commit_after>var shellView = Backbone.View.extend({
  el: '#content',
  events: {
    'click #editor-run'     : 'submitEditor',
    'mouseleave .vsplitbar' : 'renderEditor'
  },

  template: new EJS({url: '/_admin/html/js/templates/shellView.ejs'}),

  render: function() {
    $(this.el).html(this.template.text);
    this.replShell();
    this.editor();
    $("#shell_workspace").splitter({
      dock: true
    });
    $("#shell_workspace").trigger("resize", [ 200 ]);
    $('.vsplitbar').append('<div id="editor-run"><img src="img/right_icon.png"></img></div>');
    $.gritter.removeAll();
    return this;
  },
  renderEditor: function () {
    var editor = ace.edit("editor");
    editor.resize()
  },
  editor: function () {
    var editor = ace.edit("editor");
    editor.getSession().setMode("ace/mode/javascript");
  },
  executeJs: function (data) {
    try {
      var internal = require("internal");
      var result = window.eval(data);

      if (result !== undefined) {
        internal.browserOutputBuffer = "";
        internal.printShell.apply(internal.printShell, [ result ]);
        jqconsole.Write('==> ' + internal.browserOutputBuffer + '\n', 'jssuccess');
      }
      internal.browserOutputBuffer = "";

    } catch (e) {
      jqconsole.Write('ReferenceError: ' + e.message + '\n', 'jserror');
    }
  },
  submitEditor: function () {
    var editor = ace.edit("editor");
    var data = editor.getValue();
    this.executeJs(data);
    jqconsole.Focus();
  },
  replShell: function () {
    // Creating the console.
    var internal = require("internal");
    var arangodb = require("org/arangodb");
    var client = require("org/arangodb/arangosh");
    var header = 'Welcome to arangosh Copyright (c) 2012 triAGENS GmbH.\n';
    window.jqconsole = $('#replShell').jqconsole(header, 'JSH> ', "...>");
    this.executeJs(internal.print(client.HELP));
    // Abort prompt on Ctrl+Z.
    jqconsole.RegisterShortcut('Z', function() {
      jqconsole.AbortPrompt();
      handler();
    });
    // Move to line end Ctrl+E.
    jqconsole.RegisterShortcut('E', function() {
      jqconsole.MoveToEnd();
      handler();
    });
    jqconsole.RegisterMatching('{', '}', 'brace');
    jqconsole.RegisterMatching('(', ')', 'paren');
    jqconsole.RegisterMatching('[', ']', 'bracket');

    var that = this;
    // Handle a command.
    var handler = function(command) {
      if (command === 'help') {
        //command = "require(\"arangosh\").HELP";
        command = help();
      }
      if (command === "exit") {
        location.reload();
      }

      that.executeJs(command);
{'fraction_non_alphanumeric': 0.18818380743982493, 'fraction_numerical': 0.0033817386114979114, 'mean_word_length': 2.891640866873065, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '2247545', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1569, 'n_words': 294}