From 05f1685b4ce49e79cbe632a6779556a42263be2f Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 11 Apr 2006 02:29:14 +0200 Subject: [PATCH] Half working prototype --- Makefile | 7 ++ cgit | Bin 10702 -> 16787 bytes cgit.c | 271 ++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 223 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index ca09fb2..eec1e03 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ LDFLAGS = -lcurses +CFLAGS = -g all: cgit +install: all + install cgit $(HOME)/bin + +clean: + rm -f cgit + cgit: cgit.c diff --git a/cgit b/cgit index 5913b2d4009fd7c5436db14fea49d621f45dca25..8397f2759ebefd958cd202866e23cc47d8f02d97 100755 GIT binary patch literal 16787 zcmc&*3wV^(nLhtq;MW8QB!MV`BNq*tOu|hOX$?ZSSZ)Oby#7pPCYcG7nQ<); zvnM%o&ikG3eCM3++|T*X&CN>|Se7M>@d&RVTHoWdXTXg#sE`>VAcl%sF%j+%kQg>& zD|ld!z)$Ok^}%{!t01K67N1R92~5i{%BGbDaRqGS7$ImGUsR}YNqYccu-g&g5eQ|v z4EMm95B~WGqwNKzWjNEItwo$#q)i(DrZr(-{7o(b_%UPRHzeXM4T(s7BA(1|3T9Km zX(}#~mU&;e>?#?T`Jknl469WoE|L@>#=)HkdydBSaD%W@U`NBA3wtIkJY@U;?fwPQlVlLE(s( z>F^Nz#N#y1YRoz=-=Xp|3a#N99p0(K*8{)wkk6)mMncO!gGQDh<`-@a~Ul0T%8{EM7$H0#_%6jP}U*C@7I|9i}-sQFGeFF-V6Hv2UU40 zpx-VXZuEDZ#%!15zeA`0n#MPLpTx5Xv2`8S6=Y-P=M>tn* zbXG>&;@Mm@GcOU!f?GIFTSqGCWOJcR&T&LE8R?8Cg@WN!B9#&OY}AQFTSNIo&XJU? zpiCznif5!R8_tMiDwz=BmP|CX0sd$>mJ+d0*6?R@5y=$or0`HU>vV+DqB9hUgkz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}0UdCDWrNo^%0u!|ugi3rBta z%1yd}y!rNG-r!HVfV>s=VhkRS3y6pZG5v+*aYsQAcdAq8{@bMnPYlYrOg4^ql>y+y z1#+w@8SIB8IYf_kl+zBI{_tTWe+$s`hYz#l`@p6@e7L235m;VIfcx;va|)an7GS{h z1no_;C%<#RSr49`|3%1yx<8pe@8IS62RQTRov|4|K8zpUNqfsv2mCyKkDxB=_ks3+ z+&I}D)9{yodH=wX!}d7<{4c=Y(D>`XYjEeIHYL^K2_1hBa*obtHD0OlcYw{A5#KQU zK+DY=h8Kx3A2@SsFh5?_^36K_NsWJ_@$1C8eR#({q2=a{!=He6>h`bkW4yy;@V;uD zj9)Fn+IYoudW$s9YrGWL`v#&-%lB$|m&VU(+^zAG8t>A$PUDAxxsCut`&0{C%kRP`o#Gd;9BQfgtc`&B`ufS%0vwdCy<{jMtOeN(nQy=P8Zf zKp6Y)9I+?;|JCvxTK+Duu_qCX?@FXA^Fuh_NX!B@_HQ=q-&|#)%Wo`h*Z4l2ULE7( zMo0Dk&Ejq?H*YNNp$3)!>jgv?HU68#PGIkwi-#EBQ~oTl_YKA)z^43Rl>h70 z*DeBnRO24_*&aXBxI^Pp)AU8GH`ypRMq9--Hss~wBEA13<3w1Q0Vu*O3{x{%CBU+?_I3EtmW)2zl4#`O4{4aTaaedlih@kV=lH| zJ`<4{$pBZ)N0z z8~sj2zrm63VJ71=n}<01)y^y bn*PkkQ;KW9eDb^$n#_IKv`0wO9!UK^`nOUi diff --git a/cgit.c b/cgit.c index 5bb8832..a22dfbe 100644 --- a/cgit.c +++ b/cgit.c @@ -10,11 +10,39 @@ #include +#define CGIT_HELP "(q)uit, (s)hell, (j) down, (k) up" +#define KEY_ESC 27 +#define KEY_TAB 9 + +/* +------------------------------------+ + * |titlewin | + * +------------------------------------+ + * |mainwin | + * | | + * | | + * | | + * | | + * +------------------------------------+ + * |statuswin | + * +------------------------------------+ + */ + +WINDOW *titlewin; +WINDOW *mainwin; +WINDOW *statuswin; + +typedef void (*pipe_filter_T)(char *, int); + +FILE *pipe; +long pipe_lineno; +pipe_filter_T pipe_filter; + /* * Init and quit */ -static void quit(int sig) +static void +quit(int sig) { endwin(); @@ -26,31 +54,153 @@ static void quit(int sig) static void init_colors(void) { + int bg = COLOR_BLACK; + start_color(); - init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); - init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); - init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); - init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); - init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); - init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); - init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); - init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); + if (use_default_colors()) + bg = -1; + + init_pair(COLOR_BLACK, COLOR_BLACK, bg); + init_pair(COLOR_GREEN, COLOR_GREEN, bg); + init_pair(COLOR_RED, COLOR_RED, bg); + init_pair(COLOR_CYAN, COLOR_CYAN, bg); + init_pair(COLOR_WHITE, COLOR_WHITE, bg); + init_pair(COLOR_MAGENTA, COLOR_MAGENTA, bg); + init_pair(COLOR_BLUE, COLOR_BLUE, bg); + init_pair(COLOR_YELLOW, COLOR_YELLOW, bg); } static void init(void) { - (void) signal(SIGINT, quit); /* arrange interrupts to terminate */ + int x, y; - (void) initscr(); /* initialize the curses library */ - keypad(stdscr, TRUE); /* enable keyboard mapping */ - (void) nonl(); /* tell curses not to do NL->CR/NL on output */ - (void) cbreak(); /* take input chars one at a time, no wait for \n */ - (void) noecho(); /* don't echo input */ + signal(SIGINT, quit); + + initscr(); /* initialize the curses library */ + nonl(); /* tell curses not to do NL->CR/NL on output */ + cbreak(); /* take input chars one at a time, no wait for \n */ + noecho(); /* don't echo input */ if (has_colors()) init_colors(); + + getmaxyx(stdscr, y, x); + + titlewin = newwin(1, 0, 0, 0); + + wattrset(titlewin, COLOR_PAIR(COLOR_GREEN)); + waddch(titlewin, ACS_VLINE); + wprintw(titlewin, "%s", "cg-view"); + waddch(titlewin, ACS_LTEE); + whline(titlewin, ACS_HLINE, x); + wrefresh(titlewin); + + statuswin = newwin(1, 0, y - 1, 0); + + wattrset(statuswin, COLOR_PAIR(COLOR_GREEN)); + wprintw(statuswin, "%s", CGIT_HELP); + wrefresh(statuswin); + + mainwin = newwin(y - 2, 0, 1, 0); + scrollok(mainwin, TRUE); + keypad(mainwin, TRUE); /* enable keyboard mapping */ +} + +/* + * Pipe filters + */ + +#define DIFF_CMD \ + "git-rev-list $(git-rev-parse --since=1.month) HEAD^..HEAD | " \ + "git-diff-tree --stdin --pretty -r --cc --always" + + +#define LOG_CMD \ + "git-rev-list $(git-rev-parse --since=1.month) HEAD | " \ + "git-diff-tree --stdin --pretty -r" + +static void +log_filter(char *line, int lineno) +{ + static int log_filter_skip; + + if (!line) { + wattrset(mainwin, A_NORMAL); + log_filter_skip = 0; + return; + } + + if (!strncmp("commit ", line, 7)) { + attrset(COLOR_PAIR(COLOR_GREEN)); + + } else if (!strncmp("Author: ", line, 8)) { + wattrset(mainwin, COLOR_PAIR(COLOR_CYAN)); + + } else if (!strncmp("Date: ", line, 6)) { + wattrset(mainwin, COLOR_PAIR(COLOR_YELLOW)); + + } else if (!strncmp("diff --git ", line, 11)) { + wattrset(mainwin, COLOR_PAIR(COLOR_YELLOW)); + + } else if (!strncmp("diff-tree ", line, 10)) { + wattrset(mainwin, COLOR_PAIR(COLOR_BLUE)); + + } else if (!strncmp("index ", line, 6)) { + wattrset(mainwin, COLOR_PAIR(COLOR_BLUE)); + + } else if (line[0] == '-') { + wattrset(mainwin, COLOR_PAIR(COLOR_RED)); + + } else if (line[0] == '+') { + wattrset(mainwin, COLOR_PAIR(COLOR_GREEN)); + + } else if (line[0] == '@') { + wattrset(mainwin, COLOR_PAIR(COLOR_MAGENTA)); + + } else if (line[0] == ':') { + log_filter_skip = 1; + return; + + } else if (log_filter_skip) { + log_filter_skip = 0; + return; + + } else { + wattrset(mainwin, A_NORMAL); + } + + mvwaddstr(mainwin, lineno, 0, line); +} + +static FILE * +open_pipe(char *cmd, pipe_filter_T filter) +{ + pipe = popen(cmd, "r"); + pipe_lineno = 1; + pipe_filter = filter; + return pipe; +} + +static void +read_pipe(int lines) +{ + char buffer[BUFSIZ]; + char *line; + + while ((line = fgets(buffer, sizeof(buffer), pipe))) { + pipe_filter(line, pipe_lineno++); + if (!--lines) + break; + } + + if (feof(pipe) || ferror(pipe)) { + pipe_filter(NULL, pipe_lineno - 1); + pclose(pipe); + pipe = NULL; + pipe_filter = NULL; + } } /* @@ -60,68 +210,79 @@ init(void) int main(int argc, char *argv[]) { - int x, y; - init(); - getmaxyx(stdscr, y, x); - - attrset(COLOR_PAIR(COLOR_GREEN)); - - addch(ACS_VLINE); - printw("%s", "cg-view"); - addch(ACS_LTEE); - addch(ACS_HLINE); - addch(ACS_HLINE); - addch(ACS_HLINE); - addch(ACS_HLINE); - addch(ACS_HLINE); - addch(ACS_HLINE); - addch(ACS_HLINE); - mvprintw(y - 1, 0, "%s", "press 'q' to quit"); - - { - FILE *rev_list = popen("git-rev-list $(git-rev-parse --since=1.month) HEAD", "r"); - char buffer[BUFSIZ]; - char *line; - int lineno = 1; - - while ((line = fgets(buffer, sizeof(buffer), rev_list))) { - move(lineno, 0); - printw("%2d: ", lineno++); - addch(ACS_LTEE); - addch(ACS_HLINE); - addstr(line); - } - } - attrset(A_NORMAL); -/* scrollok();*/ + pipe = open_pipe(LOG_CMD, log_filter); for (;;) { - int c = getch(); /* refresh, accept single keystroke of input */ + int c; + + if (pipe) read_pipe(20); + if (pipe) nodelay(mainwin, TRUE); + + c = wgetch(mainwin); /* refresh, accept single keystroke of input */ + + if (pipe) nodelay(mainwin, FALSE); + + if (c == ERR) + continue; /* Process the command keystroke */ switch (c) { + case KEY_ESC: case 'q': quit(0); return 0; + case KEY_DOWN: + case 'j': + wscrl(mainwin, 1); + break; + + case KEY_UP: + case 'k': + wscrl(mainwin, -1); + break; + + case 'd': + pipe = open_pipe(DIFF_CMD, log_filter); + wclear(mainwin); + wmove(mainwin, 0, 0); + break; + + case 'l': + pipe = open_pipe(LOG_CMD, log_filter); + wclear(mainwin); + wmove(mainwin, 0, 0); + break; + case 's': - addstr("Shelling out..."); + mvwaddstr(statuswin, 0, 0, "Shelling out......................"); def_prog_mode(); /* save current tty modes */ endwin(); /* restore original tty modes */ system("sh"); /* run shell */ - addstr("returned.\n"); /* prepare return message */ + + wclear(statuswin); + mvwaddstr(statuswin, 0, 0, CGIT_HELP); reset_prog_mode(); //refresh(); /* restore save modes, repaint screen */ break; - default: - if (isprint(c) || isspace(c)) - addch(c); +/* default:*/ +/* if (isprint(c) || isspace(c))*/ +/* addch(c);*/ } + redrawwin(mainwin); + wrefresh(mainwin); +/* redrawwin(titlewin);*/ +/* wrefresh(titlewin);*/ +/* redrawwin(statuswin);*/ +/* wrefresh(statuswin);*/ } quit(0); } + +/* addch(ACS_LTEE);*/ +/* addch(ACS_HLINE);*/ -- 2.30.2