<commit_before>public class Spawn {

uint timeout;
string progname;
string output;
Pid pid;
int status;
int outfd;
int errfd;
IOChannel outchan;
IOChannel errchan;
MainLoop loop;

public
Spawn(string name)
{
	progname = name;
}

void
on_async_exit(Pid pid, int exit_status)
{
	Source.remove(timeout);
	Process.close_pid(pid);
	status = exit_status;
	loop.quit();
}

bool
on_output(IOChannel source, IOCondition cond)
{
	if (cond == IOCondition.HUP) return false;

	try {
		int fd = source.unix_get_fd();
		source.read_line(out output, null, null);
		if (fd == outfd)
			stdout.printf("%s", output);
		if (fd == errfd)
			stdout.printf("%c[1m%c[31m%s",
			    (char)27, (char)27, output);
	} catch (ConvertError err) {
		stderr.printf("Conversion error!: %s\n", err.message);
		return false;
	} catch (IOChannelError err) {
		stderr.printf("Read error!: %s\n", err.message);
		return false;
	}<commit_msg>spawn.test: terminate color output for errors.<commit_after>public class Spawn {

uint timeout;
string progname;
string output;
Pid pid;
int status;
int outfd;
int errfd;
IOChannel outchan;
IOChannel errchan;
MainLoop loop;

public
Spawn(string name)
{
	progname = name;
}

void
on_async_exit(Pid pid, int exit_status)
{
	Source.remove(timeout);
	Process.close_pid(pid);
	status = exit_status;
	loop.quit();
}

bool
on_output(IOChannel source, IOCondition cond)
{
	if (cond == IOCondition.HUP) return false;

	try {
		int fd = source.unix_get_fd();
		source.read_line(out output, null, null);
		if (fd == outfd)
			stdout.printf("%s", output);
		if (fd == errfd)
			stdout.printf("%c[1m%c[31m%s%c[0m",
			    (char)27, (char)27, output, (char)27);
	} catch (ConvertError err) {
		stderr.printf("Conversion error!: %s\n", err.message);
		return false;
	} catch (IOChannelError err) {
		stderr.printf("Read error!: %s\n", err.message);
		return false;
	}
{'fraction_non_alphanumeric': 0.14439655172413793, 'fraction_numerical': 0.009159482758620689, 'mean_word_length': 4.610271903323262, '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': '4359841', 'n_tokens_mistral': 742, 'n_tokens_neox': 704, 'n_words': 178}