<commit_before>/**
 Copyright 2014 <NAME> (<EMAIL>)

 This Source Code is subject to the terms of the Mozilla Public
 License, v2.0. If a copy of the MPL was not distributed with this
 file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 ------------------------------------------------------------------
  The plugin that actually writes code out to Espruino
 ------------------------------------------------------------------
**/
"use strict";
(function(){
  
  function init() {
    Espruino.Core.Config.add("RESET_BEFORE_SEND", {
      section : "Communications",
      name : "Reset before Send",
      description : "Reset Espruino before sending code from the editor pane?",
      type : "boolean",
      defaultValue : true
    });
    Espruino.Core.Config.add("STORE_LINE_NUMBERS", {
      section : "Communications",
      name : "Store line numbers",
      description : "Should Espruino store line numbers for each function? This uses one extra variable per function, but allows you to get source code debugging in the Web IDE",
      type : "boolean",
      defaultValue : true
    });
  }

  function writeToEspruino(code, callback) {  
    code = reformatCode(code);
    if (code === undefined) return; // it should already have errored
    
    // We want to make sure we've got a prompt before sending. If not,
    // this will issue a Ctrl+C
    Espruino.Core.Utils.getEspruinoPrompt(function() {
      // turn off ech around the code
      code = "echo(0);\n" + code + "\necho(1);\n";

      // If we're supposed to reset Espruino before sending...
      if (Espruino.Config.RESET_BEFORE_SEND) {
        code = "reset();\n"+code;
      } 

      //console.log("Sending... "+data);
      Espruino.Core.Serial.write(code, true, function() {
        // give 10 seconds for sending with save and 2 seconds without save
        var count = Espruino.Config.SAVE_ON_SEND ? 100 : 20;
        setTimeout(function cb() {
          if (Espruino.Core.Terminal!==undefined && 
              Espruino.Core.Terminal.getTerminalLine()!=">") {
            count--;
            if (count>0) {
              setTimeout(cb, 100);
            } else {
              Espruino.Core.Terminal.outputDataHandler("ERROR: Prompt not detected - upload failed. Trying to recover...\n");
              Espruino.Core.Serial.write("\x03echo(1)\n", false, callback);
            }
          } else {<commit_msg>Ensure that we break out of 'debug' as well if there are problems<commit_after>/**
 Copyright 2014 <NAME> (<EMAIL>)

 This Source Code is subject to the terms of the Mozilla Public
 License, v2.0. If a copy of the MPL was not distributed with this
 file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 ------------------------------------------------------------------
  The plugin that actually writes code out to Espruino
 ------------------------------------------------------------------
**/
"use strict";
(function(){
  
  function init() {
    Espruino.Core.Config.add("RESET_BEFORE_SEND", {
      section : "Communications",
      name : "Reset before Send",
      description : "Reset Espruino before sending code from the editor pane?",
      type : "boolean",
      defaultValue : true
    });
    Espruino.Core.Config.add("STORE_LINE_NUMBERS", {
      section : "Communications",
      name : "Store line numbers",
      description : "Should Espruino store line numbers for each function? This uses one extra variable per function, but allows you to get source code debugging in the Web IDE",
      type : "boolean",
      defaultValue : true
    });
  }

  function writeToEspruino(code, callback) {  
    code = reformatCode(code);
    if (code === undefined) return; // it should already have errored
    
    // We want to make sure we've got a prompt before sending. If not,
    // this will issue a Ctrl+C
    Espruino.Core.Utils.getEspruinoPrompt(function() {
      // turn off ech around the code
      code = "echo(0);\n" + code + "\necho(1);\n";

      // If we're supposed to reset Espruino before sending...
      if (Espruino.Config.RESET_BEFORE_SEND) {
        code = "reset();\n"+code;
      } 

      //console.log("Sending... "+data);
      Espruino.Core.Serial.write(code, true, function() {
        // give 10 seconds for sending with save and 2 seconds without save
        var count = Espruino.Config.SAVE_ON_SEND ? 100 : 20;
        setTimeout(function cb() {
          if (Espruino.Core.Terminal!==undefined && 
              Espruino.Core.Terminal.getTerminalLine()!=">") {
            count--;
            if (count>0) {
              setTimeout(cb, 100);
            } else {
              Espruino.Core.Terminal.outputDataHandler("ERROR: Prompt not detected - upload failed. Trying to recover...\n");
              Espruino.Core.Serial.write("\x03\x03echo(1)\n", false, callback);
            }
          } else {
{'fraction_non_alphanumeric': 0.16474701768819416, 'fraction_numerical': 0.0106951871657754, 'mean_word_length': 2.039375, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1310306', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1349, 'n_words': 436}