From fade145d38230a815600a3deca800acb309597e8 Mon Sep 17 00:00:00 2001 From: Florian Unglaub Date: Wed, 21 Mar 2012 17:38:00 +0100 Subject: [PATCH] Move some user configurable options (keybinding, colors) to config.h --- Makefile | 2 +- config.h | 63 ++++++++++++++++++++++++++++++++++++++++ gui.c | 87 ++++++++++++++++++++++++-------------------------------- 3 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 config.h diff --git a/Makefile b/Makefile index e231e92..31dd1ad 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ install: utop uninstall: rm -f ${PREFIX}/bin/utop ${PREFIX}/share/man/man1/ -gui.o: gui.c proc.h gui.h util.h +gui.o: gui.c proc.h gui.h util.h config.h main.o: main.c proc.h gui.h proc.o: proc.c proc.h util.h util.o: util.c util.h diff --git a/config.h b/config.h new file mode 100644 index 0000000..d056909 --- /dev/null +++ b/config.h @@ -0,0 +1,63 @@ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + + +#define HALF_DELAY_TIME 10 + +/* 1000ms */ +#define WAIT_TIME (HALF_DELAY_TIME * 100) +/* 60s */ +#define FULL_WAIT_TIME (WAIT_TIME * 60) + +#define INDENT " " + +// Key bindings +#define CTRL_AND(c) ((c) & 037) + +#define QUIT_CHAR 'q' +#define UP_CHAR 'k' +#define DOWN_CHAR 'j' +#define INFO_CHAR 'i' +#define KILL_CHAR 'd' +#define LSOF_CHAR 'l' +#define STRACE_CHAR 's' +#define GOTO_LOCKED_CHAR 'o' +#define GOTO_$$_CHAR 'O' +#define SCROLL_TO_TOP_CHAR 'g' +#define SCROLL_TO_BOTTOM_CHAR 'G' +#define SCROLL_TO_FIRST_CHAR 'H' +#define SCROLL_TO_LAST_CHAR 'L' +#define SCROLL_TO_MIDDLE_CHAR 'M' +#define LOCK_CHAR CTRL_AND('k') +#define REDRAW_CHAR CTRL_AND('l') +#define SEARCH_FORWARD '/' +#define SEARCH_BACKWARD '?' +#define SEARCH_NEXT_CHAR CTRL_AND('n') +#define SEARCH_PREVIOUS_CHAR CTRL_AND('p') +#define RESET_SEARCH_CHAR CTRL_AND('u') +// #define KILL_CHAR CTRL_AND('d') +#define EXPOSE_ONE_MORE_LINE_BOTTOM_CHAR CTRL_AND('e') +#define EXPOSE_ONE_MORE_LINE_TOP_CHAR CTRL_AND('y') +#define BACKWARD_WINDOW_CHAR CTRL_AND('b') +#define FORWARD_WINDOW_CHAR CTRL_AND('f') +#define BACKWARD_HALF_WINDOW_CHAR CTRL_AND('u') +#define FORWARD_HALF_WINDOW_CHAR CTRL_AND('d') + +// Colors + +// Default ncurses colors +// COLOR_BLACK 0 +// COLOR_RED 1 +// COLOR_GREEN 2 +// COLOR_YELLOW 3 +// COLOR_BLUE 4 +// COLOR_MAGENTA 5 +// COLOR_CYAN 6 +// COLOR_WHITE 7 + +#define ATTR_NOT_OWNED A_BOLD | COLOR_PAIR(1 + COLOR_BLACK) +#define ATTR_SEARCH A_BOLD | COLOR_PAIR(1 + COLOR_RED) +#define ATTR_BASENAME A_BOLD | COLOR_PAIR(1 + COLOR_CYAN) +#define ATTR_LOCK A_BOLD | COLOR_PAIR(1 + COLOR_YELLOW) + +#endif diff --git a/gui.c b/gui.c index 8e545fa..7b95ae6 100644 --- a/gui.c +++ b/gui.c @@ -11,18 +11,8 @@ #include "proc.h" #include "gui.h" #include "util.h" +#include "config.h" -#define HALF_DELAY_TIME 10 - -/* 1000ms */ -#define WAIT_TIME (HALF_DELAY_TIME * 100) -/* 60s */ -#define FULL_WAIT_TIME (WAIT_TIME * 60) - -#define LOCK_CHAR CTRL_AND('k') - -#define CTRL_AND(c) ((c) & 037) -#define INDENT " " #define STATUS(y, x, ...) do{ mvprintw(y, x, __VA_ARGS__); clrtoeol(); }while(0) #define WAIT_STATUS(...) do{ STATUS(0, 0, __VA_ARGS__); ungetch(getch()); }while(0) @@ -67,14 +57,14 @@ void gui_init() start_color(); use_default_colors(); - init_pair(1 + COLOR_BLACK , COLOR_BLACK , -1); - init_pair(1 + COLOR_GREEN , COLOR_GREEN , -1); - init_pair(1 + COLOR_WHITE , COLOR_WHITE , -1); - init_pair(1 + COLOR_RED , COLOR_RED , -1); - init_pair(1 + COLOR_CYAN , COLOR_CYAN , -1); - init_pair(1 + COLOR_MAGENTA, COLOR_MAGENTA, -1); - init_pair(1 + COLOR_BLUE , COLOR_BLUE , -1); - init_pair(1 + COLOR_YELLOW , COLOR_YELLOW , -1); + init_pair(1 + COLOR_BLACK , COLOR_BLACK , -1); + init_pair(1 + COLOR_GREEN , COLOR_GREEN , -1); + init_pair(1 + COLOR_WHITE , COLOR_WHITE , -1); + init_pair(1 + COLOR_RED , COLOR_RED , -1); + init_pair(1 + COLOR_CYAN , COLOR_CYAN , -1); + init_pair(1 + COLOR_MAGENTA , COLOR_MAGENTA, -1); + init_pair(1 + COLOR_BLUE , COLOR_BLUE , -1); + init_pair(1 + COLOR_YELLOW , COLOR_YELLOW , -1); } } } @@ -153,11 +143,6 @@ void showproc(struct proc *proc, int *py, int indent) int len = LINES; int lock = proc->pid == lock_proc_pid; -#define ATTR_NOT_OWNED A_BOLD | COLOR_PAIR(1 + COLOR_BLACK) -#define ATTR_SEARCH A_BOLD | COLOR_PAIR(1 + COLOR_RED) -#define ATTR_BASENAME A_BOLD | COLOR_PAIR(1 + COLOR_CYAN) -#define ATTR_LOCK A_BOLD | COLOR_PAIR(1 + COLOR_YELLOW) - move(y, 0); if(lock) @@ -483,8 +468,10 @@ void gui_search(int ch, struct proc **procs) do_lock = 1; break; - case CTRL_AND('n'): search_offset++; break; - case CTRL_AND('p'): + case SEARCH_NEXT_CHAR: + search_offset++; + break; + case SEARCH_PREVIOUS_CHAR: if(search_offset > 0) search_offset--; break; @@ -496,7 +483,7 @@ void gui_search(int ch, struct proc **procs) search = 0; break; - case CTRL_AND('u'): + case RESET_SEARCH_CHAR: search_idx = 0; *search_str = '\0'; break; @@ -555,46 +542,46 @@ void gui_run(struct proc **procs) gui_search(ch, procs); }else{ switch(ch){ - case 'q': + case QUIT_CHAR: fin = 1; break; - case 'k': + case UP_CHAR: if(pos_y > 0) position(pos_y - 1); break; - case 'j': + case DOWN_CHAR: position(pos_y + 1); break; - case 'g': + case SCROLL_TO_TOP_CHAR: position(0); break; - case 'G': + case SCROLL_TO_BOTTOM_CHAR: position(pst.count); break; - case CTRL_AND('u'): + case BACKWARD_HALF_WINDOW_CHAR: position(pos_y - LINES / 2); break; - case CTRL_AND('d'): + case FORWARD_HALF_WINDOW_CHAR: position(pos_y + LINES / 2); break; - case CTRL_AND('b'): + case BACKWARD_WINDOW_CHAR: position(pos_y - LINES); break; - case CTRL_AND('f'): + case FORWARD_WINDOW_CHAR: position(pos_y + LINES); break; - case CTRL_AND('e'): + case EXPOSE_ONE_MORE_LINE_BOTTOM_CHAR: if(pos_top < pst.count - 1){ pos_top++; if(pos_y < pos_top) pos_y = pos_top; } break; - case CTRL_AND('y'): + case EXPOSE_ONE_MORE_LINE_TOP_CHAR: if(pos_top > 0){ pos_top--; if(pos_y > pos_top + LINES - 2) @@ -602,33 +589,33 @@ void gui_run(struct proc **procs) } break; - case 'L': + case SCROLL_TO_LAST_CHAR: position(pos_top + LINES - 2); break; - case 'H': + case SCROLL_TO_FIRST_CHAR: position(pos_top); break; - case 'M': + case SCROLL_TO_MIDDLE_CHAR: position(pos_top + (pst.count > LINES ? LINES : pst.count) / 2); break; - case 'i': + case INFO_CHAR: on_curproc("info", info, 0, procs); break; - case 'd': + case KILL_CHAR: on_curproc("delete", delete, 0, procs); break; - case 'l': + case LSOF_CHAR: on_curproc("lsof", lsof, 1, procs); break; - case 's': + case STRACE_CHAR: on_curproc("strace", strace, 1, procs); break; - case 'o': + case GOTO_LOCKED_CHAR: goto_lock(procs); break; - case 'O': + case GOTO_$$_CHAR: /* goto $$ */ goto_me(procs); break; @@ -654,7 +641,7 @@ void gui_run(struct proc **procs) break; - case CTRL_AND('l'): + case REDRAW_CHAR: /* redraw */ clear(); break; @@ -664,8 +651,8 @@ void gui_run(struct proc **procs) break; - case '?': - case '/': + case SEARCH_BACKWARD: + case SEARCH_FORWARD: *search_str = '\0'; search_idx = 0; search_pid = ch == '?';