<commit_before>/* global Elm */

(function () {
  'use strict';

  var socket;
  var telmnet = Elm.fullscreen(Elm.Telmnet, {
    receiveMessage: '',
    disconnected: null
  });

  function isHidden(el) {
    return el.offsetParent === null;
  }

  function focusEl(elId, timeout) {
    if (elId === '') {
      return;
    }

    timeout = timeout || 50;

    setTimeout(function () {
      var el = document.getElementById(elId);

      if (isHidden(el)) {
        // Don't try to focus the element if it is hidden.
        return;
      }

      if (document.activeElement !== el) {
        el.focus();
      }

      // On focus, the cursor moves to the start of a input box, the following
      // moves it to the end.
      var value = el.value;
      el.value = '';
      el.value = value;

    }, timeout);
  }

  telmnet.ports.reFocus.subscribe(focusEl);

  telmnet.ports.connection.subscribe(function (model) {
    var connected = model.connected,
        server = model.server;

    if (connected) {
      try {
        socket = new WebSocket(server, ['binary']);
      } catch (e) {
        telmnet.ports.disconnected.send(e.message);
        return;
      }
      socket.onmessage = function (msg) {
        var reader = new FileReader();
        reader.addEventListener('loadend', function() {
          telmnet.ports.receiveMessage.send(reader.result);
        });
        reader.readAsBinaryString(msg.data);
      };
      socket.onerror = function (/* err */) {
        if (connected) {
          telmnet.ports.disconnected.send('Server error.');
          connected = false;
        }
      };
      socket.onclose = function () {
        if (connected) {
          telmnet.ports.disconnected.send(null);
          connected = false;
        }
      };
    } else {
      if (socket) {
        socket.close();
      }
      socket = null;
    }
  });

  telmnet.ports.sendMessage.subscribe(function (msg) {
    socket.send(msg);
  });

  // TODO: Avoid the following app logic in JavaScript
  focusEl('server');
  window.onfocus = function () {
    // Focus the prompt
    focusEl('prompt');
  };
}());
<commit_msg>Add the debugger way of bootstraping app<commit_after>/* global Elm */

(function () {
  'use strict';

  var socket,
      initial = {
        receiveMessage: '',
        disconnected: null
      };
  // var telmnet = Elm.fullscreenDebug('Telmnet', 'Telmnet.elm', initial);
  var telmnet = Elm.fullscreen(Elm.Telmnet, initial);

  function isHidden(el) {
    return el.offsetParent === null;
  }

  function focusEl(elId, timeout) {
    if (elId === '') {
      return;
    }

    timeout = timeout || 50;

    setTimeout(function () {
      var el = document.getElementById(elId);

      if (isHidden(el)) {
        // Don't try to focus the element if it is hidden.
        return;
      }

      if (document.activeElement !== el) {
        el.focus();
      }

      // On focus, the cursor moves to the start of a input box, the following
      // moves it to the end.
      var value = el.value;
      el.value = '';
      el.value = value;

    }, timeout);
  }

  telmnet.ports.reFocus.subscribe(focusEl);

  telmnet.ports.connection.subscribe(function (model) {
    var connected = model.connected,
        server = model.server;

    if (connected) {
      try {
        socket = new WebSocket(server, ['binary']);
      } catch (e) {
        telmnet.ports.disconnected.send(e.message);
        return;
      }
      socket.onmessage = function (msg) {
        var reader = new FileReader();
        reader.addEventListener('loadend', function() {
          telmnet.ports.receiveMessage.send(reader.result);
        });
        reader.readAsBinaryString(msg.data);
      };
      socket.onerror = function (/* err */) {
        if (connected) {
          telmnet.ports.disconnected.send('Server error.');
          connected = false;
        }
      };
      socket.onclose = function () {
        if (connected) {
          telmnet.ports.disconnected.send(null);
          connected = false;
        }
      };
    } else {
      if (socket) {
        socket.close();
      }
      socket = null;
    }
  });

  telmnet.ports.sendMessage.subscribe(function (msg) {
    socket.send(msg);
  });

  // TODO: Avoid the following app logic in JavaScript
  focusEl('server');
  window.onfocus = function () {
    // Focus the prompt
    focusEl('prompt');
  };
}());

{'fraction_non_alphanumeric': 0.13614703880190607, 'fraction_numerical': 0.0009076469253460404, 'mean_word_length': 2.0171115674195756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5580652', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1316, 'n_words': 303}