Skip to content

Commit

Permalink
Move some user configurable options (keybinding, colors) to config.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Unglaub committed Mar 21, 2012
1 parent 0f43c49 commit fade145
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
63 changes: 63 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
@@ -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
87 changes: 37 additions & 50 deletions gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -555,80 +542,80 @@ 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)
pos_y = pos_top + LINES - 2;
}
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;
Expand All @@ -654,7 +641,7 @@ void gui_run(struct proc **procs)
break;


case CTRL_AND('l'):
case REDRAW_CHAR:
/* redraw */
clear();
break;
Expand All @@ -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 == '?';
Expand Down

0 comments on commit fade145

Please sign in to comment.