<commit_before>#include <kernel/user.h>

#include <kotaka/paths.h>
#include <kotaka/privilege.h>

inherit LIB_FILTER;
string outbuf;
int callout;
int escape;
int dead;

private void schedule()
{
	if (callout == -1 && strlen(outbuf)) {
		switch(outbuf[0]) {
		case '\033': escape = 1; break;
		case 'A' .. 'Z': escape = 0; break;
		case 'a' .. 'z': escape = 0; break;
		}

		if (escape) {
			callout = call_out("char", 0);
		} else {
			callout = call_out("char", 0.05);
		}
	}
}

static void create(int clone)
{
	if (clone) {
		outbuf = "";
		callout = -1;
		::create();
	}
}

int message(string str)
{
	ACCESS_CHECK(previous_program() == LIB_USER);

	outbuf += str;
	schedule();

	return 1;
}

void disconnect()
{
	if (query_conn()) {
		dead = 1;
		if (!strlen(outbuf)) {
			::disconnect();
		}
	} else {
		::disconnect();
	}
}

/*
int receive_message(string str)
{
	if (!dead) {
		return ::receive_message(str);
	} else {
		return MODE_NOCHANGE;
	}
}
*/
static void char()
{
	callout = -1;

	::message(outbuf[0 .. 0]);
	outbuf = outbuf[1 ..];

	if (dead && !strlen(outbuf)) {
		::disconnect();
	}
<commit_msg>Have lagger handle output draining<commit_after>#include <kernel/user.h>

#include <kotaka/paths.h>
#include <kotaka/privilege.h>

inherit LIB_FILTER;
string outbuf;
int callout;
int escape;
int dead;

private void schedule()
{
	if (callout == -1 && strlen(outbuf)) {
		switch(outbuf[0]) {
		case '\033': escape = 1; break;
		case 'A' .. 'Z': escape = 0; break;
		case 'a' .. 'z': escape = 0; break;
		}

		if (escape) {
			callout = call_out("char", 0);
		} else {
			callout = call_out("char", 0.05);
		}
	}
}

static void create(int clone)
{
	if (clone) {
		outbuf = "";
		callout = -1;
		::create();
	}
}

int message(string str)
{
	ACCESS_CHECK(previous_program() == LIB_USER);

	outbuf += str;
	schedule();

	return 1;
}

void disconnect()
{
	if (query_conn()) {
		dead = 1;
		if (!strlen(outbuf)) {
			::disconnect();
		}
	} else {
		::disconnect();
	}
}

int receive_message(string str)
{
	if (!dead) {
		return ::receive_message(str);
	} else {
		return MODE_NOCHANGE;
	}
}

static void char()
{
	callout = -1;

	::message(outbuf[0 .. 0]);
	outbuf = outbuf[1 ..];

	if (dead && !strlen(outbuf)) {
		::disconnect();
	}

{'fraction_non_alphanumeric': 0.19213583556747096, 'fraction_numerical': 0.016979445933869526, 'mean_word_length': 3.3560311284046693, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '357335', 'n_tokens_mistral': 998, 'n_tokens_neox': 910, 'n_words': 212}