<commit_before>#include <fudge.h>
#include <abi.h>

static char inputdata1[128];
static struct ring input1;
static char inputdata2[128];
static struct ring input2;
static char resultdata[1024];
static struct ring result;

static unsigned int copyringtobuffer(struct ring *ring, void *buffer, unsigned int count, unsigned int offset)
{

    unsigned char *b = buffer;
    unsigned int head;
    unsigned int tail;
    unsigned int c;

    head = ring->head;
    tail = ring->tail;

    c = ring_read(ring, b + offset, count - offset);

    ring->head = head;
    ring->tail = tail;

    return c;

}

static void update(void)
{

    char buffer[BUFFER_SIZE];
    unsigned int count = 0;

    count += buffer_write(buffer, BUFFER_SIZE, "= input1 content \"", 18, count);
    count += copyringtobuffer(&input1, buffer, BUFFER_SIZE, count);
    count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);
    count += buffer_write(buffer, BUFFER_SIZE, "= input2 content \"", 18, count);
    count += copyringtobuffer(&input2, buffer, BUFFER_SIZE, count);
    count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);
    count += buffer_write(buffer, BUFFER_SIZE, "= result content \"", 18, count);
    count += copyringtobuffer(&result, buffer, BUFFER_SIZE, count);
    count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    file_notify(FILE_G0, EVENT_WMRENDERDATA, count, buffer);

}

static void print(void *buffer, unsigned int count)
{

    char *b = buffer;
    unsigned int i;

    for (i = 0; i < count; i++)
    {

        if (!ring_avail(&result))
            ring_skip(&result, ring_find(&result, '\n') + 1);

        if (b[i] != '\r')
            ring_write(&result, &b[i], 1);

    }

}

static void printprompt(void)
{

    print("$ ", 2);

}

static void moveleft(unsigned int steps)
{

    char buffer[128];

    ring_writereverse(&input2, buffer, ring_readreverse(&input1, buffer, steps));

}

static void moveright(unsigned int steps)
{

    char buffer[128];

    ring_write(&input1, buffer, ring_read(&input2, buffer, steps));

}

static void onmain(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMMAP, 0, 0);

}

static void onterm(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMUNMAP, 0, 0);
    channel_close();

}

static void onwminit(unsigned int source, void *mdata, unsigned int msize)
{

    char *data =
        "+ window id \"window\" title \"Shell\"\n"
        "+ container id \"base\" in \"window\" layout \"maximize\" padding \"16\"\n"
        "+ textbox id \"output\" in \"base\"\n"
        "+ text id \"result\" in \"output\" wrap \"none\"\n"
        "+ text id \"prompt\" in \"output\" wrap \"none\" weight \"bold\" content \"$ \"\n"
        "+ text id \"input1\" in \"output\" wrap \"none\"\n"
        "+ text id \"cursor\" in \"output\" wrap \"none\" mode \"inverted\" content \" \"\n"
        "+ text id \"input2\" in \"output\" wrap \"none\"\n";

    file_notify(FILE_G0, EVENT_WMRENDERDATA, cstring_length(data), data);

}

