16 #define CGIT_HELP "(q)uit, (s)hell, (j) down, (k) up"
24 typedef void (*pipe_filter_T
)(char *, int);
28 pipe_filter_T pipe_filter
;
32 put_status(char *msg
, ...)
38 wmove(statuswin
, 0, 0);
39 vwprintw(statuswin
, msg
, args
);
53 /* do your non-curses wrapup here */
65 if (use_default_colors() != ERR
)
68 init_pair(COLOR_BLACK
, COLOR_BLACK
, bg
);
69 init_pair(COLOR_GREEN
, COLOR_GREEN
, bg
);
70 init_pair(COLOR_RED
, COLOR_RED
, bg
);
71 init_pair(COLOR_CYAN
, COLOR_CYAN
, bg
);
72 init_pair(COLOR_WHITE
, COLOR_WHITE
, bg
);
73 init_pair(COLOR_MAGENTA
, COLOR_MAGENTA
, bg
);
74 init_pair(COLOR_BLUE
, COLOR_BLUE
, bg
);
75 init_pair(COLOR_YELLOW
, COLOR_YELLOW
, bg
);
85 initscr(); /* initialize the curses library */
86 nonl(); /* tell curses not to do NL->CR/NL on output */
87 cbreak(); /* take input chars one at a time, no wait for \n */
88 noecho(); /* don't echo input */
89 leaveok(stdscr
, TRUE
);
94 getmaxyx(stdscr
, y
, x
);
97 titlewin
= newwin(1, 0, y
- 2, 0);
99 wattrset(titlewin
, COLOR_PAIR(COLOR_GREEN
));
100 waddch(titlewin
, ACS_VLINE
);
101 wprintw(titlewin
, "%s", "cg-view");
102 waddch(titlewin
, ACS_LTEE
);
103 whline(titlewin
, ACS_HLINE
, x
);
106 statuswin
= newwin(1, 0, y
- 1, 0);
108 wattrset(statuswin
, COLOR_PAIR(COLOR_GREEN
));
109 put_status(CGIT_HELP
);
111 mainwin
= newwin(y
- 1, 0, 0, 0);
112 scrollok(mainwin
, TRUE
);
113 keypad(mainwin
, TRUE
); /* enable keyboard mapping */
121 "git-rev-list HEAD^..HEAD | " \
122 "git-diff-tree --stdin --pretty -r --cc --always"
126 "git-rev-list $(git-rev-parse --since=1.month) HEAD | " \
127 "git-diff-tree --stdin --pretty -r --root"
130 log_filter(char *line
, int lineno
)
132 static int log_filter_skip
;
135 wattrset(mainwin
, A_NORMAL
);
140 if (!strncmp("commit ", line
, 7)) {
141 attrset(COLOR_PAIR(COLOR_GREEN
));
143 } else if (!strncmp("Author: ", line
, 8)) {
144 wattrset(mainwin
, COLOR_PAIR(COLOR_CYAN
));
146 } else if (!strncmp("Date: ", line
, 6)) {
147 wattrset(mainwin
, COLOR_PAIR(COLOR_YELLOW
));
149 } else if (!strncmp("diff --git ", line
, 11)) {
150 wattrset(mainwin
, COLOR_PAIR(COLOR_YELLOW
));
152 } else if (!strncmp("diff-tree ", line
, 10)) {
153 wattrset(mainwin
, COLOR_PAIR(COLOR_BLUE
));
155 } else if (!strncmp("index ", line
, 6)) {
156 wattrset(mainwin
, COLOR_PAIR(COLOR_BLUE
));
158 } else if (line
[0] == '-') {
159 wattrset(mainwin
, COLOR_PAIR(COLOR_RED
));
161 } else if (line
[0] == '+') {
162 wattrset(mainwin
, COLOR_PAIR(COLOR_GREEN
));
164 } else if (line
[0] == '@') {
165 wattrset(mainwin
, COLOR_PAIR(COLOR_MAGENTA
));
167 } else if (line
[0] == ':') {
172 } else if (log_filter_skip
) {
178 wattrset(mainwin
, A_NORMAL
);
181 mvwaddstr(mainwin
, lineno
, 0, line
);
185 open_pipe(char *cmd
, pipe_filter_T filter
)
187 pipe
= popen(cmd
, "r");
189 pipe_filter
= filter
;
191 wmove(mainwin
, 0, 0);
192 put_status("Loading...");
203 while ((line
= fgets(buffer
, sizeof(buffer
), pipe
))) {
209 linelen
= strlen(line
);
211 line
[linelen
- 1] = 0;
213 pipe_filter(line
, pipe_lineno
++);
216 if (feof(pipe
) || ferror(pipe
)) {
217 pipe_filter(NULL
, pipe_lineno
- 1);
221 put_status("%s (lines %d)", CGIT_HELP
, pipe_lineno
- 1);
230 main(int argc
, char *argv
[])
234 //pipe = open_pipe(LOG_CMD, log_filter);
239 if (pipe
) read_pipe(20);
240 if (pipe
) nodelay(mainwin
, TRUE
);
242 c
= wgetch(mainwin
); /* refresh, accept single keystroke of input */
244 if (pipe
) nodelay(mainwin
, FALSE
);
246 /* No input from wgetch() with nodelay() enabled. */
250 /* Process the command keystroke */
272 pipe
= open_pipe(DIFF_CMD
, log_filter
);
276 pipe
= open_pipe(LOG_CMD
, log_filter
);
280 mvwaddstr(statuswin
, 0, 0, "Shelling out...");
281 def_prog_mode(); /* save current tty modes */
282 endwin(); /* restore original tty modes */
283 system("sh"); /* run shell */
286 mvwaddstr(statuswin
, 0, 0, CGIT_HELP
);