void frame_set_highlighting(Frame_T* frame, bool highlight, bool refresh_win){
- if(frame){
- int rows,cols;
- int line = FrameTopBuffer + count_double_lines_to_idx(frame, false) + frame->workdir->idx - frame->top_index;
- attr_t newattr= highlight ? (A_STANDOUT|A_BOLD) : A_NORMAL;
- File_T* file = (File_T*) vec_at(frame->workdir->vfiles, frame->workdir->idx);
- short color = (file && is_dir(file->path) ? DIRECTORY : 0);
- getmaxyx(frame->p_win, rows, cols);
- (void) rows;
- mvwchgat(frame->p_win, line, 1, cols-2, newattr, color, NULL);
- if(file && file->expanded) mvwchgat(frame->p_win, line+1, 1, cols-2, newattr, color, NULL);
- wmove(frame->p_win, 0, 0); //move the cursor out of the way
- if(frame_scroll(frame)) state_set_screen_dirty(true);
- if(refresh_win) wrefresh(frame->p_win);
- }
+ if(frame){
++ int rows,cols;
+ int line = FrameTopBuffer + count_double_lines_to_idx(frame, false) + frame->workdir->idx - frame->top_index;
+ attr_t newattr= highlight ? (A_STANDOUT|A_BOLD) : A_NORMAL;
+ File_T* file = (File_T*) vec_at(frame->workdir->vfiles, frame->workdir->idx);
+ short color = (file && is_dir(file->path) ? DIRECTORY : 0);
- mvwchgat(frame->p_win, line, 0, -1, newattr, color, NULL);
- if(file && file->expanded) mvwchgat(frame->p_win, line+1, color, -1, newattr, 0, NULL);
++ getmaxyx(frame->p_win, rows, cols);
++ (void) rows;
++ mvwchgat(frame->p_win, line, 1, cols-2, newattr, color, NULL);
++ if(file && file->expanded) mvwchgat(frame->p_win, line+1, 1, cols-2, newattr, color, NULL);
++ wmove(frame->p_win, 0, 0); //move the cursor out of the way
+ if(frame_scroll(frame)) state_set_refresh_state(REFRESH_CURR_WIN);
+ if(refresh_win) wrefresh(frame->p_win);
+ }
}
static list_t* Frame_List;
- int i = 0;
- list_node_t* edon = Frame_List->head;
- while(edon!=NULL && edon != node) { edon = edon->next; i++; }
- return (edon!=NULL ? i : -1 );
+/* TODO: add equiv. function to list */
+static int get_index_of_node(list_node_t* node){
++ int i = 0;
++ list_node_t* edon = Frame_List->head;
++ while(edon!=NULL && edon != node) { edon = edon->next; i++; }
++ return (edon!=NULL ? i : -1 );
+}
+
void screen_init(void) {
+ /* Initialize ncurses */
+ initscr();
+ start_color();
+ init_pair(DIRECTORY, COLOR_BLUE, COLOR_BLACK);
+ init_pair(2, COLOR_MAGENTA, COLOR_BLACK);
+ init_pair(3, COLOR_RED, COLOR_BLACK);
+ init_pair(4, COLOR_YELLOW, COLOR_BLACK);
+ init_pair(5, COLOR_GREEN, COLOR_BLACK);
+ init_pair(6, COLOR_CYAN, COLOR_BLACK);
+ raw();
+ keypad(stdscr, TRUE);
+ noecho();
+ timeout(25);
+ refresh();
+ /* Initialize the frame list */
Frame_List = list_new();
list_push_back(Frame_List, frame_new());
state_set_focused_node(Frame_List->head);
void screen_open(void) {
list_push_back(Frame_List, frame_new());
- state_set_screen_dirty(true);
- state_set_screen_resized(true);
+ state_set_refresh_state(REFRESH_ALL_WINS);
}
-/* TODO: add equiv. function to list */
static int get_focused_frame_index(void){
- return get_index_of_node(state_get_focused_node());
- int i = 0;
- list_node_t* n = Frame_List->head;
- while(n != state_get_focused_node() && n != Frame_List->tail){ n = n->next; i++; }
- if(n != state_get_focused_node()) i = -1;
- return i;
++ return get_index_of_node(state_get_focused_node());
}
void screen_close(void) {
// new_focus will be null if rm-d tail: set it to new tail
if(new_focus == NULL) new_focus = Frame_List->tail;
state_set_focused_node(new_focus);
- state_set_screen_dirty(true);
- state_set_screen_resized(true);
+ state_set_refresh_state(REFRESH_ALL_WINS);
mem_release(doomed_node);
- fprintf(stderr, "frame not found\n");
- }
+ }else{
++ fprintf(stderr, "frame not found\n");
+ }
}
}
int num_frames = list_size(Frame_List);
list_node_t* p_node;
getmaxyx(stdscr, lines, cols);
-
/* Print the master frame */
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);
- frame_draw_files(p_frame);
- box(p_frame->p_win, 0 , 0);
- wrefresh(p_frame->p_win);
+ frame_move(p_frame, 0, 0);
+ frame_resize(p_frame, lines, (num_frames > 1) ? cols/2 : cols);
+ frame_draw(p_frame);
/* Print any other frames we might have */
p_node = list_at(Frame_List,1);
void screen_focus_next(void){
list_node_t* focused = state_get_focused_node();
state_set_focused_node(focused->next ? focused->next : Frame_List->head);
- state_set_screen_dirty(true);
+ state_set_refresh_state(REFRESH_CURR_WIN);
}
- list_node_t* prev = (Frame_List->head == node) ? NULL : Frame_List->head;
- while(prev && prev->next != node) prev=prev->next;
- return prev;
+//TODO: this should be a function in list.h
+list_node_t* find_prev_node(list_node_t* node){
++ list_node_t* prev = (Frame_List->head == node) ? NULL : Frame_List->head;
++ while(prev && prev->next != node) prev=prev->next;
++ return prev;
+}
+
void screen_focus_prev(void){
- list_node_t* prev = find_prev_node(state_get_focused_node());
- if(!prev) prev = Frame_List->tail;
- state_set_focused_node(prev);
- state_set_screen_dirty(true);
- int i = get_focused_frame_index();
- if(i >= 0){
- list_node_t* prev = (i == 0) ? Frame_List->tail : list_at(Frame_List, i-1);
- if(prev) state_set_focused_node(prev);
- state_set_refresh_state(REFRESH_CURR_WIN);
- }
++ list_node_t* prev = find_prev_node(state_get_focused_node());
++ if(!prev) prev = Frame_List->tail;
++ state_set_focused_node(prev);
++ state_set_refresh_state(REFRESH_CURR_WIN);
}
void screen_focus_master(void){
state_set_focused_node(Frame_List->head);
- state_set_screen_dirty(true);
+ state_set_refresh_state(REFRESH_CURR_WIN);
}
- //this almost works. may need to manually force refresh (R) after repositioning windows
- //unknown why screen_force_redraw at bottom is insufficient
- //TODO: this should be done by callign functions in list.h
- //but reqd functions do not exist yet
- list_node_t* focused = state_get_focused_node();
- list_node_t* master = Frame_List->head;
- list_node_t* prev = find_prev_node(focused);
- list_node_t* tmp = master->next;
- if(prev){ //if prev is null, implies focus is already master & should do nothing
- //put master in list
- if(prev!=master) prev->next = master;
- master->next = focused->next;
- //make focused new heaad
- if(focused != tmp) focused->next = tmp;
- else focused->next = master;
- Frame_List->head = focused;
- //fix tail if put master at end
- if(master->next == NULL) Frame_List->tail = master;
- screen_force_redraw();
- }
- }
-
- void screen_force_redraw(void){
- state_set_screen_dirty(true);
- state_set_screen_resized(true);
+void screen_swap_with_master(void){
++ //this almost works. may need to manually force refresh (R) after repositioning windows
++ //unknown why screen_force_redraw at bottom is insufficient
++ //TODO: this should be done by callign functions in list.h
++ //but reqd functions do not exist yet
++ list_node_t* focused = state_get_focused_node();
++ list_node_t* master = Frame_List->head;
++ list_node_t* prev = find_prev_node(focused);
++ list_node_t* tmp = master->next;
++ if(prev){ //if prev is null, implies focus is already master & should do nothing
++ //put master in list
++ if(prev!=master) prev->next = master;
++ master->next = focused->next;
++ //make focused new heaad
++ if(focused != tmp) focused->next = tmp;
++ else focused->next = master;
++ Frame_List->head = focused;
++ //fix tail if put master at end
++ if(master->next == NULL) Frame_List->tail = master;
++ state_set_refresh_state(REFRESH_ALL_WINS);
++ }
+}
+