static void onwmkeypress(unsigned int source, void *mdata, unsigned int msize)
{

    struct event_wmkeypress2 *wmkeypress = mdata;

    if (!cstring_match(wmkeypress->pressed, "output"))
        return;

    switch (wmkeypress->scancode)
    {

    case 0x0E:
        ring_skipreverse(&input1, 1);

        break;

    case 0x0F:
        ring_move(&input1, &input2);
        /* complete(&input1); */

        break;

    case 0x1C:
        ring_move(&input1, &input2);
        ring_write(&input1, &wmkeypress->unicode, wmkeypress->length);
        /* interpret(&input1); */

        break;

    case 0x16:
        if (wmkeypress->keymod & KEYMOD_CTRL)
            ring_reset(&input1);
        else
            ring_write(&input1, &wmkeypress->unicode, wmkeypress->length);

        break;
<commit_msg>more<commit_after>#include <fudge.h>
#include <abi.h>

static char inputdata1[128];
static struct ring input1;
static char inputdata2[128];
static struct ring input2;
static char resultdata[1024];
static struct ring result;

static unsigned int copyringtobuffer(struct ring *ring, void *buffer, unsigned int count, unsigned int offset)
{

    unsigned char *b = buffer;
    unsigned int head;
    unsigned int tail;
    unsigned int c;

    head = ring->head;
    tail = ring->tail;

    c = ring_read(ring, b + offset, count - offset);

    ring->head = head;
    ring->tail = tail;

    return c;

}

static void update(void)
{

    char buffer[BUFFER_SIZE];
    unsigned int count = 0;

    if (ring_count(&input1))
    {

        count += buffer_write(buffer, BUFFER_SIZE, "= input1 content \"", 18, count);
        count += copyringtobuffer(&input1, buffer, BUFFER_SIZE, count);
        count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    }

    if (ring_count(&input2))
    {

        count += buffer_write(buffer, BUFFER_SIZE, "= input2 content \"", 18, count);
        count += copyringtobuffer(&input2, buffer, BUFFER_SIZE, count);
        count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    }

    if (ring_count(&result))
    {

        count += buffer_write(buffer, BUFFER_SIZE, "= result content \"", 18, count);
        count += copyringtobuffer(&result, buffer, BUFFER_SIZE, count);
        count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    }

    file_notify(FILE_G0, EVENT_WMRENDERDATA, count, buffer);

}

static void print(void *buffer, unsigned int count)
{

    char *b = buffer;
    unsigned int i;

    for (i = 0; i < count; i++)
    {

        if (!ring_avail(&result))
            ring_skip(&result, ring_find(&result, '\n') + 1);

        if (b[i] != '\r')
            ring_write(&result, &b[i], 1);

    }

}

static void printprompt(void)
{

    print("$ ", 2);

}

static void moveleft(unsigned int steps)
{

    char buffer[128];

    ring_writereverse(&input2, buffer, ring_readreverse(&input1, buffer, steps));

}

static void moveright(unsigned int steps)
{

    char buffer[128];

    ring_write(&input1, buffer, ring_read(&input2, buffer, steps));

}

static void onmain(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMMAP, 0, 0);

}

static void interpret(void)
{

    ring_reset(&input1);
    ring_reset(&input2);

}

static void onterm(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMUNMAP, 0, 0);
    channel_close();

}

static void onwminit(unsigned int source, void *mdata, unsigned int msize)
{

    char *data =
        "+ window id \"window\" title \"Shell\"\n"
        "+ container id \"base\" in \"window\" layout \"maximize\" padding \"16\"\n"
        "+ textbox id \"output\" in \"base\"\n"
        "+ text id \"result\" in \"output\" wrap \"none\"\n"
        "+ text id \"prompt\" in \"output\" wrap \"none\" weight \"bold\" content \"$ \"\n"
        "+ text id \"input1\" in \"output\" wrap \"none\"\n"
        "+ text id \"cursor\" in \"output\" wrap \"none\" mode \"inverted\" content \" \"\n"
        "+ text id \"input2\" in \"output\" wrap \"none\"\n";

    file_notify(FILE_G0, EVENT_WMRENDERDATA, cstring_length(data), data);

}

static void onwmkeypress(unsigned int source, void *mdata, unsigned int msize)
{

    struct event_wmkeypress2 *wmkeypress = mdata;

    if (!cstring_match(wmkeypress->pressed, "output"))
        return;

    switch (wmkeypress->scancode)
    {

    case 0x0E:
        ring_skipreverse(&input1, 1);

        break;

    case 0x0F:
        ring_move(&input1, &input2);
        /* complete(&input1); */

        break;

    case 0x1C:
        ring_move(&input1, &input2);
        ring_write(&input1, &wmkeypress->unicode, wmkeypress->length);
        interpret();

        break;

    case 0x16:
        if (wmkeypress->keymod & KEYMOD_CTRL)
            ring_reset(&input1);
        else
            ring_write(&input1, &wmkeypress->unicode, wmkeypress->length);

        break;

{'fraction_non_alphanumeric': 0.1486690105474636, 'fraction_numerical': 0.01921145153189352, 'mean_word_length': 2.860882210373243, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '2801772', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2606, 'n_words': 717}