<commit_before>/* external libraries */
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>

/* internal libraries */
#include "vec.h"
#include "list.h"
#include "mem.h"

/* internal headers */
#include "screen.h"
#include "state.h"
#include "aardvark.h"
#include "workdir.h"

static void screen_place_windows(void);
static frame_t* screen_frame_new(void);
static void screen_frame_free(void* p_frame);
void screen_frame_draw_files(frame_t* frame);

static list_t* Screen_List;

frame_t* master_frame(void){
	return (frame_t*) Screen_List->head->contents;
}

void screen_init(void) {
    Screen_List = list_new();
    list_push_back(Screen_List, screen_frame_new());
    state_set_focused_frame(master_frame());
}

void screen_deinit(void) {
    mem_release(Screen_List);
}

void screen_update(void) {
    /* Clear screen and update LINES and COLS */
    if(state_get_screen_resized()){
        endwin();
        state_set_screen_resized(false);
    }
    clear();
    refresh();
    screen_place_windows();
    if(state_get_aardvark_mode()) aardvark_draw();
    /* Refresh and mark complete */
    state_set_screen_dirty(false);
}

void screen_open(void) {
    list_push_back(Screen_List, screen_frame_new());
}

void screen_close(void) {
    int num_frames = list_size(Screen_List);
    if(num_frames > 1)
        list_delete(Screen_List, 0);
}

static void screen_place_windows(void) {
    frame_t* p_frame;
    int id, pos, lines, cols;
    int num_frames = list_size(Screen_List);
    list_node_t* p_node;
    getmaxyx(stdscr, lines, cols);

    /* Print the master frame */
    p_frame = list_at(Screen_List,0)->contents;
    mvwin(p_frame->p_win, 0, 0);
    wresize(p_frame->p_win, lines, (num_frames > 1) ? cols/2 : cols);
    wclear(p_frame->p_win);
    screen_frame_draw_files(p_frame);
    box(p_frame->p_win, 0 , 0);
    wrefresh(p_frame->p_win);

    /* Print any other frames we might have */
    p_node = list_at(Screen_List,1);
    pos = 0;
    id = 1;
    while(p_node != NULL) {<commit_msg>reset focus after deleting a window<commit_after>/* external libraries */
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>

/* internal libraries */
#include "vec.h"
#include "list.h"
#include "mem.h"

/* internal headers */
#include "screen.h"
#include "state.h"
#include "aardvark.h"
#include "workdir.h"

static void screen_place_windows(void);
static frame_t* screen_frame_new(void);
static void screen_frame_free(void* p_frame);
void screen_frame_draw_files(frame_t* frame);

static list_t* Screen_List;

frame_t* master_frame(void){
	return (frame_t*) Screen_List->head->contents;
}

void screen_init(void) {
    Screen_List = list_new();
    list_push_back(Screen_List, screen_frame_new());
    state_set_focused_frame(master_frame());
}

void screen_deinit(void) {
    mem_release(Screen_List);
}

void screen_update(void) {
    /* Clear screen and update LINES and COLS */
    if(state_get_screen_resized()){
        endwin();
        state_set_screen_resized(false);
    }
    clear();
    refresh();
    screen_place_windows();
    if(state_get_aardvark_mode()) aardvark_draw();
    /* Refresh and mark complete */
    state_set_screen_dirty(false);
}

void screen_open(void) {
    list_push_back(Screen_List, screen_frame_new());
}

void screen_close(void) {
    int num_frames = list_size(Screen_List);
    if(num_frames > 1){
        list_delete(Screen_List, 0);
		state_set_focused_frame(master_frame());
    }
}

static void screen_place_windows(void) {
    frame_t* p_frame;
    int id, pos, lines, cols;
    int num_frames = list_size(Screen_List);
    list_node_t* p_node;
    getmaxyx(stdscr, lines, cols);

    /* Print the master frame */
    p_frame = list_at(Screen_List,0)->contents;
    mvwin(p_frame->p_win, 0, 0);
    wresize(p_frame->p_win, lines, (num_frames > 1) ? cols/2 : cols);
    wclear(p_frame->p_win);
    screen_frame_draw_files(p_frame);
    box(p_frame->p_win, 0 , 0);
    wrefresh(p_frame->p_win);

    /* Print any other frames we might have */
    p_node = list_at(Screen_List,1);
    pos = 0;
    id = 1;
    while(p_node != NULL) {
{'fraction_non_alphanumeric': 0.13230994152046785, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 4.13125, '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': '3573739', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1504, 'n_words': 300}