<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#include <err.h>

#define MAX_LINES 1024
#define MAX_LINE_LEN 1024

typedef struct row {
    char *strings[MAX_LINES];
    int len;
    int selected;
} row_t;

// prototypes
row_t *rows_new();
void rows_add(row_t *rows, char *str);
void rows_destroy(row_t *rows);
void input(row_t *rows, int argc, char **argv);
void display(row_t *rows);
void usage();
void quitw(row_t *rows);
void quit(row_t *rows);
int main(int argc, char **argv);

//

row_t *rows_new() {
    row_t *rows = malloc(sizeof(row_t));
    rows->len = 0;
    rows->selected = 0;
    return rows;
}

void rows_add(row_t *rows, char *str) {
    rows->strings[rows->len++] = str;
}

void rows_destroy(row_t *rows) {
    for(int i = 0; i < rows->len; i++) {
        free(rows->strings[i]);
    }
    free(rows);
    rows = NULL;
}

void display(row_t *rows) {
    clear();
    for(int i = 0; i < rows->len; i++)
    {
        if (i == rows->selected) {
            attron(COLOR_PAIR(1));
        } else {
            attroff(COLOR_PAIR(1));
        }
        mvaddstr(i, 0, (const char *) rows->strings[i]);
    }
    refresh();
}

void quitw(row_t *rows) {
    rows_destroy(rows);
    exit(0);
}

void quit(row_t *rows) {
    endwin();
    quitw(rows);
}

void input(row_t *rows, int argc, char **argv) {
    switch (getch()) {
        case 'j':
            if(rows->selected < rows->len - 1)
                rows->selected++;
            break;
        case 'k':
            if(rows->selected > 0)
                rows->selected--;
            break;
        case 'q':
            quit(rows);
            break;
        case '\n':
            endwin();
            char *s = rows->strings[rows->selected];
            char *ns = malloc(MAX_LINE_LEN);
            snprintf(ns, MAX_LINE_LEN, "%s %s", argv[1], s);
            fputs(ns, stderr);
            system(ns);
            free(ns);
            quitw(rows);<commit_msg>added scrolling<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <string.h>
#include <err.h>

#define MAX_LINES 1024
#define MAX_LINE_LEN 1024

typedef struct row {
    char *strings[MAX_LINES];
    int len;
    int selected;
    int start;
} row_t;

// prototypes
row_t *rows_new();
void rows_add(row_t *rows, char *str);
void rows_destroy(row_t *rows);
void input(row_t *rows, int argc, char **argv);
void display(row_t *rows);
void usage();
void quitw(row_t *rows);
void quit(row_t *rows);
int main(int argc, char **argv);

//

row_t *rows_new() {
    row_t *rows = malloc(sizeof(row_t));
    rows->len = 0;
    rows->selected = 0;
    rows->start = 0;
    return rows;
}

void rows_add(row_t *rows, char *str) {
    rows->strings[rows->len++] = str;
}

void rows_destroy(row_t *rows) {
    for(int i = 0; i < rows->len; i++) {
        free(rows->strings[i]);
    }
    free(rows);
    rows = NULL;
}

void display(row_t *rows) {
    for(int i = 0; i < LINES; i++)
    {
        if (i == rows->selected) {
            attron(COLOR_PAIR(1));
        } else {
            attroff(COLOR_PAIR(1));
        }
        mvaddstr(i, 0, (const char *) rows->strings[rows->start + i]);
    }
    refresh();
}

void quitw(row_t *rows) {
    rows_destroy(rows);
    exit(0);
}

void quit(row_t *rows) {
    endwin();
    quitw(rows);
}

void input(row_t *rows, int argc, char **argv) {
    switch (getch()) {
        case 'j':
            if(rows->start + rows->selected < rows->len - 1)
            {
                if(rows->selected >= LINES - 3 && rows->start + rows->selected + 3 < rows->len)
                    rows->start++;
                else
                    rows->selected++;
            }
            break;
        case 'k':
            if(rows->start + rows->selected > 0)
            {
                if(rows->selected < 3 && rows->start + rows->selected - 2 > 0)
                    rows->start--;
                else
                    rows->selected--;
            }
            break;
        case 'q':
            quit(rows);
            break;
        case '\n':
            endwin();
            char *s = rows->strings[rows->selected];
            char *ns = malloc(MAX_LINE_LEN);
            snprintf(ns, MAX_LINE_LEN, "%s %s", argv[1], s);
            fputs(ns, stderr);
            system(ns);
            free(ns);
            quitw(rows);
{'fraction_non_alphanumeric': 0.16004566210045662, 'fraction_numerical': 0.01004566210045662, 'mean_word_length': 1.9363270777479893, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 61, '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': '383520', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1512, 'n_words': 361}