summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 67392cc)
raw | patch | inline | side by side (parent: 67392cc)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 15 Apr 2006 00:55:07 +0000 (02:55 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Sat, 15 Apr 2006 00:55:07 +0000 (02:55 +0200) |
cgit.c | patch | blob | history |
index 6461e547efd7c93228506fa208f1b901388c6a5d..aa42f6f3ca86991ffd200fda401f804336b8080e 100644 (file)
--- a/cgit.c
+++ b/cgit.c
*
*/
+#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include <ctype.h>
#include <signal.h>
#include <curses.h>
+
#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 *titlewin;
WINDOW *mainwin;
WINDOW *statuswin;
long pipe_lineno;
pipe_filter_T pipe_filter;
+
+static void
+put_status(char *msg, ...)
+{
+ va_list args;
+
+ va_start(args, msg);
+ werase(statuswin);
+ wmove(statuswin, 0, 0);
+ vwprintw(statuswin, msg, args);
+ wrefresh(statuswin);
+ va_end(args);
+}
+
/*
* Init and quit
*/
start_color();
- if (use_default_colors())
+ if (use_default_colors() != ERR)
bg = -1;
init_pair(COLOR_BLACK, COLOR_BLACK, bg);
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 */
+ leaveok(stdscr, TRUE);
if (has_colors())
init_colors();
getmaxyx(stdscr, y, x);
- titlewin = newwin(1, 0, 0, 0);
+#if 0
+ titlewin = newwin(1, 0, y - 2, 0);
wattrset(titlewin, COLOR_PAIR(COLOR_GREEN));
waddch(titlewin, ACS_VLINE);
waddch(titlewin, ACS_LTEE);
whline(titlewin, ACS_HLINE, x);
wrefresh(titlewin);
-
+#endif
statuswin = newwin(1, 0, y - 1, 0);
wattrset(statuswin, COLOR_PAIR(COLOR_GREEN));
- wprintw(statuswin, "%s", CGIT_HELP);
- wrefresh(statuswin);
+ put_status(CGIT_HELP);
- mainwin = newwin(y - 2, 0, 1, 0);
+ mainwin = newwin(y - 1, 0, 0, 0);
scrollok(mainwin, TRUE);
keypad(mainwin, TRUE); /* enable keyboard mapping */
}
*/
#define DIFF_CMD \
- "git-rev-list $(git-rev-parse --since=1.month) HEAD^..HEAD | " \
+ "git-rev-list HEAD^..HEAD | " \
"git-diff-tree --stdin --pretty -r --cc --always"
open_pipe(char *cmd, pipe_filter_T filter)
{
pipe = popen(cmd, "r");
- pipe_lineno = 1;
+ pipe_lineno = 0;
pipe_filter = filter;
+ wclear(mainwin);
+ wmove(mainwin, 0, 0);
+ put_status("Loading...");
return pipe;
}
{
char buffer[BUFSIZ];
char *line;
+ int x, y;
while ((line = fgets(buffer, sizeof(buffer), pipe))) {
- pipe_filter(line, pipe_lineno++);
+ int linelen;
+
if (!--lines)
break;
+
+ linelen = strlen(line);
+ if (linelen)
+ line[linelen - 1] = 0;
+
+ pipe_filter(line, pipe_lineno++);
}
if (feof(pipe) || ferror(pipe)) {
pclose(pipe);
pipe = NULL;
pipe_filter = NULL;
+ put_status("%s (lines %d)", CGIT_HELP, pipe_lineno - 1);
}
}
{
init();
- pipe = open_pipe(LOG_CMD, log_filter);
+ //pipe = open_pipe(LOG_CMD, log_filter);
for (;;) {
int c;
if (pipe) nodelay(mainwin, FALSE);
+ /* No input from wgetch() with nodelay() enabled. */
if (c == ERR)
continue;
wscrl(mainwin, -1);
break;
+ case 'c':
+ wclear(mainwin);
+ 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':
- mvwaddstr(statuswin, 0, 0, "Shelling out......................");
+ mvwaddstr(statuswin, 0, 0, "Shelling out...");
def_prog_mode(); /* save current tty modes */
endwin(); /* restore original tty modes */
system("sh"); /* run shell */
- wclear(statuswin);
+ werase(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);*/
}
redrawwin(mainwin);
wrefresh(mainwin);
-/* redrawwin(titlewin);*/
-/* wrefresh(titlewin);*/
-/* redrawwin(statuswin);*/
-/* wrefresh(statuswin);*/
}
quit(0);
}
-
-/* addch(ACS_LTEE);*/
-/* addch(ACS_HLINE);*/