summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e3e7b9f)
raw | patch | inline | side by side (parent: e3e7b9f)
author | Jonas Fonseca <fonseca@diku.dk> | |
Tue, 18 Apr 2006 21:12:21 +0000 (23:12 +0200) | ||
committer | Jonas Fonseca <fonseca@antimatter.localdomain> | |
Tue, 18 Apr 2006 21:12:21 +0000 (23:12 +0200) |
cgit.c | patch | blob | history |
index aa42f6f3ca86991ffd200fda401f804336b8080e..a05103ec8ed0dedd12fafec64063824c7c10db52 100644 (file)
--- a/cgit.c
+++ b/cgit.c
-/*
+/* Cursed git browser
*
+ * Copyright (c) Jonas Fonseca, 2006
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*/
#include <stdarg.h>
#include <curses.h>
-#define CGIT_HELP "(q)uit, (s)hell, (j) down, (k) up"
+#define MSG_HELP "(q)uit, (s)hell, (j) down, (k) up"
+
#define KEY_ESC 27
#define KEY_TAB 9
WINDOW *mainwin;
WINDOW *statuswin;
-typedef void (*pipe_filter_T)(char *, int);
+typedef void (*pipe_reader_T)(char *, int);
FILE *pipe;
long pipe_lineno;
-pipe_filter_T pipe_filter;
+pipe_reader_T pipe_reader;
static void
statuswin = newwin(1, 0, y - 1, 0);
wattrset(statuswin, COLOR_PAIR(COLOR_GREEN));
- put_status(CGIT_HELP);
+ put_status(MSG_HELP);
mainwin = newwin(y - 1, 0, 0, 0);
scrollok(mainwin, TRUE);
}
/*
- * Pipe filters
+ * Pipe readers
*/
#define DIFF_CMD \
"git-rev-list HEAD^..HEAD | " \
- "git-diff-tree --stdin --pretty -r --cc --always"
+ "git-diff-tree --stdin --pretty -r --cc --always --stat"
-#define LOG_CMD \
+#define LOG_CMD0 \
"git-rev-list $(git-rev-parse --since=1.month) HEAD | " \
"git-diff-tree --stdin --pretty -r --root"
+#define LOG_CMD \
+ "git-rev-list HEAD | git-diff-tree --stdin --pretty -r --root"
+
static void
-log_filter(char *line, int lineno)
+log_reader(char *line, int lineno)
{
- static int log_filter_skip;
+ static int log_reader_skip;
if (!line) {
wattrset(mainwin, A_NORMAL);
- log_filter_skip = 0;
+ log_reader_skip = 0;
return;
}
if (!strncmp("commit ", line, 7)) {
- attrset(COLOR_PAIR(COLOR_GREEN));
+ wattrset(mainwin, COLOR_PAIR(COLOR_GREEN));
} else if (!strncmp("Author: ", line, 8)) {
wattrset(mainwin, COLOR_PAIR(COLOR_CYAN));
} else if (line[0] == ':') {
pipe_lineno--;
- log_filter_skip = 1;
+ log_reader_skip = 1;
return;
- } else if (log_filter_skip) {
+ } else if (log_reader_skip) {
pipe_lineno--;
- log_filter_skip = 0;
+ log_reader_skip = 0;
return;
} else {
}
static FILE *
-open_pipe(char *cmd, pipe_filter_T filter)
+open_pipe(char *cmd, pipe_reader_T reader)
{
pipe = popen(cmd, "r");
pipe_lineno = 0;
- pipe_filter = filter;
+ pipe_reader = reader;
wclear(mainwin);
wmove(mainwin, 0, 0);
put_status("Loading...");
if (linelen)
line[linelen - 1] = 0;
- pipe_filter(line, pipe_lineno++);
+ pipe_reader(line, pipe_lineno++);
}
if (feof(pipe) || ferror(pipe)) {
- pipe_filter(NULL, pipe_lineno - 1);
+ pipe_reader(NULL, pipe_lineno - 1);
pclose(pipe);
pipe = NULL;
- pipe_filter = NULL;
- put_status("%s (lines %d)", CGIT_HELP, pipe_lineno - 1);
+ pipe_reader = NULL;
+ put_status("%s (lines %d)", MSG_HELP, pipe_lineno - 1);
}
}
{
init();
- //pipe = open_pipe(LOG_CMD, log_filter);
+ //pipe = open_pipe(LOG_CMD, log_reader);
for (;;) {
int c;
break;
case 'd':
- pipe = open_pipe(DIFF_CMD, log_filter);
+ pipe = open_pipe(DIFF_CMD, log_reader);
break;
case 'l':
- pipe = open_pipe(LOG_CMD, log_filter);
+ pipe = open_pipe(LOG_CMD, log_reader);
break;
case 's':
system("sh"); /* run shell */
werase(statuswin);
- mvwaddstr(statuswin, 0, 0, CGIT_HELP);
+ mvwaddstr(statuswin, 0, 0, MSG_HELP);
reset_prog_mode();
break;
}