1 /* Copyright (c) 2006 Jonas Fonseca <fonseca@diku.dk>
2 * See license info at the bottom. */
9 * tig - text-mode interface for git
15 * tig [options] log [git log options]
16 * tig [options] diff [git diff options]
17 * tig [options] < [git log or git diff output]
21 * Browse changes in a git repository.
29 #define VERSION "tig-0.1"
44 static void die(const char *err
, ...);
45 static void report(const char *msg
, ...);
46 static void update_title(void);
48 /* Size of symbolic or SHA1 ID. */
49 #define SIZEOF_REF 256
51 /* This color name can be used to refer to the default term colors. */
52 #define COLOR_DEFAULT (-1)
54 /* The format and size of the date column in the main view. */
55 #define DATE_FORMAT "%Y-%m-%d %H:%M"
56 #define DATE_COLS (STRING_SIZE("2006-04-29 14:21 "))
58 /* The interval between line numbers. */
59 #define NUMBER_INTERVAL 1
61 #define ABS(x) ((x) >= 0 ? (x) : -(x))
62 #define MIN(x, y) ((x) < (y) ? (x) : (y))
64 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
65 #define STRING_SIZE(x) (sizeof(x) - 1)
67 /* Some ascii-shorthands that fit into the ncurses namespace. */
73 /* XXX: Keep the view request first and in sync with views[]. */
83 REQ_TOGGLE_LINE_NUMBERS
,
107 string_ncopy(char *dst
, char *src
, int dstlen
)
109 strncpy(dst
, src
, dstlen
- 1);
113 /* Shorthand for safely copying into a fixed buffer. */
114 #define string_copy(dst, src) \
115 string_ncopy(dst, src, sizeof(dst))
123 static int opt_line_number
;
124 static int opt_request
= REQ_VIEW_MAIN
;
126 char head_id
[SIZEOF_REF
] = "HEAD";
127 char commit_id
[SIZEOF_REF
] = "HEAD";
129 /* Returns the index of log or diff command or -1 to exit. */
131 parse_options(int argc
, char *argv
[])
135 for (i
= 1; i
< argc
; i
++) {
142 if (!strcmp(opt
, "log")) {
143 opt_request
= REQ_VIEW_LOG
;
150 } else if (!strcmp(opt
, "diff")) {
151 opt_request
= REQ_VIEW_DIFF
;
156 * Start up in log view.
158 } else if (!strcmp(opt
, "-l")) {
159 opt_request
= REQ_VIEW_LOG
;
163 * Start up in diff view.
165 } else if (!strcmp(opt
, "-d")) {
166 opt_request
= REQ_VIEW_DIFF
;
169 * -n, --line-number::
170 * Prefix line numbers in log and diff view.
172 } else if (!strcmp(opt
, "-n") ||
173 !strcmp(opt
, "--line-number")) {
178 * Show version and exit.
180 } else if (!strcmp(opt
, "-v") ||
181 !strcmp(opt
, "--version")) {
182 printf("tig version %s\n", VERSION
);
187 * Commit reference, symbolic or raw SHA1 ID.
189 } else if (opt
[0] && opt
[0] != '-') {
190 string_copy(head_id
, opt
);
191 string_copy(commit_id
, opt
);
194 die("unknown command '%s'", opt
);
215 * stop all background loading
226 #define HELP "(d)iff, (l)og, (m)ain, (q)uit, (v)ersion, (h)elp"
233 struct keymap keymap
[] = {
234 /* Cursor navigation */
235 { KEY_UP
, REQ_MOVE_UP
},
236 { 'k', REQ_MOVE_UP
},
237 { KEY_DOWN
, REQ_MOVE_DOWN
},
238 { 'j', REQ_MOVE_DOWN
},
239 { KEY_HOME
, REQ_MOVE_FIRST_LINE
},
240 { KEY_END
, REQ_MOVE_LAST_LINE
},
241 { KEY_NPAGE
, REQ_MOVE_PAGE_DOWN
},
242 { KEY_PPAGE
, REQ_MOVE_PAGE_UP
},
245 { KEY_IC
, REQ_SCROLL_LINE_UP
}, /* scroll field backward a line */
246 { KEY_DC
, REQ_SCROLL_LINE_DOWN
}, /* scroll field forward a line */
247 { 's', REQ_SCROLL_PAGE_DOWN
}, /* scroll field forward a page */
248 { 'w', REQ_SCROLL_PAGE_UP
}, /* scroll field backward a page */
251 { 'd', REQ_VIEW_DIFF
},
252 { 'l', REQ_VIEW_LOG
},
253 { 'm', REQ_VIEW_MAIN
},
256 { KEY_ESC
, REQ_QUIT
},
258 { 'z', REQ_STOP_LOADING
},
259 { 'v', REQ_SHOW_VERSION
},
260 { 'r', REQ_SCREEN_REDRAW
},
261 { 'n', REQ_TOGGLE_LINE_NUMBERS
},
263 /* wgetch() with nodelay() enabled returns ERR when there's no input. */
264 { ERR
, REQ_SCREEN_UPDATE
},
268 get_request(int request
)
272 for (i
= 0; i
< ARRAY_SIZE(keymap
); i
++)
273 if (keymap
[i
].alias
== request
)
274 return keymap
[i
].request
;
281 * Line-oriented content detection.
326 #define LINE(type, line, fg, bg, attr) \
327 { LINE_##type, (line), STRING_SIZE(line), (fg), (bg), (attr) }
329 static struct line_info line_info
[] = {
331 LINE(DIFF
, "diff --git ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
332 LINE(INDEX
, "index ", COLOR_BLUE
, COLOR_DEFAULT
, 0),
333 LINE(DIFF_CHUNK
, "@@", COLOR_MAGENTA
, COLOR_DEFAULT
, 0),
334 LINE(DIFF_ADD
, "+", COLOR_GREEN
, COLOR_DEFAULT
, 0),
335 LINE(DIFF_DEL
, "-", COLOR_RED
, COLOR_DEFAULT
, 0),
336 LINE(DIFF_OLDMODE
, "old mode ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
337 LINE(DIFF_NEWMODE
, "new mode ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
338 LINE(DIFF_COPY
, "copy ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
339 LINE(DIFF_RENAME
, "rename ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
340 LINE(DIFF_SIM
, "similarity ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
341 LINE(DIFF_DISSIM
, "dissimilarity ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
343 /* Pretty print commit header */
344 LINE(AUTHOR
, "Author: ", COLOR_CYAN
, COLOR_DEFAULT
, 0),
345 LINE(MERGE
, "Merge: ", COLOR_BLUE
, COLOR_DEFAULT
, 0),
346 LINE(DATE
, "Date: ", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
348 /* Raw commit header */
349 LINE(COMMIT
, "commit ", COLOR_GREEN
, COLOR_DEFAULT
, 0),
350 LINE(PARENT
, "parent ", COLOR_BLUE
, COLOR_DEFAULT
, 0),
351 LINE(TREE
, "tree ", COLOR_BLUE
, COLOR_DEFAULT
, 0),
352 LINE(AUTHOR_IDENT
, "author ", COLOR_CYAN
, COLOR_DEFAULT
, 0),
353 LINE(COMMITTER
, "committer ", COLOR_MAGENTA
, COLOR_DEFAULT
, 0),
356 LINE(DIFF_TREE
, "diff-tree ", COLOR_BLUE
, COLOR_DEFAULT
, 0),
357 LINE(SIGNOFF
, " Signed-off-by", COLOR_YELLOW
, COLOR_DEFAULT
, 0),
360 LINE(DEFAULT
, "", COLOR_DEFAULT
, COLOR_DEFAULT
, A_NORMAL
),
361 LINE(CURSOR
, "", COLOR_WHITE
, COLOR_GREEN
, A_BOLD
),
362 LINE(STATUS
, "", COLOR_GREEN
, COLOR_DEFAULT
, 0),
363 LINE(TITLE
, "", COLOR_WHITE
, COLOR_BLUE
, A_BOLD
),
364 LINE(MAIN_DATE
, "", COLOR_BLUE
, COLOR_DEFAULT
, 0),
365 LINE(MAIN_AUTHOR
, "", COLOR_GREEN
, COLOR_DEFAULT
, 0),
366 LINE(MAIN_COMMIT
, "", COLOR_DEFAULT
, COLOR_DEFAULT
, 0),
367 LINE(MAIN_DELIM
, "", COLOR_MAGENTA
, COLOR_DEFAULT
, 0),
370 static struct line_info
*
371 get_line_info(char *line
)
373 int linelen
= strlen(line
);
376 for (i
= 0; i
< ARRAY_SIZE(line_info
); i
++) {
377 if (linelen
< line_info
[i
].linelen
378 || strncasecmp(line_info
[i
].line
, line
, line_info
[i
].linelen
))
381 return &line_info
[i
];
387 static enum line_type
388 get_line_type(char *line
)
390 struct line_info
*info
= get_line_info(line
);
392 return info ? info
->type
: LINE_DEFAULT
;
396 get_line_attr(enum line_type type
)
400 for (i
= 0; i
< ARRAY_SIZE(line_info
); i
++)
401 if (line_info
[i
].type
== type
)
402 return COLOR_PAIR(line_info
[i
].type
) | line_info
[i
].attr
;
410 int default_bg
= COLOR_BLACK
;
411 int default_fg
= COLOR_WHITE
;
416 if (use_default_colors() != ERR
) {
421 for (i
= 0; i
< ARRAY_SIZE(line_info
); i
++) {
422 struct line_info
*info
= &line_info
[i
];
423 int bg
= info
->bg
== COLOR_DEFAULT ? default_bg
: info
->bg
;
424 int fg
= info
->fg
== COLOR_DEFAULT ? default_fg
: info
->fg
;
426 init_pair(info
->type
, fg
, bg
);
442 int (*read
)(struct view
*, char *);
443 int (*draw
)(struct view
*, unsigned int);
444 size_t objsize
; /* Size of objects in the line index */
450 unsigned long offset
; /* Offset of the window top */
451 unsigned long lineno
; /* Current line number */
454 unsigned long lines
; /* Total number of lines */
455 void **line
; /* Line index */
461 static int pager_draw(struct view
*view
, unsigned int lineno
);
462 static int pager_read(struct view
*view
, char *line
);
464 static int main_draw(struct view
*view
, unsigned int lineno
);
465 static int main_read(struct view
*view
, char *line
);
468 "git log --stat -n1 %s ; echo; " \
469 "git diff --find-copies-harder -B -C %s^ %s"
472 "git log --cc --stat -n100 %s"
475 "git log --stat --pretty=raw %s"
477 /* The status window is used for polling keystrokes. */
478 static WINDOW
*status_win
;
479 static WINDOW
*title_win
;
481 /* The number of loading views. Controls when nodelay should be in effect when
482 * polling user input. */
483 static unsigned int nloading
;
485 static struct view views
[] = {
486 { "diff", DIFF_CMD
, commit_id
, pager_read
, pager_draw
, sizeof(char) },
487 { "log", LOG_CMD
, head_id
, pager_read
, pager_draw
, sizeof(char) },
488 { "main", MAIN_CMD
, head_id
, main_read
, main_draw
, sizeof(struct commit
) },
491 /* The display array of active views and the index of the current view. */
492 static struct view
*display
[ARRAY_SIZE(views
)];
493 static unsigned int current_view
;
495 #define foreach_view(view, i) \
496 for (i = 0; i < sizeof(display) && (view = display[i]); i++)
500 redraw_view_from(struct view
*view
, int lineno
)
502 assert(0 <= lineno
&& lineno
< view
->height
);
504 for (; lineno
< view
->height
; lineno
++) {
505 if (!view
->draw(view
, lineno
))
509 redrawwin(view
->win
);
514 redraw_view(struct view
*view
)
517 redraw_view_from(view
, 0);
521 resize_view(struct view
*view
)
525 getmaxyx(stdscr
, lines
, cols
);
528 mvwin(view
->win
, 0, 0);
529 wresize(view
->win
, lines
- 2, cols
);
532 view
->win
= newwin(lines
- 2, 0, 0, 0);
534 report("failed to create %s view", view
->name
);
537 scrollok(view
->win
, TRUE
);
540 getmaxyx(view
->win
, view
->height
, view
->width
);
544 /* Scrolling backend */
546 do_scroll_view(struct view
*view
, int lines
)
548 /* The rendering expects the new offset. */
549 view
->offset
+= lines
;
551 assert(0 <= view
->offset
&& view
->offset
< view
->lines
);
554 /* Redraw the whole screen if scrolling is pointless. */
555 if (view
->height
< ABS(lines
)) {
559 int line
= lines
> 0 ? view
->height
- lines
: 0;
560 int end
= line
+ ABS(lines
);
562 wscrl(view
->win
, lines
);
564 for (; line
< end
; line
++) {
565 if (!view
->draw(view
, line
))
570 /* Move current line into the view. */
571 if (view
->lineno
< view
->offset
) {
572 view
->lineno
= view
->offset
;
575 } else if (view
->lineno
>= view
->offset
+ view
->height
) {
576 view
->lineno
= view
->offset
+ view
->height
- 1;
577 view
->draw(view
, view
->lineno
- view
->offset
);
580 assert(view
->offset
<= view
->lineno
&& view
->lineno
< view
->lines
);
582 redrawwin(view
->win
);
587 /* Scroll frontend */
589 scroll_view(struct view
*view
, int request
)
594 case REQ_SCROLL_PAGE_DOWN
:
595 lines
= view
->height
;
596 case REQ_SCROLL_LINE_DOWN
:
597 if (view
->offset
+ lines
> view
->lines
)
598 lines
= view
->lines
- view
->offset
;
600 if (lines
== 0 || view
->offset
+ view
->height
>= view
->lines
) {
601 report("already at last line");
606 case REQ_SCROLL_PAGE_UP
:
607 lines
= view
->height
;
608 case REQ_SCROLL_LINE_UP
:
609 if (lines
> view
->offset
)
610 lines
= view
->offset
;
613 report("already at first line");
621 do_scroll_view(view
, lines
);
626 move_view(struct view
*view
, int request
)
631 case REQ_MOVE_FIRST_LINE
:
632 steps
= -view
->lineno
;
635 case REQ_MOVE_LAST_LINE
:
636 steps
= view
->lines
- view
->lineno
- 1;
639 case REQ_MOVE_PAGE_UP
:
640 steps
= view
->height
> view
->lineno
641 ?
-view
->lineno
: -view
->height
;
644 case REQ_MOVE_PAGE_DOWN
:
645 steps
= view
->lineno
+ view
->height
>= view
->lines
646 ? view
->lines
- view
->lineno
- 1 : view
->height
;
658 if (steps
<= 0 && view
->lineno
== 0) {
659 report("already at first line");
662 } else if (steps
>= 0 && view
->lineno
+ 1 == view
->lines
) {
663 report("already at last line");
667 /* Move the current line */
668 view
->lineno
+= steps
;
669 assert(0 <= view
->lineno
&& view
->lineno
< view
->lines
);
671 /* Repaint the old "current" line if we be scrolling */
672 if (ABS(steps
) < view
->height
)
673 view
->draw(view
, view
->lineno
- steps
- view
->offset
);
675 /* Check whether the view needs to be scrolled */
676 if (view
->lineno
< view
->offset
||
677 view
->lineno
>= view
->offset
+ view
->height
) {
678 if (steps
< 0 && -steps
> view
->offset
) {
679 steps
= -view
->offset
;
681 } else if (steps
> 0) {
682 if (view
->lineno
== view
->lines
- 1 &&
683 view
->lines
> view
->height
) {
684 steps
= view
->lines
- view
->offset
- 1;
685 if (steps
>= view
->height
)
686 steps
-= view
->height
- 1;
690 do_scroll_view(view
, steps
);
694 /* Draw the current line */
695 view
->draw(view
, view
->lineno
- view
->offset
);
697 redrawwin(view
->win
);
705 begin_update(struct view
*view
)
712 if (snprintf(buf
, sizeof(buf
), view
->cmd
, id
, id
, id
) < sizeof(buf
))
713 view
->pipe
= popen(buf
, "r");
719 nodelay(status_win
, TRUE
);
722 display
[current_view
] = view
;
732 end_update(struct view
*view
)
734 wattrset(view
->win
, A_NORMAL
);
739 nodelay(status_win
, FALSE
);
743 update_view(struct view
*view
)
748 /* The number of lines to read. If too low it will cause too much
749 * redrawing (and possible flickering), if too high responsiveness
751 int lines
= view
->height
;
752 int redraw_from
= -1;
757 /* Only redraw if lines are visible. */
758 if (view
->offset
+ view
->height
>= view
->lines
)
759 redraw_from
= view
->lines
- view
->offset
;
761 tmp
= realloc(view
->line
, sizeof(*view
->line
) * (view
->lines
+ lines
));
767 while ((line
= fgets(buffer
, sizeof(buffer
), view
->pipe
))) {
770 linelen
= strlen(line
);
772 line
[linelen
- 1] = 0;
774 if (!view
->read(view
, line
))
781 /* CPU hogilicious! */
784 if (redraw_from
>= 0) {
785 /* If this is an incremental update, redraw the previous line
786 * since for commits some members could have changed. */
790 /* Incrementally draw avoids flickering. */
791 redraw_view_from(view
, redraw_from
);
794 if (ferror(view
->pipe
)) {
795 report("failed to read %s: %s", view
->cmd
, strerror(errno
));
798 } else if (feof(view
->pipe
)) {
799 report("loaded %d lines", view
->lines
);
806 report("allocation failure");
815 switch_view(struct view
*prev
, int request
)
817 struct view
*view
= &views
[request
];
818 struct view
*displayed
;
822 foreach_view (displayed
, i
) ;
825 report("already in %s view", view
->name
);
827 report("FIXME: Maximize");
832 foreach_view (displayed
, i
) {
833 if (view
== displayed
) {
835 report("new current view");
847 for (i
= 0; i
< view
->lines
; i
++)
855 if (prev
&& prev
->pipe
)
858 if (begin_update(view
)) {
862 /* Clear the old view and let the incremental updating
863 * refill the screen. */
865 report("loading...");
873 /* Process keystrokes */
875 view_driver(struct view
*view
, int key
)
877 int request
= get_request(key
);
883 case REQ_MOVE_PAGE_UP
:
884 case REQ_MOVE_PAGE_DOWN
:
885 case REQ_MOVE_FIRST_LINE
:
886 case REQ_MOVE_LAST_LINE
:
888 move_view(view
, request
);
891 case REQ_SCROLL_LINE_DOWN
:
892 case REQ_SCROLL_LINE_UP
:
893 case REQ_SCROLL_PAGE_DOWN
:
894 case REQ_SCROLL_PAGE_UP
:
896 scroll_view(view
, request
);
902 view
= switch_view(view
, request
);
905 case REQ_TOGGLE_LINE_NUMBERS
:
906 opt_line_number
= !opt_line_number
;
911 case REQ_STOP_LOADING
:
912 foreach_view (view
, i
) {
915 //scroll_view(view, 0);
920 case REQ_SHOW_VERSION
:
921 report("version %s", VERSION
);
924 case REQ_SCREEN_REDRAW
:
928 case REQ_SCREEN_UPDATE
:
949 pager_draw(struct view
*view
, unsigned int lineno
)
956 if (view
->offset
+ lineno
>= view
->lines
)
959 line
= view
->line
[view
->offset
+ lineno
];
960 type
= get_line_type(line
);
962 if (view
->offset
+ lineno
== view
->lineno
) {
963 if (type
== LINE_COMMIT
)
964 string_copy(commit_id
, line
+ 7);
968 attr
= get_line_attr(type
);
969 wattrset(view
->win
, attr
);
971 linelen
= strlen(line
);
972 linelen
= MIN(linelen
, view
->width
);
974 if (opt_line_number
) {
975 unsigned int real_lineno
= view
->offset
+ lineno
+ 1;
978 if (real_lineno
== 1 || (real_lineno
% NUMBER_INTERVAL
) == 0)
979 mvwprintw(view
->win
, lineno
, 0, "%4d: ", real_lineno
);
981 mvwaddstr(view
->win
, lineno
, 0, " : ");
985 waddnstr(view
->win
, " ", 8 - (col
% 8));
986 col
+= 8 - (col
% 8);
990 char *tab
= strchr(line
, '\t');
993 waddnstr(view
->win
, line
, tab
- line
);
995 waddstr(view
->win
, line
);
1000 waddstr(view
->win
, line
);
1003 /* No empty lines makes cursor drawing and clearing implicit. */
1005 line
= " ", linelen
= 1;
1006 mvwaddnstr(view
->win
, lineno
, 0, line
, linelen
);
1013 pager_read(struct view
*view
, char *line
)
1015 view
->line
[view
->lines
] = strdup(line
);
1016 if (!view
->line
[view
->lines
])
1024 main_draw(struct view
*view
, unsigned int lineno
)
1027 struct commit
*commit
;
1028 enum line_type type
;
1032 if (view
->offset
+ lineno
>= view
->lines
)
1035 commit
= view
->line
[view
->offset
+ lineno
];
1036 if (!*commit
->author
)
1039 if (view
->offset
+ lineno
== view
->lineno
) {
1040 string_copy(commit_id
, commit
->id
);
1043 type
= LINE_MAIN_COMMIT
;
1046 wmove(view
->win
, lineno
, cols
);
1047 wattrset(view
->win
, get_line_attr(LINE_MAIN_DATE
));
1049 timelen
= strftime(buf
, sizeof(buf
), DATE_FORMAT
, &commit
->time
);
1050 waddnstr(view
->win
, buf
, timelen
);
1051 waddstr(view
->win
, " ");
1054 wmove(view
->win
, lineno
, cols
);
1055 wattrset(view
->win
, get_line_attr(LINE_MAIN_AUTHOR
));
1057 if (strlen(commit
->author
) > 19) {
1058 waddnstr(view
->win
, commit
->author
, 18);
1059 wattrset(view
->win
, get_line_attr(LINE_MAIN_DELIM
));
1060 waddch(view
->win
, '~');
1062 waddstr(view
->win
, commit
->author
);
1066 wattrset(view
->win
, A_NORMAL
);
1067 mvwaddch(view
->win
, lineno
, cols
, ACS_LTEE
);
1068 wattrset(view
->win
, get_line_attr(type
));
1069 mvwaddstr(view
->win
, lineno
, cols
+ 2, commit
->title
);
1070 wattrset(view
->win
, A_NORMAL
);
1075 /* Reads git log --pretty=raw output and parses it into the commit struct. */
1077 main_read(struct view
*view
, char *line
)
1079 enum line_type type
= get_line_type(line
);
1080 struct commit
*commit
;
1084 commit
= calloc(1, sizeof(struct commit
));
1088 line
+= STRING_SIZE("commit ");
1090 view
->line
[view
->lines
++] = commit
;
1091 string_copy(commit
->id
, line
);
1094 case LINE_AUTHOR_IDENT
:
1096 char *ident
= line
+ STRING_SIZE("author ");
1097 char *end
= strchr(ident
, '<');
1100 for (; end
> ident
&& isspace(end
[-1]); end
--) ;
1104 commit
= view
->line
[view
->lines
- 1];
1105 string_copy(commit
->author
, ident
);
1107 /* Parse epoch and timezone */
1109 char *secs
= strchr(end
+ 1, '>');
1113 if (!secs
|| secs
[1] != ' ')
1117 time
= (time_t) atol(secs
);
1118 zone
= strchr(secs
, ' ');
1119 if (zone
&& strlen(zone
) == STRING_SIZE(" +0700")) {
1123 tz
= ('0' - zone
[1]) * 60 * 60 * 10;
1124 tz
+= ('0' - zone
[2]) * 60 * 60;
1125 tz
+= ('0' - zone
[3]) * 60;
1126 tz
+= ('0' - zone
[4]) * 60;
1133 gmtime_r(&time
, &commit
->time
);
1138 /* Fill in the commit title */
1139 commit
= view
->line
[view
->lines
- 1];
1140 if (commit
->title
[0] ||
1141 strncmp(line
, " ", 4) ||
1145 string_copy(commit
->title
, line
+ 4);
1165 /* FIXME: Shutdown gracefully. */
1170 static void die(const char *err
, ...)
1176 va_start(args
, err
);
1177 fputs("tig: ", stderr
);
1178 vfprintf(stderr
, err
, args
);
1179 fputs("\n", stderr
);
1188 struct view
*view
= display
[current_view
];
1191 wmove(title_win
, 0, 0);
1193 /* [main] ref: 334b506... - line 6 of 4383 (0%) */
1194 wprintw(title_win
, "[%s] ref: %s", view
->name
, commit_id
);
1197 wprintw(title_win
, " - line %d of %d (%d%%)",
1200 view
->lines ?
(view
->lineno
+ 1) * 100 / view
->lines
: 0);
1203 wprintw(title_win
, "commit %s", commit_id
);
1205 wrefresh(title_win
);
1208 /* Status and title window updater. */
1210 report(const char *msg
, ...)
1214 va_start(args
, msg
);
1219 wmove(status_win
, 0, 0);
1222 if (display
[current_view
])
1223 wprintw(status_win
, "%s %4s: ", commit_id
, display
[current_view
]->name
);
1225 vwprintw(status_win
, msg
, args
);
1226 wrefresh(status_win
);
1232 main(int argc
, char *argv
[])
1238 signal(SIGINT
, quit
);
1240 git_cmd
= parse_options(argc
, argv
);
1243 if (git_cmd
< argc
) {
1247 request
= opt_request
;
1249 initscr(); /* initialize the curses library */
1250 nonl(); /* tell curses not to do NL->CR/NL on output */
1251 cbreak(); /* take input chars one at a time, no wait for \n */
1252 noecho(); /* don't echo input */
1253 leaveok(stdscr
, TRUE
);
1259 getmaxyx(stdscr
, y
, x
);
1260 status_win
= newwin(1, 0, y
- 1, 0);
1262 die("Failed to create status window");
1264 title_win
= newwin(1, 0, y
- 2, 0);
1266 die("Failed to create title window");
1268 /* Enable keyboard mapping */
1269 keypad(status_win
, TRUE
);
1270 wbkgdset(status_win
, get_line_attr(LINE_STATUS
));
1271 wbkgdset(title_win
, get_line_attr(LINE_TITLE
));
1273 while (view_driver(display
[current_view
], request
)) {
1277 foreach_view (view
, i
) {
1283 /* Refresh, accept single keystroke of input */
1284 request
= wgetch(status_win
);
1285 if (request
== KEY_RESIZE
) {
1288 getmaxyx(stdscr
, lines
, cols
);
1290 mvwin(status_win
, lines
- 1, 0);
1291 wresize(status_win
, 1, cols
- 1);
1293 mvwin(title_win
, lines
- 2, 0);
1294 wresize(title_win
, 1, cols
- 1);
1306 * Features that should be explored.
1308 * - Dynamic scaling of line number indentation.
1310 * - Proper command line handling; ability to take the command that should be
1315 * - Internal command line (exmode-inspired) which allows to specify what git
1316 * log or git diff command to run. Example:
1320 * - Proper resizing support. I am yet to figure out whether catching SIGWINCH
1321 * is preferred over using ncurses' built-in support for resizing.
1327 * Copyright (c) Jonas Fonseca <fonseca@diku.dk>, 2006
1329 * This program is free software; you can redistribute it and/or modify
1330 * it under the terms of the GNU General Public License as published by
1331 * the Free Software Foundation; either version 2 of the License, or
1332 * (at your option) any later version.
1337 * link:http://www.kernel.org/pub/software/scm/git/docs/[git(7)],
1338 * link:http://www.kernel.org/pub/software/scm/cogito/docs/[cogito(7)]
1339 * gitk(1): git repository browser written using tcl/tk,
1340 * gitview(1): git repository browser written using python/gtk.