<commit_before>if(!window.console){
  console = {
    log: function(x){
    }
  }
}

(function($) {
  var commandHistory = [];
  var historyPosition = -1;
  var currentCommand = ''
  
  var settings;
  
  var messageListeners = {
    observe: [
      function(msg){
        methods.setObservations(msg.observations);
      }
    ],
    write: [
      function(msg){
        methods.write(msg.text, msg.is_error, msg.escape_html);
      }
    ]
  }
  
  var methods = {
    init: function(options){
      // Create some defaults, extending them with any options that were provided
      settings = $.extend({
        listen: false,
        comet_url: "/api/exec/messages/",
        rest_url: "/api/exec/",
        
        callback: function(){
          // methods.write('Connected...');
        },
        
        error_handler: function(err){
          methods.write(err, true, true);
        },
        
        observation_template: "<div class=\"jumbotron\"></span>",
        issued_command_template: "<div class=\"alert alert-warning issued-command\"><div class=\"date-container\"></div>$content</div>",
        error_template: "<div class=\"alert alert-danger received-error\"><div class=\"date-container\"></div>$content</div>",
        message_template: "<div class=\"panel panel-info received-message\"><div class=\"panel-body date-container\">$content</div></div>",
        
        // // The rest of these settings are defined in the client template
        // // when the plugin is instantiated, keeping all template-related
        // // code together. The setting names are also listed here:
        //
        // issued_command_template    actions_selector
        // error_template       name_selector
        // message_template       description_selector
        // player_image_template    contents_selector
        // 
        // players_wrapper_node     player_name_node
        // contents_wrapper_node    player_mood_node
        // players_list_node      people_here_node
        // contents_list_node     contents_here_node
        // player_image_node      clear_both_node
        // default_image_node     player_list_item_node
        // content_list_item_node
      }, options);
      
      return this.each(function(){
        function listen(handler){
          $.ajax({
            method: 'GET',
            url: settings.comet_url,
            contentType: "application/json",
            cache: false,
            error:    function(jqXHR, textStatus, errorThrown){
              if(textStatus == 'timeout'){
                listen(handler);
              }
              else if(textStatus != 'abort'){
                if(errorThrown){
                  settings.error_handler('Error in listen: ' + errorThrown);
                }
                else{
                  settings.error_handler('Error in listen: Server Gone');
                }
              }
            },
            success: function(data, textStatus, jqXHR){
              handler(data);
              setTimeout(function(){
                listen(handler);
              }, 1);
            }
          });
        }
        
        function handleKeyEvent(event){
          /*
           * Command-line key handler.
           */
          switch(event.which){
            case 13:
              var command = event.target.value;
              if(command){
                methods.parse(command);
                commandHistory.push(command);<commit_msg>added retry after failure with exponential backoff, made errors more subtle -- this happens all the time on mobile<commit_after>if(!window.console){
  console = {
    log: function(x){
    }
  }
}

(function($) {
  var commandHistory = [];
  var historyPosition = -1;
  var currentCommand = ''
  
  var settings;
  
  var messageListeners = {
    observe: [
      function(msg){
        methods.setObservations(msg.observations);
      }
    ],
    write: [
      function(msg){
        methods.write(msg.text, msg.is_error, msg.escape_html);
      }
    ]
  }
  
  var methods = {
    init: function(options){
      // Create some defaults, extending them with any options that were provided
      settings = $.extend({
        listen: false,
        comet_url: "/api/exec/messages/",
        rest_url: "/api/exec/",
        
        callback: function(){
          // methods.write('Connected...');
        },
        
        observation_template: "<div class=\"jumbotron\"></span>",
        issued_command_template: "<div class=\"alert alert-warning issued-command\"><div class=\"date-container\"></div>$content</div>",
        error_template: "<div class=\"alert alert-danger received-error\"><div class=\"date-container\"></div>$content</div>",
        message_template: "<div class=\"panel panel-info received-message\"><div class=\"panel-body date-container\">$content</div></div>",
        
        // // The rest of these settings are defined in the client template
        // // when the plugin is instantiated, keeping all template-related
        // // code together. The setting names are also listed here:
        //
        // issued_command_template    actions_selector
        // error_template       name_selector
        // message_template       description_selector
        // player_image_template    contents_selector
        // 
        // players_wrapper_node     player_name_node
        // contents_wrapper_node    player_mood_node
        // players_list_node      people_here_node
        // contents_list_node     contents_here_node
        // player_image_node      clear_both_node
        // default_image_node     player_list_item_node
        // content_list_item_node
      }, options);
      
      return this.each(function(){
        var delay;
        function listen(handler){
          $.ajax({
            method: 'GET',
            url: settings.comet_url,
            contentType: "application/json",
            cache: false,
            error:    function(jqXHR, textStatus, errorThrown){
              if(textStatus == 'timeout'){
                listen(handler);
              }
              else if(textStatus != 'abort'){
                if(delay < 1000){
                  delay = 1000;
                }
                delay = delay * 2;
                if(errorThrown){
                  console.log('Error in listen: ' + errorThrown);
                }
                else{
                  console.log('Error in listen: Server Gone');
                }
                setTimeout(function(){
                  listen(handler);
                }, delay);
              }
            },
            success: function(data, textStatus, jqXHR){
              handler(data);
              delay = 100;
              setTimeout(function(){
                listen(handler);
              }, delay);
            }
          });
        }
        
        function handleKeyEvent(event){
          /*
           * Command-line key handler.
           */
          switch(event.which){
            case 13:
              var command = event.target.value;
              if(command){
                methods.parse(command);
                commandHistory.push(command);
{'fraction_non_alphanumeric': 0.11315240083507307, 'fraction_numerical': 0.0026443980514961724, 'mean_word_length': 1.6322344322344322, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 31, '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': '5924330', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1821, 'n_words': 391}