<commit_before>#include <ncurses.h>
#include <stdbool.h>
#include <signal.h>
#include <stdlib.h>

static bool Running = true;
//static int Term_X = 0;
//static int Term_Y = 0;
static WINDOW* WindowLeft;
static WINDOW* WindowRight;

static int Idx = 0; /* TODO: this should be per-window */

void list_files(WINDOW* win) {
    FILE* ls = popen("ls", "r");
    char* filename = NULL;
    size_t len = 0;
    ssize_t read;
    int topbuff=1; /* lines to skip before printing (window border/title) */
    int i = 0;
    int rows, cols;
    getmaxyx(win, rows, cols);
    while ((read = getline(&filename, &len, ls)) != -1){
        if(i==Idx){
            wattron(win, A_STANDOUT);
            wattron(win, A_BOLD);
        }
        mvwaddnstr(win, i+topbuff, 1, filename, cols-2); /* prevent spilling out of window with long filenames */
        if(i==Idx){
            wattroff(win, A_STANDOUT);
            wattroff(win, A_BOLD);
        }
        i++;
        if(i>rows) break; /* TODO: implement scrolling to handle when there are more files than lines */
    }
    if(filename) free(filename);
}

void handle_input(char ch) {
    if(ch == 'q')
        Running = false;
    if(ch == 'j')
        Idx+=1;
    if(ch == 'k' && Idx>0)
        Idx-=1;
}

WINDOW* create_window(int x, int y, int height, int width) {
    WINDOW* p_win = newwin(height, width, y, x);
    box(p_win, 0, 0);
    wrefresh(p_win);
    return p_win;
}

void destroy_window(WINDOW* p_win) {
    /* Erase remnants of the window */
    wborder(p_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
    wrefresh(p_win);<commit_msg>store file list in memory; don't scroll past end<commit_after>#include <ncurses.h>
#include <stdbool.h>
#include <signal.h>
#include <stdlib.h>

static bool Running = true;
//static int Term_X = 0;
//static int Term_Y = 0;
static WINDOW* WindowLeft;
static WINDOW* WindowRight;

static int Idx = 0; /* TODO: this should be per-window */
//static char* Cwd = ""; /* TODO; this should be per-window */
static char** Files; /* TODO: this should be per-window */
static int FileCount; /* TODO: ditto */

/* TODO redraw less frequently */
/* TODO detect filesystem changes */

/*TODO: when have collection of windows and ^^ vars are in a struct, should take a windex*/
void get_files(){
    /*free existing contents*/
    int i=0;
    if(Files){
        /*fuck memory (this is broken)
        while(Files[i]){
            free(Files[i]);
            i++;
        }*/
        free(Files);
    }
    /* TODO: malloc smartly, instead of tapping out at 1024 files */
    Files = malloc(sizeof(char*)*1024);
    Files[0] = ".."; /* parent directory; todo only add if cwd!=/ */
    FILE* ls = popen("ls", "r");
    size_t len = 0;
    ssize_t read;
    i=1;
    while ((read = getline(&Files[i], &len, ls)) != -1){
        i++;
        if(i>1022) break;
    }
    FileCount=i-1;
    Files[i]=0; /*always end with nullpointer */
}

void list_files(WINDOW* win) {
    get_files();
    int topbuff=1; /* lines to skip before printing (window border/title) */
    int i = 0;
    int rows, cols;
    getmaxyx(win, rows, cols);
    while (Files[i] != 0){
        if(i==Idx){
            wattron(win, A_STANDOUT);
            wattron(win, A_BOLD);
        }
        mvwaddnstr(win, i+topbuff, 1, Files[i], cols-2); /* prevent spilling out of window with long filenames */
        if(i==Idx){
            wattroff(win, A_STANDOUT);
            wattroff(win, A_BOLD);
        }
        i++;
        if(i>rows) break; /* TODO: implement scrolling to handle when there are more files than lines */
    }
}

void handle_input(char ch) {
    if(ch == 'q')
        Running = false;
    if(ch == 'j' && Idx<FileCount)
        Idx+=1;
    if(ch == 'k' && Idx>0)
        Idx-=1;
}

WINDOW* create_window(int x, int y, int height, int width) {
    WINDOW* p_win = newwin(height, width, y, x);
    box(p_win, 0, 0);
    wrefresh(p_win);
    return p_win;
}

void destroy_window(WINDOW* p_win) {
    /* Erase remnants of the window */
    wborder(p_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
    wrefresh(p_win);
{'fraction_non_alphanumeric': 0.158062930186824, 'fraction_numerical': 0.011307767944936086, 'mean_word_length': 2.486718080548415, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, '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': '860953', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1448, 'n_words': 417}