<commit_before>/**
 *  repl.cpp
 *
 *  @author <NAME>
 */

#include <iostream>
#include <string>
#include <stdio.h>

#include "repl.h"
#include "conio/conio.h"
using namespace std;

REPL::REPL() {
    has_started = false;
    string_is_ready = false;
    input_marker = ":: ";
    history_current_position = 0;
}

void REPL::add_history() {
    if (history.size() >= 100) {
        history.erase(history.begin());
    }

    history.push_back(current_str);
}

void REPL::clear() {
    int curr_input_length = current_str.length() + input_marker.length();

    for (int i = 0; i < curr_input_length; i++) {
        printf("\b \b");
    }
}

void REPL::rewrite() {
    cout << input_marker + current_str << flush;
}

void REPL::read() {
    has_started = true;
    char curr_char;

    if (string_is_ready) {
        string_is_ready = false;
        current_str = "";

        cout << input_marker << flush;
    }

    //printf("%d\n", curr_char = Conio::getche());
    curr_char = Conio::getch();
    
    if (curr_char == 3) {
        // Control + C
        exit(0);
    } else if (curr_char == 127) {
        // Backspace
        if (current_str != "") {
            current_str = current_str.substr(0, current_str.length() - 1);
            printf("\b \b");
        }
    } else if (curr_char == 27) {
        if (Conio::getche() == 91) {
            // Arrow keys
            curr_char = Conio::getche();
            if (curr_char == 65) {
                // Up
                // TODO: Fix this - It's doing it in the wrong order
                if (history_current_position < history.size()) {
                    clear();

                    current_str = history.at(history.size() - 1 - history_current_position);
                    history_current_position++;

                    rewrite();
                }
            } else if (curr_char == 66) {
                // Down
                if (history_current_position != 0) {
                    clear();

                    if (history_current_position - 1 > 0) {
                        current_str = history.at(history.size() + 1 - history_current_position);
                        history_current_position--;
                    } else {
                        history_current_position = 0;
                        current_str = "";
                    }

                    rewrite();
                }
            }
        }
    } else if (curr_char != 10) {
        // Others
        char *char_str = new char[2];
        char_str[0] = curr_char;<commit_msg>Removed a wrong TODO comment<commit_after>/**
 *  repl.cpp
 *
 *  @author <NAME>
 */

#include <iostream>
#include <string>
#include <stdio.h>

#include "repl.h"
#include "conio/conio.h"
using namespace std;

REPL::REPL() {
    has_started = false;
    string_is_ready = false;
    input_marker = ":: ";
    history_current_position = 0;
}

void REPL::add_history() {
    if (history.size() >= 100) {
        history.erase(history.begin());
    }

    history.push_back(current_str);
}

void REPL::clear() {
    int curr_input_length = current_str.length() + input_marker.length();

    for (int i = 0; i < curr_input_length; i++) {
        printf("\b \b");
    }
}

void REPL::rewrite() {
    cout << input_marker + current_str << flush;
}

void REPL::read() {
    has_started = true;
    char curr_char;

    if (string_is_ready) {
        string_is_ready = false;
        current_str = "";

        cout << input_marker << flush;
    }

    //printf("%d\n", curr_char = Conio::getche());
    curr_char = Conio::getch();
    
    if (curr_char == 3) {
        // Control + C
        exit(0);
    } else if (curr_char == 127) {
        // Backspace
        if (current_str != "") {
            current_str = current_str.substr(0, current_str.length() - 1);
            printf("\b \b");
        }
    } else if (curr_char == 27) {
        if (Conio::getche() == 91) {
            // Arrow keys
            curr_char = Conio::getche();
            if (curr_char == 65) {
                // Up
                if (history_current_position < history.size()) {
                    clear();

                    current_str = history.at(history.size() - 1 - history_current_position);
                    history_current_position++;

                    rewrite();
                }
            } else if (curr_char == 66) {
                // Down
                if (history_current_position != 0) {
                    clear();

                    if (history_current_position - 1 > 0) {
                        current_str = history.at(history.size() + 1 - history_current_position);
                        history_current_position--;
                    } else {
                        history_current_position = 0;
                        current_str = "";
                    }

                    rewrite();
                }
            }
        }
    } else if (curr_char != 10) {
        // Others
        char *char_str = new char[2];
        char_str[0] = curr_char;
{'fraction_non_alphanumeric': 0.1342777334397446, 'fraction_numerical': 0.011971268954509178, 'mean_word_length': 1.5115230460921845, 'pattern_counts': {'":': 2, '<': 31, '<?xml version=': 0, '>': 15, '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': '6897240', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1486, 'n_words': 313}