]> git.mdlowis.com Git - archive/afm.git/commitdiff
split frame from screen. rm some unneeded includes. add focused_workdir getter to...
authora bellenir <a@bellenir.com>
Mon, 28 Jul 2014 04:16:05 +0000 (04:16 +0000)
committera bellenir <a@bellenir.com>
Mon, 28 Jul 2014 04:16:05 +0000 (04:16 +0000)
source/aardvark.c
source/input.c
source/main.c
source/screen.c
source/screen.h
source/state.c
source/state.h
source/workdir.c

index 25df8cf86edc53e5e30567e58165f7c7ecb612ca..a9ebcdf5bc315793b06d5202d521b9562230649d 100644 (file)
@@ -1,7 +1,8 @@
-#include "aardvark.h"
 #include <stdint.h>
 #include <ncurses.h>
 
+#include "aardvark.h"
+
 typedef struct {
     uint8_t a, b, c;
 } Triplet_T;
index 6916a2b8bbe48763a75681d9ffb2c27055fbac6b..e1ab9b31a3c2c1d81dea9f744a1e76475a1bbb8d 100644 (file)
@@ -1,9 +1,11 @@
+#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
 
@@ -24,39 +26,39 @@ static void handle_quit(void) {
 }
 
 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){
@@ -81,7 +83,7 @@ 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();
     }
index cf7f83a5d71e2af5ce3a2d33777e8cf70f820023..2d4dc6d2eec064424ecc167ed0b4313d9c604a3d 100644 (file)
@@ -6,11 +6,9 @@
 #include <unistd.h> /*TODO: anything using this is almost certainly broken on windows */
 #include <string.h>
 
-#include "aardvark.h"
 #include "state.h"
 #include "input.h"
 #include "screen.h"
-#include "workdir.h"
 
 void handle_signal(int sig) {
     state_set_screen_dirty(true);
index 96a148436e1e068ad8f36ca3d22b1930dbb48d4b..8767b4041792ca2c17a7ec0671e8ef7bb385ba71 100644 (file)
 
 /* 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) {
@@ -54,15 +49,15 @@ 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);
@@ -70,23 +65,23 @@ void screen_close(void) {
 }
 
 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) {
@@ -98,7 +93,7 @@ static void screen_place_windows(void) {
         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);
@@ -109,108 +104,12 @@ static void screen_place_windows(void) {
     }
 }
 
-
 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));
-}
-
index 82dc985c2438efba49df26766df6f0e3d68bf853..c082b195dd4e2dc17595150e90b69aa842bf39ef 100644 (file)
@@ -7,26 +7,11 @@
 #ifndef SCREEN_H
 #define SCREEN_H
 
-#include <ncurses.h>
-#include "workdir.h"
-
 void screen_init(void);
 void screen_deinit(void);
 void screen_update(void);
 void screen_open(void);
 void screen_close(void);
 
-typedef struct {
-    WINDOW* p_win;
-    WorkDir_T* workdir;
-    int top_index;
-} frame_t;
-
-enum ColorPairs {
-    DIRECTORY = 1
-};
-
-void screen_frame_page_up(frame_t* p_frame);
-void screen_frame_page_down(frame_t* p_frame);
 
 #endif /* SCREEN_H */
index 20e3f84df1403e34389e653d85f3d55fc633a6b0..5972fa6a4161cb1389ea683ded455a8e6c35c530 100644 (file)
@@ -1,3 +1,4 @@
+#include "frame.h"
 #include "state.h"
 #include "screen.h"
 
@@ -14,64 +15,59 @@ static bool Resized = true;
 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;
 }
 
index cc342efba769ae7dcee145f85d2e21e319e507a4..de24383c946379415007feb8098fd66682db8e5a 100644 (file)
@@ -8,7 +8,9 @@
 #define STATE_H
 
 #include <stdbool.h>
-#include "screen.h"
+#include "frame.h"
+#include "workdir.h"
+
 
 typedef enum{ MODE_NORMAL, MODE_SEARCH } Mode_T;
 
@@ -20,8 +22,9 @@ bool state_get_screen_resized(void);
 void state_set_screen_resized(bool val);
 bool state_get_aardvark_mode(void);
 void state_set_aardvark_mode(bool val);
-frame_t* state_get_focused_frame(void);
-void state_set_focused_frame(frame_t* p_frame);
+Frame_T* state_get_focused_frame(void);
+WorkDir_T* state_get_focused_workdir(void);
+void state_set_focused_frame(Frame_T* p_frame);
 Mode_T state_get_mode(void);
 void state_set_mode(Mode_T);
 
index 19d2583b99d50a5799e95d9746ff62d6c0589c38..37a0b01daa5e421fbb5e9ae29201c8d692557cf1 100644 (file)
@@ -11,9 +11,8 @@
 #include "mem.h"
 
 /* internal headers */
-#include "state.h"
 #include "workdir.h"
-#include "screen.h"
+#include "state.h"
 
 bool is_dir(char* path) {
     struct stat s;