<commit_before><% if @console_session && @console_session.binding %>
  <div id="console"
    data-remote-path='<%= "console/repl_sessions/#{@console_session.id}" %>'
    data-initial-prompt='<%= @console_session.prompt %>'>
  </div>

  <script type="text/javascript">
    (function() {
      // DOM helpers
      function hasClass(el, className) {
        var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)', 'g');
        return el.className.match(regex);
      }

      function addClass(el, className) {
        el.className += " " + className;
      }

      function removeClass(el, className) {
        var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)', 'g');
        el.className = el.className.replace(regex, '');
      }

      function removeAllChildren(el) {
        while (el.firstChild) {
          el.removeChild(el.firstChild);
        }
      }

      function escapeHTML(html) {
        return html
          .replace(/&/g, '&amp;')
          .replace(/</g, '&lt;')
          .replace(/>/g, '&gt;')
          .replace(/"/g, '&quot;')
          .replace(/'/g, '&#x27;')
          .replace(/`/g, '&#x60;');
      }

      // Add CSS styles dynamically. This probably doesnt work for IE <8.
      var style = document.createElement('style');
      style.type = 'text/css';
      style.innerHTML =
        "#console { position: fixed; left: 0; bottom: 0; width: 100%; height: 150px; border: 1px solid; padding: 0 0 20px 0; overflow: none; margin: 0; background: none repeat scroll 0% 0% #333; } " +
        "#console div.console-inner { font-family: monospace; font-size: 11px; height: 100%; overflow: auto; background: #333; border: 0; padding: 0 margin: 0; } " +
        "#console div.console-prompt-box { color: #FFF; } " +
        "#console pre.console-message { color: #1AD027; margin: 0; border: 0; white-space: pre-wrap; background-color: #333; padding: 0; } " +
        "#console div.console-focus span.console-cursor { background: #FEFEFE; color: #333; font-weight: bold; }";
      document.getElementsByTagName('head')[0].appendChild(style);

      /**
       * Constructor for command storage.
       * It uses localStorage if available. Otherwise fallback to normal JS array.
       */
      function CommandStorage() {
        this.previousCommands = [];
        var previousCommandOffset = 0;
        var hasLocalStorage = typeof window.localStorage !== 'undefined';
        var STORAGE_KEY = "web_console_previous_commands";
        var MAX_STORAGE = 100;

        if (hasLocalStorage) {
          this.previousCommands = JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
          previousCommandOffset = this.previousCommands.length;
        }

        this.addCommand = function(command) {
          previousCommandOffset = this.previousCommands.push(command);

          if (previousCommandOffset > MAX_STORAGE) {
            this.previousCommands.splice(0, 1);
            previousCommandOffset = MAX_STORAGE;
          }

          if (hasLocalStorage) {
            localStorage.setItem(STORAGE_KEY, JSON.stringify(this.previousCommands));
          }
        };

        this.navigate = function(offset) {
          previousCommandOffset += offset;

          if (previousCommandOffset < 0) {
            previousCommandOffset = -1;
            return null;
          }

          if (previousCommandOffset >= this.previousCommands.length) {
            previousCommandOffset = this.previousCommands.length;
            return null;
          }

          return this.previousCommands[previousCommandOffset];
        }
      }

      // HTML strings for dynamic elements.
      var consoleInnerHtml = [
        "<div id='resizer' style='width: 100%; height: 3px; cursor: ns-resize;'></div>",
        "<div class='console-inner'></div>",
        "<input id='clipboard' type='text' style='visibility: hidden;'>"
      ].join("");

      var promptBoxHtml = [
        "<span class='console-prompt-label' style='display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0;'></span>",
        "<pre class='console-prompt-display' style='display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0;'></pre>"
      ].join("");

      // REPLConsole Constructor
      function REPLConsole(config) {
        this.commandStorage = new CommandStorage();
        this.prompt = config && config.promptLabel ? config.promptLabel : ' >>';
        this.commandHandle = config && config.commandHandle ? config.commandHandle : function() { return this; }
      }


      REPLConsole.prototype.install = function(container) {
        var _this = this;

        document.onkeydown = function(ev) {
          if (_this.focused) { _this.onKeyDown(ev); }
        };

        document.onkeypress = function(ev) {
          if (_this.focused) { _this.onKeyPress(ev); }
        };

        document.addEventListener('mousedown', function(ev) {
          var el = ev.target || ev.srcElement;

          if (el) {
            do {
              if (el === container) {
                _this.focus();
                return;
              }
            } while (el = el.parentNode);

            _this.blur();
          }
        });

        // Render the console.
        container.innerHTML = consoleInnerHtml;
        // Make the console resizable.
        document.getElementById('resizer').addEventListener('mousedown', function(ev) {
          var startY = ev.clientY;
          var startHeight = parseInt(document.defaultView.getComputedStyle(consoleDiv).height, 10);

          var doDrag = function(e) {
            consoleDiv.style.height = (startHeight + startY - e.clientY) + 'px';
          };

          var stopDrag = function(e) {
            document.documentElement.removeEventListener('mousemove', doDrag, false);
            document.documentElement.removeEventListener('mouseup', stopDrag, false);
          };

          document.documentElement.addEventListener('mousemove', doDrag, false);
          document.documentElement.addEventListener('mouseup', stopDrag, false);
        });

        // Initialize
        this.inner = container.getElementsByClassName('console-inner')[0];
        this.clipboard = document.getElementById('clipboard');
        this.newPromptBox();
        this.focus();
      };

      REPLConsole.prototype.focus = function() {
        this.focused = true;
        if (! hasClass(this.inner, "console-focus")) {
          addClass(this.inner, "console-focus");
        }
        this.scrollToBottom();
      };

      REPLConsole.prototype.blur = function() {<commit_msg>Don't scroll to bottom on click if the console is focused<commit_after><% if @console_session && @console_session.binding %>
  <div id="console"
    data-remote-path='<%= "console/repl_sessions/#{@console_session.id}" %>'
    data-initial-prompt='<%= @console_session.prompt %>'>
  </div>

  <script type="text/javascript">
    (function() {
      // DOM helpers
      function hasClass(el, className) {
        var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)', 'g');
        return el.className.match(regex);
      }

      function addClass(el, className) {
        el.className += " " + className;
      }

      function removeClass(el, className) {
        var regex = new RegExp('(?:^|\\s)' + className + '(?!\\S)', 'g');
        el.className = el.className.replace(regex, '');
      }

      function removeAllChildren(el) {
        while (el.firstChild) {
          el.removeChild(el.firstChild);
        }
      }

      function escapeHTML(html) {
        return html
          .replace(/&/g, '&amp;')
          .replace(/</g, '&lt;')
          .replace(/>/g, '&gt;')
          .replace(/"/g, '&quot;')
          .replace(/'/g, '&#x27;')
          .replace(/`/g, '&#x60;');
      }

      // Add CSS styles dynamically. This probably doesnt work for IE <8.
      var style = document.createElement('style');
      style.type = 'text/css';
      style.innerHTML =
        "#console { position: fixed; left: 0; bottom: 0; width: 100%; height: 150px; border: 1px solid; padding: 0 0 20px 0; overflow: none; margin: 0; background: none repeat scroll 0% 0% #333; } " +
        "#console div.console-inner { font-family: monospace; font-size: 11px; height: 100%; overflow: auto; background: #333; border: 0; padding: 0 margin: 0; } " +
        "#console div.console-prompt-box { color: #FFF; } " +
        "#console pre.console-message { color: #1AD027; margin: 0; border: 0; white-space: pre-wrap; background-color: #333; padding: 0; } " +
        "#console div.console-focus span.console-cursor { background: #FEFEFE; color: #333; font-weight: bold; }";
      document.getElementsByTagName('head')[0].appendChild(style);

      /**
       * Constructor for command storage.
       * It uses localStorage if available. Otherwise fallback to normal JS array.
       */
      function CommandStorage() {
        this.previousCommands = [];
        var previousCommandOffset = 0;
        var hasLocalStorage = typeof window.localStorage !== 'undefined';
        var STORAGE_KEY = "web_console_previous_commands";
        var MAX_STORAGE = 100;

        if (hasLocalStorage) {
          this.previousCommands = JSON.parse(localStorage.getItem(STORAGE_KEY)) || [];
          previousCommandOffset = this.previousCommands.length;
        }

        this.addCommand = function(command) {
          previousCommandOffset = this.previousCommands.push(command);

          if (previousCommandOffset > MAX_STORAGE) {
            this.previousCommands.splice(0, 1);
            previousCommandOffset = MAX_STORAGE;
          }

          if (hasLocalStorage) {
            localStorage.setItem(STORAGE_KEY, JSON.stringify(this.previousCommands));
          }
        };

        this.navigate = function(offset) {
          previousCommandOffset += offset;

          if (previousCommandOffset < 0) {
            previousCommandOffset = -1;
            return null;
          }

          if (previousCommandOffset >= this.previousCommands.length) {
            previousCommandOffset = this.previousCommands.length;
            return null;
          }

          return this.previousCommands[previousCommandOffset];
        }
      }

      // HTML strings for dynamic elements.
      var consoleInnerHtml = [
        "<div id='resizer' style='width: 100%; height: 3px; cursor: ns-resize;'></div>",
        "<div class='console-inner'></div>",
        "<input id='clipboard' type='text' style='visibility: hidden;'>"
      ].join("");

      var promptBoxHtml = [
        "<span class='console-prompt-label' style='display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0;'></span>",
        "<pre class='console-prompt-display' style='display: inline; color: #FFF; background: none repeat scroll 0% 0% #333; border: 0; padding: 0;'></pre>"
      ].join("");

      // REPLConsole Constructor
      function REPLConsole(config) {
        this.commandStorage = new CommandStorage();
        this.prompt = config && config.promptLabel ? config.promptLabel : ' >>';
        this.commandHandle = config && config.commandHandle ? config.commandHandle : function() { return this; }
      }


      REPLConsole.prototype.install = function(container) {
        var _this = this;

        document.onkeydown = function(ev) {
          if (_this.focused) { _this.onKeyDown(ev); }
        };

        document.onkeypress = function(ev) {
          if (_this.focused) { _this.onKeyPress(ev); }
        };

        document.addEventListener('mousedown', function(ev) {
          var el = ev.target || ev.srcElement;

          if (el) {
            do {
              if (el === container) {
                _this.focus();
                return;
              }
            } while (el = el.parentNode);

            _this.blur();
          }
        });

        // Render the console.
        container.innerHTML = consoleInnerHtml;
        // Make the console resizable.
        document.getElementById('resizer').addEventListener('mousedown', function(ev) {
          var startY = ev.clientY;
          var startHeight = parseInt(document.defaultView.getComputedStyle(consoleDiv).height, 10);

          var doDrag = function(e) {
            consoleDiv.style.height = (startHeight + startY - e.clientY) + 'px';
          };

          var stopDrag = function(e) {
            document.documentElement.removeEventListener('mousemove', doDrag, false);
            document.documentElement.removeEventListener('mouseup', stopDrag, false);
          };

          document.documentElement.addEventListener('mousemove', doDrag, false);
          document.documentElement.addEventListener('mouseup', stopDrag, false);
        });

        // Initialize
        this.inner = container.getElementsByClassName('console-inner')[0];
        this.clipboard = document.getElementById('clipboard');
        this.newPromptBox();
        this.focus();
      };

      REPLConsole.prototype.focus = function() {
        if (! this.focused) {
          this.focused = true;
          if (! hasClass(this.inner, "console-focus")) {
            addClass(this.inner, "console-focus");
          }
          this.scrollToBottom();
        }
      };

      REPLConsole.prototype.blur = function() {
{'fraction_non_alphanumeric': 0.14081020255063767, 'fraction_numerical': 0.011852963240810203, 'mean_word_length': 2.3005694478831393, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 43, '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': '6985238', 'n_tokens_mistral': 3904, 'n_tokens_neox': 3699, 'n_words': 818}