From: abellenir Date: Sat, 26 Jul 2014 05:11:30 +0000 (+0000) Subject: colors! X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b2273d95d89fbdd63fc9a6a5c790f70c4121c109;p=archive%2Fafm.git colors! --- diff --git a/source/main.c b/source/main.c index 5809f4a..86ecf80 100644 --- a/source/main.c +++ b/source/main.c @@ -22,6 +22,8 @@ int main(int argc, char** argv) { signal(SIGWINCH, handle_signal); /* Initialize ncurses and user input settings */ initscr(); + start_color(); + init_pair(DIRECTORY, COLOR_BLUE, COLOR_BLACK); raw(); keypad(stdscr, TRUE); noecho(); diff --git a/source/screen.c b/source/screen.c index d48921b..023e159 100644 --- a/source/screen.c +++ b/source/screen.c @@ -145,17 +145,20 @@ void screen_frame_draw_files(frame_t* frame){ //list files while (i < vec_size(frame->workdir->vfiles)){ char* filename = (char*)vec_at(frame->workdir->vfiles, i); + bool dir = is_dir(filename); if(strcmp(filename, "..") != 0) filename = &(filename[pathlength]); if(filename[0] == '/') filename = &(filename[1]); if(frame == state_get_focused_frame() && i == frame->workdir->idx){ wattron(frame->p_win, A_STANDOUT); wattron(frame->p_win, A_BOLD); } + if(dir) wattron(frame->p_win, COLOR_PAIR(DIRECTORY)); mvwaddnstr(frame->p_win, FrameTopBuffer+i-frame->workdir->top_index, 1, filename, cols-2); if(frame == state_get_focused_frame() && i == frame->workdir->idx){ wattroff(frame->p_win, A_STANDOUT); wattroff(frame->p_win, A_BOLD); } + if(dir) wattroff(frame->p_win, COLOR_PAIR(DIRECTORY)); i++; if((FrameTopBuffer+i-frame->workdir->top_index+FrameBotBuffer) > rows) break; } diff --git a/source/screen.h b/source/screen.h index 3a48292..546cc24 100644 --- a/source/screen.h +++ b/source/screen.h @@ -25,4 +25,8 @@ typedef struct { WorkDir_T* workdir; } frame_t; +enum ColorPairs { + DIRECTORY = 1 +}; + #endif /* SCREEN_H */ diff --git a/source/workdir.c b/source/workdir.c index eed6bb4..09b8a8b 100644 --- a/source/workdir.c +++ b/source/workdir.c @@ -17,7 +17,7 @@ static void get_files(int windex); -static bool is_dir(char* path) { +bool is_dir(char* path) { struct stat s; return ((stat(path, &s) == 0) && (s.st_mode & S_IFDIR)); } diff --git a/source/workdir.h b/source/workdir.h index a325287..b123910 100644 --- a/source/workdir.h +++ b/source/workdir.h @@ -10,8 +10,6 @@ #include #include "vec.h" -static bool is_dir(char* path); - void workdir_deinit(void); typedef struct { @@ -31,4 +29,6 @@ void workdir_cd(WorkDir_T*); void workdir_ls(WorkDir_T*); +bool is_dir(char* path); + #endif /* WORKDIR_H */