#import "EtermSupport.h"
#import "EtermHandle.h"
#import "Appender.h"
#import <assert.h>
#import <stdlib.h>
#import <libc.h>
#import <appkit/Application.h>

struct display {
    id deputy;
};

void *new_display_rock(id deputy)
{
    struct display *new_display;

    new_display = malloc(sizeof(struct display));
    assert(new_display);

    new_display->deputy = deputy;

    return (void *)new_display;
}

void input_from_apps(int fd, void *rock)
{
    struct display *display = (struct display *)rock;
    static char buf[1024]; // local buffer increase performance
    int n;
    id deputy = display->deputy;

    n = read(fd, buf, sizeof(buf)-1);
    if (n < 1) {
	[NXApp terminate:nil];
    }

    if (n > 0) buf[n] = 0;	/* terminate the string */
    [deputy outputFromApp:buf];
}

