<commit_before>if (window.yoob === undefined) yoob = {};

/*
 * Object that captures keystrokes and accumulates a string from them.
 * Optionally also updates a TextConsole.
 * Mostly for demonstration purposes so far.
 */
yoob.LineInputBuffer = function() {
  this.listenObject = undefined;
  this.console = undefined;
  this.callback = undefined;
  this.text = undefined;

  this.init = function(listenObject, console, callback) {
    this.listenObject = listenObject;
    this.console = console;
    this.callback = callback;
    this.text = "";
    
    me = this;
    listenObject.addEventListener('keyup', function(e) {
      //alert(e.keyCode);
      switch (e.keyCode) {
        case 8:   /* Backspace */
          if (me.console !== undefined) {
            me.console.write('\b \b');
          }
          if (me.text.length > 0) {
            me.text = me.text.substring(0, me.text.length-2);
          }
          e.cancelBubble = true;
          break;
        case 13:  /* Enter */
          if (me.console !== undefined) {
            me.console.write('\n');
          }
          me.text = me.text.substring(0, me.text.length-1);
          if (me.callback !== undefined) {
            me.callback(me.text);
          }
          me.text = "";
          e.cancelBubble = true;
          break;
        case 38:  /* Up arrow */
          break;
        case 40:  /* Down arrow */
          break;
        case 37:  /* Left arrow */
          break;
        case 39:  /* Right arrow */
          break;
      }
    }, true);
    /* TODO support on more browsers, with keyup */
    listenObject.addEventListener('keypress', function(e) {
      if (e.altKey) {
        //alert(e.charCode);
        return;
      }
      var chr = String.fromCharCode(e.charCode);
      if (me.console !== undefined) {
        me.console.write(chr);
      }
      me.text += chr;
      e.cancelBubble = true;
    }, true);
  };
};<commit_msg>LineInputBuffer requires a TextTerminal, not just TextConsole.<commit_after>if (window.yoob === undefined) yoob = {};

/*
 * Object that captures keystrokes and accumulates a string from them.
 * Optionally also updates a TextTerminal (not a TextConsole as it sends
 * control codes such as backspace which TextConsole does not understand.)
 * Mostly for demonstration purposes so far.
 */
yoob.LineInputBuffer = function() {
  this.listenObject = undefined;
  this.terminal = undefined;
  this.callback = undefined;
  this.text = undefined;

  this.init = function(listenObject, terminal, callback) {
    this.listenObject = listenObject;
    this.terminal = terminal;
    this.callback = callback;
    this.text = "";
    
    var me = this;
    listenObject.addEventListener('keyup', function(e) {
      //alert(e.keyCode);
      switch (e.keyCode) {
        case 8:   /* Backspace */
          if (me.terminal !== undefined) {
            me.terminal.write('\b \b');
          }
          if (me.text.length > 0) {
            me.text = me.text.substring(0, me.text.length-2);
          }
          e.cancelBubble = true;
          break;
        case 13:  /* Enter */
          if (me.terminal !== undefined) {
            me.terminal.write('\n');
          }
          me.text = me.text.substring(0, me.text.length-1);
          if (me.callback !== undefined) {
            me.callback(me.text);
          }
          me.text = "";
          e.cancelBubble = true;
          break;
        case 38:  /* Up arrow */
          break;
        case 40:  /* Down arrow */
          break;
        case 37:  /* Left arrow */
          break;
        case 39:  /* Right arrow */
          break;
      }
    }, true);
    /* TODO support on more browsers, with keyup */
    listenObject.addEventListener('keypress', function(e) {
      if (e.altKey) {
        //alert(e.charCode);
        return;
      }
      var chr = String.fromCharCode(e.charCode);
      if (me.terminal !== undefined) {
        me.terminal.write(chr);
      }
      me.text += chr;
      e.cancelBubble = true;
    }, true);
  };
};
{'fraction_non_alphanumeric': 0.13344887348353554, 'fraction_numerical': 0.007922753156721961, 'mean_word_length': 1.7958477508650519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5370179', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1186, 'n_words': 291}