<commit_before>import 'dart:html' as html;

import 'package:chrome_net/server.dart' show PicoServer, ServerLogger, HttpRequest, HttpResponse;

import 'static_servlet.dart';

var port = 5000;
var staticServlet;

// UI elements
var body;
var dropdownTrigger;
var dropdownMenu;
var dropdownEntryLoading;
var dropdownEntryEmpty;
var dropdownEntryChoose;
var loggerContainer;

void main() {
  body = html.document.body;
  dropdownTrigger = html.querySelector('#dropdownTrigger');
  dropdownMenu = html.querySelector('#dropdownMenu');
  dropdownEntryLoading = html.querySelector('#dropdownEntryLoading');
  dropdownEntryEmpty = html.querySelector('#dropdownEntryEmpty');
  dropdownEntryChoose = html.querySelector('#dropdownEntryChoose');
  loggerContainer = html.querySelector('#loggerContainer');

  body.onClick.listen((e) {
    dropdownMenu.attributes['hidden'] = '';
  });
  dropdownMenu.onClick.listen((e) => e.stopPropagation());

  dropdownTrigger.onClick.listen((e) {
    e.stopPropagation();
    dropdownMenu.attributes.remove('hidden');
  });

  dropdownEntryChoose.onClick.listen((e) {
    dropdownMenu.attributes['hidden'] = '';
    triggerChoose();
  });
}

void triggerChoose() {
  StaticServlet.choose().then((servlet) {
    staticServlet = servlet;
    staticServlet.setLogger(new PrintServletLogger());
    dropdownTrigger.text = staticServlet.name;
    return PicoServer.createServer(port);
  }).then((server) {
    server.addServlet(staticServlet);
    return server.getInfo();
  }).then((info) {
    print("Server running on ${info.localAddress}:${info.localPort.toString()}");
  });
}

class PrintServletLogger extends ServletLogger {
  void logStart(int id, HttpRequest request) => print('[$id] > $request');
  void logComplete(int id, HttpResponse response) => print('[$id] < $response');
  void logError(int id, error) => print('[$id] ! $error');
}

class ElementServletLogger extends ServletLogger {

  final html.HtmlElement _container;

  ElementServletLogger(this._container);

  void logStart(int id, HttpRequest request) => print('[$id] > $request');
  void logComplete(int id, HttpResponse response) => print('[$id] < $response');
  void logError(int id, error) => print('[$id] ! $error');

  void _parse(data) {

  }

  void _append(html.HtmlElement element) {
    _container.append(element);
    _container.scrollTop = _container.scrollHeight - _container.clientHeight;
  }
}<commit_msg>elementservletlogger<commit_after>import 'dart:html' as html;

import 'package:chrome_net/server.dart' show PicoServer, ServerLogger, HttpRequest, HttpResponse;

import 'static_servlet.dart';

var port = 5000;
var staticServlet;

// UI elements
var body;
var dropdownTrigger;
var dropdownMenu;
var dropdownEntryLoading;
var dropdownEntryEmpty;
var dropdownEntryChoose;
var loggerContainer;

void main() {
  body = html.document.body;
  dropdownTrigger = html.querySelector('#dropdownTrigger');
  dropdownMenu = html.querySelector('#dropdownMenu');
  dropdownEntryLoading = html.querySelector('#dropdownEntryLoading');
  dropdownEntryEmpty = html.querySelector('#dropdownEntryEmpty');
  dropdownEntryChoose = html.querySelector('#dropdownEntryChoose');
  loggerContainer = html.querySelector('#loggerContainer');

  body.onClick.listen((e) {
    dropdownMenu.attributes['hidden'] = '';
  });
  dropdownMenu.onClick.listen((e) => e.stopPropagation());

  dropdownTrigger.onClick.listen((e) {
    e.stopPropagation();
    dropdownMenu.attributes.remove('hidden');
  });

  dropdownEntryChoose.onClick.listen((e) {
    dropdownMenu.attributes['hidden'] = '';
    triggerChoose();
  });
}

void triggerChoose() {
  StaticServlet.choose().then((servlet) {
    staticServlet = servlet;
    staticServlet.setLogger(new ElementServletLogger(loggerContainer));
    dropdownTrigger.text = staticServlet.name;
    return PicoServer.createServer(port);
  }).then((server) {
    server.addServlet(staticServlet);
    return server.getInfo();
  }).then((info) {
    print("Server running on ${info.localAddress}:${info.localPort.toString()}");
  });
}

class PrintServletLogger extends ServletLogger {
  void logStart(int id, HttpRequest request) => print('[$id] > $request');
  void logComplete(int id, HttpResponse response) => print('[$id] < $response');
  void logError(int id, error) => print('[$id] ! $error');
}

class ElementServletLogger extends ServletLogger {

  final html.HtmlElement _container;

  ElementServletLogger(this._container);

  void logStart(int id, HttpRequest request) => _parse({ 'id': id, 'icon': '>', 'msg': request });
  void logComplete(int id, HttpResponse response) => _parse({ 'id': id, 'icon': '<', 'msg': response });
  void logError(int id, error) => _parse({ 'id': id, 'icon': '!', 'msg': error });

  void _parse(Map data) {
    var text = '[${data['id']}] ${data['icon']} ${data['msg']}';
    var div = new html.DivElement();
    div.text = text;
    _append(div);
  }

  void _append(html.HtmlElement element) {
    _container.append(element);
    _container.scrollTop = _container.scrollHeight - _container.clientHeight;
  }
}
{'fraction_non_alphanumeric': 0.15009861932938856, 'fraction_numerical': 0.0015779092702169625, 'mean_word_length': 5.3786163522012576, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6459389', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1470, 'n_words': 307}