13 #define CGIT_HELP "(q)uit, (s)hell, (j) down, (k) up"
17 /* +------------------------------------+
19 * +------------------------------------+
25 * +------------------------------------+
27 * +------------------------------------+
34 typedef void (*pipe_filter_T
)(char *, int);
38 pipe_filter_T pipe_filter
;
49 /* do your non-curses wrapup here */
61 if (use_default_colors())
64 init_pair(COLOR_BLACK
, COLOR_BLACK
, bg
);
65 init_pair(COLOR_GREEN
, COLOR_GREEN
, bg
);
66 init_pair(COLOR_RED
, COLOR_RED
, bg
);
67 init_pair(COLOR_CYAN
, COLOR_CYAN
, bg
);
68 init_pair(COLOR_WHITE
, COLOR_WHITE
, bg
);
69 init_pair(COLOR_MAGENTA
, COLOR_MAGENTA
, bg
);
70 init_pair(COLOR_BLUE
, COLOR_BLUE
, bg
);
71 init_pair(COLOR_YELLOW
, COLOR_YELLOW
, bg
);
81 initscr(); /* initialize the curses library */
82 nonl(); /* tell curses not to do NL->CR/NL on output */
83 cbreak(); /* take input chars one at a time, no wait for \n */
84 noecho(); /* don't echo input */
89 getmaxyx(stdscr
, y
, x
);
91 titlewin
= newwin(1, 0, 0, 0);
93 wattrset(titlewin
, COLOR_PAIR(COLOR_GREEN
));
94 waddch(titlewin
, ACS_VLINE
);
95 wprintw(titlewin
, "%s", "cg-view");
96 waddch(titlewin
, ACS_LTEE
);
97 whline(titlewin
, ACS_HLINE
, x
);
100 statuswin
= newwin(1, 0, y
- 1, 0);
102 wattrset(statuswin
, COLOR_PAIR(COLOR_GREEN
));
103 wprintw(statuswin
, "%s", CGIT_HELP
);
106 mainwin
= newwin(y
- 2, 0, 1, 0);
107 scrollok(mainwin
, TRUE
);
108 keypad(mainwin
, TRUE
); /* enable keyboard mapping */
116 "git-rev-list $(git-rev-parse --since=1.month) HEAD^..HEAD | " \
117 "git-diff-tree --stdin --pretty -r --cc --always"
121 "git-rev-list $(git-rev-parse --since=1.month) HEAD | " \
122 "git-diff-tree --stdin --pretty -r"
125 log_filter(char *line
, int lineno
)
127 static int log_filter_skip
;
130 wattrset(mainwin
, A_NORMAL
);
135 if (!strncmp("commit ", line
, 7)) {
136 attrset(COLOR_PAIR(COLOR_GREEN
));
138 } else if (!strncmp("Author: ", line
, 8)) {
139 wattrset(mainwin
, COLOR_PAIR(COLOR_CYAN
));
141 } else if (!strncmp("Date: ", line
, 6)) {
142 wattrset(mainwin
, COLOR_PAIR(COLOR_YELLOW
));
144 } else if (!strncmp("diff --git ", line
, 11)) {
145 wattrset(mainwin
, COLOR_PAIR(COLOR_YELLOW
));
147 } else if (!strncmp("diff-tree ", line
, 10)) {
148 wattrset(mainwin
, COLOR_PAIR(COLOR_BLUE
));
150 } else if (!strncmp("index ", line
, 6)) {
151 wattrset(mainwin
, COLOR_PAIR(COLOR_BLUE
));
153 } else if (line
[0] == '-') {
154 wattrset(mainwin
, COLOR_PAIR(COLOR_RED
));
156 } else if (line
[0] == '+') {
157 wattrset(mainwin
, COLOR_PAIR(COLOR_GREEN
));
159 } else if (line
[0] == '@') {
160 wattrset(mainwin
, COLOR_PAIR(COLOR_MAGENTA
));
162 } else if (line
[0] == ':') {
166 } else if (log_filter_skip
) {
171 wattrset(mainwin
, A_NORMAL
);
174 mvwaddstr(mainwin
, lineno
, 0, line
);
178 open_pipe(char *cmd
, pipe_filter_T filter
)
180 pipe
= popen(cmd
, "r");
182 pipe_filter
= filter
;
192 while ((line
= fgets(buffer
, sizeof(buffer
), pipe
))) {
193 pipe_filter(line
, pipe_lineno
++);
198 if (feof(pipe
) || ferror(pipe
)) {
199 pipe_filter(NULL
, pipe_lineno
- 1);
211 main(int argc
, char *argv
[])
215 pipe
= open_pipe(LOG_CMD
, log_filter
);
220 if (pipe
) read_pipe(20);
221 if (pipe
) nodelay(mainwin
, TRUE
);
223 c
= wgetch(mainwin
); /* refresh, accept single keystroke of input */
225 if (pipe
) nodelay(mainwin
, FALSE
);
230 /* Process the command keystroke */
248 pipe
= open_pipe(DIFF_CMD
, log_filter
);
250 wmove(mainwin
, 0, 0);
254 pipe
= open_pipe(LOG_CMD
, log_filter
);
256 wmove(mainwin
, 0, 0);
260 mvwaddstr(statuswin
, 0, 0, "Shelling out......................");
261 def_prog_mode(); /* save current tty modes */
262 endwin(); /* restore original tty modes */
263 system("sh"); /* run shell */
266 mvwaddstr(statuswin
, 0, 0, CGIT_HELP
);
268 //refresh(); /* restore save modes, repaint screen */
272 /* if (isprint(c) || isspace(c))*/
278 /* redrawwin(titlewin);*/
279 /* wrefresh(titlewin);*/
280 /* redrawwin(statuswin);*/
281 /* wrefresh(statuswin);*/
287 /* addch(ACS_LTEE);*/
288 /* addch(ACS_HLINE);*/