+#include <stdlib.h>
+#include <string.h>
+
#include "input.h"
#include "state.h"
#include "workdir.h"
#include "screen.h"
-#include <stdlib.h>
-#include <string.h>
+#include "frame.h"
#define ESC 27
}
static void handle_next(void) {
- workdir_next(state_get_focused_frame()->workdir);
+ workdir_next(state_get_focused_workdir());
}
static void handle_prev(void) {
- workdir_prev(state_get_focused_frame()->workdir);
+ workdir_prev(state_get_focused_workdir());
}
static void handle_cd(void) {
- workdir_cd(state_get_focused_frame()->workdir);
+ workdir_cd(state_get_focused_workdir());
}
static void handle_scroll_to_top(void) {
- workdir_scroll_to_top(state_get_focused_frame()->workdir);
+ workdir_scroll_to_top(state_get_focused_workdir());
}
static void handle_scroll_to_bottom(void) {
- workdir_scroll_to_bot(state_get_focused_frame()->workdir);
+ workdir_scroll_to_bot(state_get_focused_workdir());
}
static void handle_page_up(void){
- screen_frame_page_up(state_get_focused_frame());
+ frame_page_up(state_get_focused_frame());
}
static void handle_page_down(void){
- screen_frame_page_down(state_get_focused_frame());
+ frame_page_down(state_get_focused_frame());
}
static void handle_expand(void){
- workdir_expand_selected(state_get_focused_frame()->workdir);
+ workdir_expand_selected(state_get_focused_workdir());
}
static void handle_collapse(void){
- workdir_collapse_selected(state_get_focused_frame()->workdir);
+ workdir_collapse_selected(state_get_focused_workdir());
}
static void search_mode(void){
searchstr[searchlen] = inpt;
searchlen += 1;
searchstr[searchlen] = 0;
- workdir_seek(state_get_focused_frame()->workdir, searchstr);
+ workdir_seek(state_get_focused_workdir(), searchstr);
}
if(state_get_screen_dirty()) screen_update();
}
/* internal headers */
#include "screen.h"
+#include "frame.h"
#include "state.h"
#include "aardvark.h"
-#include "workdir.h"
static void screen_place_windows(void);
static void screen_refresh_curr_frame(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;
-static int FrameTopBuffer = 2;
-static int FrameBotBuffer = 2;
+static list_t* Frame_List;
-static frame_t* master_frame(void){
- return (frame_t*) Screen_List->head->contents;
+static Frame_T* master_frame(void){
+ return (Frame_T*) Frame_List->head->contents;
}
void screen_init(void) {
- Screen_List = list_new();
- list_push_back(Screen_List, screen_frame_new());
+ Frame_List = list_new();
+ list_push_back(Frame_List, frame_new());
state_set_focused_frame(master_frame());
}
void screen_deinit(void) {
- mem_release(Screen_List);
+ mem_release(Frame_List);
}
void screen_update(void) {
}
void screen_open(void) {
- list_push_back(Screen_List, screen_frame_new());
+ list_push_back(Frame_List, frame_new());
state_set_screen_dirty(true);
state_set_screen_resized(true);
}
void screen_close(void) {
- int num_frames = list_size(Screen_List);
+ int num_frames = list_size(Frame_List);
if(num_frames > 1){
- list_delete(Screen_List, 0);
+ list_delete(Frame_List, 0);
state_set_focused_frame(master_frame());
}
state_set_screen_dirty(true);
}
static void screen_place_windows(void) {
- frame_t* p_frame;
+ Frame_T* p_frame;
int id, pos, lines, cols;
- int num_frames = list_size(Screen_List);
+ int num_frames = list_size(Frame_List);
list_node_t* p_node;
getmaxyx(stdscr, lines, cols);
/* Print the master frame */
- p_frame = list_at(Screen_List,0)->contents;
+ p_frame = list_at(Frame_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);
+ 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);
+ p_node = list_at(Frame_List,1);
pos = 0;
id = 1;
while(p_node != NULL) {
mvwin(p_frame->p_win, pos, cols/2);
wresize(p_frame->p_win, height, cols/2);
wclear(p_frame->p_win);
- screen_frame_draw_files(p_frame);
+ frame_draw_files(p_frame);
wmove(p_frame->p_win, 1, 1);
box(p_frame->p_win, 0 , 0);
wrefresh(p_frame->p_win);
}
}
-
static void screen_refresh_curr_frame(void) {
/* Print the master frame */
- frame_t* p_frame = list_at(Screen_List,0)->contents;
+ Frame_T* p_frame = list_at(Frame_List,0)->contents;
wclear(p_frame->p_win);
- screen_frame_draw_files(p_frame);
+ frame_draw_files(p_frame);
box(p_frame->p_win, 0 , 0);
wrefresh(p_frame->p_win);
}
-//get the curent directory and copy it into a ref-counted memory block
-//return a pointer to the new block
-char* pwd(){
- char* dir = getcwd(NULL, 0);
- char* rid = mem_allocate(sizeof(char)*(1+strlen(dir)), NULL);
- strcpy(rid, dir);
- free(dir);
- return rid;
-}
-
-static frame_t* screen_frame_new(void) {
- frame_t* p_frame = (frame_t*)mem_allocate(sizeof(frame_t),&screen_frame_free);
- p_frame->p_win = newwin(1, 1, 0, 0);
- p_frame->top_index = 0;
- bool first_window = !state_get_focused_frame();
- char* path = first_window ? pwd() : state_get_focused_frame()->workdir->path;
- p_frame->workdir = workdir_new(path);
- if(first_window) mem_release(path);
- return p_frame;
-}
-
-static void screen_frame_free(void* p_frame_ptr) {
- frame_t* p_frame = (frame_t*)p_frame_ptr;
- wclear(p_frame->p_win);
- wborder(p_frame->p_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
- wrefresh(p_frame->p_win);
- delwin(p_frame->p_win);
- if(p_frame->workdir) mem_release(p_frame->workdir);
-}
-
-static int count_double_lines(frame_t* p_frame){
- int count = 0;
- for(int i = p_frame->top_index; i <= p_frame->workdir->idx; i++)
- if (((File_T*)vec_at(p_frame->workdir->vfiles, i))->expanded) count++;
- return count;
-}
-
-static void screen_frame_scroll(frame_t* p_frame){
- int rows,cols;
- getmaxyx(p_frame->p_win, rows, cols);
- (void) cols;
- if(p_frame->workdir->idx < p_frame->top_index){
- p_frame->top_index = p_frame->workdir->idx;
- }else{
- int doublelines = count_double_lines(p_frame);
- if (p_frame->top_index < doublelines+p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer))
- p_frame->top_index = doublelines+p_frame->workdir->idx-(rows-FrameTopBuffer-FrameBotBuffer);
- }
-}
-
-void screen_frame_draw_files(frame_t* frame){
- int file_i, frame_i = FrameTopBuffer;
- int rows, cols;
- getmaxyx(frame->p_win, rows, cols);
- screen_frame_scroll(frame);
- file_i = frame->top_index;
- //draw path
- wattron(frame->p_win, A_UNDERLINE);
- mvwaddnstr(frame->p_win, 1, 1, frame->workdir->path, cols-2);
- wattroff(frame->p_win, A_UNDERLINE);
- //list files
- while (file_i < vec_size(frame->workdir->vfiles)){
- File_T* file = (File_T*)vec_at(frame->workdir->vfiles, file_i);
- bool dir = is_dir(file->path);
- if(frame == state_get_focused_frame() && file_i == frame->workdir->idx){
- wattron(frame->p_win, A_STANDOUT | A_BOLD);
- }
- if(dir) wattron(frame->p_win, COLOR_PAIR(DIRECTORY));
- mvwaddnstr(frame->p_win, frame_i, 1, file->name, cols-2);
- frame_i++;
- if(file->expanded){
- mvwprintw(frame->p_win, frame_i, 1, " owned by user id %d, group id %d", file->uid, file->gid);
- frame_i++;
- }
- wstandend(frame->p_win);
- file_i++;
- if((frame_i+FrameBotBuffer) > rows) break;
- }
-}
-
-int realrows(frame_t* p_frame){
- int rows, cols;
- getmaxyx(p_frame->p_win, rows, cols);
- (void) cols;
- return rows - FrameTopBuffer - FrameBotBuffer;
-}
-
-void screen_frame_page_up(frame_t* p_frame){
- workdir_set_idx(p_frame->workdir, p_frame->workdir->idx - realrows(p_frame));
-}
-
-void screen_frame_page_down(frame_t* p_frame){
- workdir_set_idx(p_frame->workdir, p_frame->workdir->idx+realrows(p_frame));
-}
-
+#include "frame.h"
#include "state.h"
#include "screen.h"
static bool AardvarkOn = false;
/** A pointer to the currently focused frame */
-static frame_t* Focused_Frame = 0;
+static Frame_T* Focused_Frame = 0;
static Mode_T CurrentMode = 0;
-bool state_get_running(void)
-{
+bool state_get_running(void) {
return Running;
}
-void state_set_running(bool val)
-{
+void state_set_running(bool val) {
Running = val;
}
-bool state_get_screen_dirty(void)
-{
+bool state_get_screen_dirty(void) {
return Screen_Dirty;
}
-void state_set_screen_dirty(bool val)
-{
+void state_set_screen_dirty(bool val) {
Screen_Dirty = val;
}
-bool state_get_screen_resized(void)
-{
+bool state_get_screen_resized(void) {
return Resized;
}
-void state_set_screen_resized(bool val)
-{
+void state_set_screen_resized(bool val) {
Resized = val;
}
-bool state_get_aardvark_mode(void)
-{
+bool state_get_aardvark_mode(void) {
return AardvarkOn;
}
-void state_set_aardvark_mode(bool val)
-{
+void state_set_aardvark_mode(bool val) {
AardvarkOn = val;
}
-frame_t* state_get_focused_frame(void) {
+Frame_T* state_get_focused_frame(void) {
return Focused_Frame;
}
-void state_set_focused_frame(frame_t *p_frame)
-{
+WorkDir_T* state_get_focused_workdir(void) {
+ return Focused_Frame->workdir;
+}
+
+void state_set_focused_frame(Frame_T *p_frame) {
Focused_Frame = p_frame;
}
-Mode_T state_get_mode(){
+Mode_T state_get_mode() {
return CurrentMode;
}
-void state_set_mode(Mode_T m){
+void state_set_mode(Mode_T m) {
CurrentMode = m;
}