From: Michael D. Lowis Date: Sun, 20 Jul 2014 23:44:23 +0000 (-0400) Subject: partial implementation of window handling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3a0407cac8ccdc2e6b4c93e480ea349e04d45637;p=archive%2Fafm.git partial implementation of window handling --- diff --git a/source/input.c b/source/input.c index 1606ec3..2f147d2 100644 --- a/source/input.c +++ b/source/input.c @@ -1,6 +1,7 @@ #include "input.h" #include "state.h" #include "workdir.h" +#include "screen.h" void input_handle_key(char ch) { /* Assume screen is dirty by default */ @@ -16,6 +17,10 @@ void input_handle_key(char ch) { break; case 'e': workdir_cd(); break; + case 'n': screen_open(); + break; + case 'c': screen_close(); + break; default: is_screen_dirty = false; break; } diff --git a/source/main.c b/source/main.c index 1144df3..8417d56 100644 --- a/source/main.c +++ b/source/main.c @@ -29,6 +29,7 @@ int main(int argc, char** argv) { noecho(); timeout(25); refresh(); + screen_init(); while(state_get_running()) { if(state_get_screen_dirty()) screen_update(); input_handle_key(getch()); diff --git a/source/screen.c b/source/screen.c index 3e82e35..e2096cd 100644 --- a/source/screen.c +++ b/source/screen.c @@ -3,6 +3,24 @@ #include "aardvark.h" #include "workdir.h" #include +#include "vec.h" +#include "mem.h" + +typedef struct { + WINDOW* p_win; +} frame_t; + +static void screen_place_windows(void); +static frame_t* screen_frame_new(void); +static void screen_frame_free(void* p_frame); + +static int Master_Idx; +static vec_t* Screen_List; + +void screen_init(void) { + Screen_List = vec_new(1, screen_frame_new()); + Master_Idx = 0; +} void screen_update(void) { /* Clear screen and update LINES and COLS */ @@ -11,19 +29,52 @@ void screen_update(void) { state_set_screen_resized(false); } clear(); - //should probably redraw all, but since only one window exists, it doesn't matter - workdir_ls(); + refresh(); + screen_place_windows(); if(state_get_aardvark_mode()) aardvark_draw(); - /* Draw the Border */ - mvaddch(0, 0, ACS_ULCORNER); - mvhline(0, 1, ACS_HLINE, COLS-2); - mvaddch(0, COLS-1, ACS_URCORNER); - mvvline(1, 0, ACS_VLINE, LINES-2); - mvaddch(LINES-1, 0, ACS_LLCORNER); - mvhline(LINES-1, 1, ACS_HLINE, COLS-2); - mvaddch(LINES-1, COLS-1, ACS_LRCORNER); - mvvline(1, COLS-1, ACS_VLINE, LINES-2); /* Refresh and mark complete */ - refresh(); state_set_screen_dirty(false); } + +void screen_open(void) { + vec_push_back(Screen_List, screen_frame_new()); +} + +void screen_close(void) { + vec_erase(Screen_List, 0, 1); +} + +static void screen_place_windows(void) { + frame_t* p_frame; + int i, lines, cols; + getmaxyx(stdscr, lines, cols); + move(0,0); + for(i = 0; i < vec_size(Screen_List); i++) { + p_frame = (frame_t*)vec_at(Screen_List, i); + printw("%d", vec_size(Screen_List)); + if(i == Master_Idx) { + wmove(p_frame->p_win, 0, 0); + wresize(p_frame->p_win, lines, (vec_size(Screen_List) == 1) ? cols : cols/2); + box(p_frame->p_win, 0 , 0); + wrefresh(p_frame->p_win); + } else { + wmove(p_frame->p_win, 0, cols/2); + wresize(p_frame->p_win, lines, cols/2); + box(p_frame->p_win, 0 , 0); + wrefresh(p_frame->p_win); + } + } +} + +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(LINES, COLS, 0, 0); + return p_frame; +} + +static void screen_frame_free(void* p_frame_ptr) { + frame_t* p_frame = (frame_t*)p_frame_ptr; + wborder(p_frame->p_win, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '); + wrefresh(p_frame->p_win); + delwin(p_frame->p_win); +} diff --git a/source/screen.h b/source/screen.h index d400a41..44f7114 100644 --- a/source/screen.h +++ b/source/screen.h @@ -7,6 +7,9 @@ #ifndef SCREEN_H #define SCREEN_H +void screen_init(void); void screen_update(void); +void screen_open(void); +void screen_close(void); #endif /* SCREEN_H */