<commit_before>#include <lib/call.h>
#include <lib/elf.h>
#include <lib/memory.h>
#include <lib/stack.h>
#include <lib/file.h>
#include <lib/string.h>
#include <lib/vfs.h>
#include <kernel/elf.h>
#include <kernel/kernel.h>
#include <kernel/tty.h>

struct vfs_node ttyLocationNode;
struct vfs_node ttyStdoutNode;
struct vfs_node *ttyVgaNode;
struct vfs_node *ttyVgaColorNode;
struct vfs_node *ttyVgaCursorNode;
unsigned short ttyVgaCursorOffset;

char ttyLocation[256];

static void tty_scroll()
{

    char buffer[TTY_CHARACTER_SIZE];

    file_read(ttyVgaNode, TTY_CHARACTER_WIDTH, TTY_CHARACTER_SIZE - TTY_CHARACTER_WIDTH, buffer);
    memory_set(buffer + TTY_CHARACTER_SIZE - TTY_CHARACTER_WIDTH, ' ', TTY_CHARACTER_WIDTH);
    file_write(ttyVgaNode, 0, TTY_CHARACTER_SIZE, buffer);

    ttyVgaCursorOffset -= TTY_CHARACTER_WIDTH;

}

static void tty_putc(char c)
{

    if (c == '\b')
    {

        ttyVgaCursorOffset--;

    }

    else if (c == '\t')
    {

        ttyVgaCursorOffset = (ttyVgaCursorOffset + 8) & ~(8 - 1);

    }

    else if (c == '\r')
    {

        ttyVgaCursorOffset -= (ttyVgaCursorOffset % TTY_CHARACTER_WIDTH);

    }

    else if (c == '\n')
    {

        ttyVgaCursorOffset += TTY_CHARACTER_WIDTH - (ttyVgaCursorOffset % TTY_CHARACTER_WIDTH);

    }
    
    else if (c >= ' ')
    {

        file_write(ttyVgaNode, ttyVgaCursorOffset, 1, &c);
        ttyVgaCursorOffset++;

    }

    if (ttyVgaCursorOffset >= TTY_CHARACTER_WIDTH * TTY_CHARACTER_HEIGHT - TTY_CHARACTER_WIDTH)
        tty_scroll();

    file_write(ttyVgaCursorNode, 0, 1, &ttyVgaCursorOffset);

}

static void tty_vga_clear()
{

    char c = ' ';
    int i;

    for (i = 0; i < TTY_CHARACTER_SIZE; i++)
        file_write(ttyVgaNode, i, 1, &c);

}

static unsigned int tty_write(struct vfs_node *node, unsigned int offset, unsigned int count, void *buffer)
{

    unsigned int i;
    unsigned int j = 0;

    for (i = offset; i < offset + count; i++, j++)
        tty_putc(((char *)buffer)[j]);

    return count;

}<commit_msg>changed so cursor position only updates after write is complete<commit_after>#include <lib/call.h>
#include <lib/elf.h>
#include <lib/memory.h>
#include <lib/stack.h>
#include <lib/file.h>
#include <lib/string.h>
#include <lib/vfs.h>
#include <kernel/elf.h>
#include <kernel/kernel.h>
#include <kernel/tty.h>

struct vfs_node ttyLocationNode;
struct vfs_node ttyStdoutNode;
struct vfs_node *ttyVgaNode;
struct vfs_node *ttyVgaColorNode;
struct vfs_node *ttyVgaCursorNode;
unsigned short ttyVgaCursorOffset;

char ttyLocation[256];

static void tty_scroll()
{

    char buffer[TTY_CHARACTER_SIZE];

    file_read(ttyVgaNode, TTY_CHARACTER_WIDTH, TTY_CHARACTER_SIZE - TTY_CHARACTER_WIDTH, buffer);
    memory_set(buffer + TTY_CHARACTER_SIZE - TTY_CHARACTER_WIDTH, ' ', TTY_CHARACTER_WIDTH);
    file_write(ttyVgaNode, 0, TTY_CHARACTER_SIZE, buffer);

    ttyVgaCursorOffset -= TTY_CHARACTER_WIDTH;

}

static void tty_putc(char c)
{

    if (c == '\b')
    {

        ttyVgaCursorOffset--;

    }

    else if (c == '\t')
    {

        ttyVgaCursorOffset = (ttyVgaCursorOffset + 8) & ~(8 - 1);

    }

    else if (c == '\r')
    {

        ttyVgaCursorOffset -= (ttyVgaCursorOffset % TTY_CHARACTER_WIDTH);

    }

    else if (c == '\n')
    {

        ttyVgaCursorOffset += TTY_CHARACTER_WIDTH - (ttyVgaCursorOffset % TTY_CHARACTER_WIDTH);

    }
    
    else if (c >= ' ')
    {

        file_write(ttyVgaNode, ttyVgaCursorOffset, 1, &c);
        ttyVgaCursorOffset++;

    }

    if (ttyVgaCursorOffset >= TTY_CHARACTER_WIDTH * TTY_CHARACTER_HEIGHT - TTY_CHARACTER_WIDTH)
        tty_scroll();

}

static void tty_vga_clear()
{

    char c = ' ';
    int i;

    for (i = 0; i < TTY_CHARACTER_SIZE; i++)
        file_write(ttyVgaNode, i, 1, &c);

}

static unsigned int tty_write(struct vfs_node *node, unsigned int offset, unsigned int count, void *buffer)
{

    unsigned int i;
    unsigned int j = 0;

    for (i = offset; i < offset + count; i++, j++)
        tty_putc(((char *)buffer)[j]);

    file_write(ttyVgaCursorNode, 0, 1, &ttyVgaCursorOffset);

    return count;

}
{'fraction_non_alphanumeric': 0.12439261418853255, 'fraction_numerical': 0.006316812439261419, 'mean_word_length': 3.3245798319327733, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '1008678', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1556, 'n_words': 329}