Commit | Line | Data |
---|---|---|
800a900c JF |
1 | /* |
2 | * | |
3 | * | |
4 | */ | |
5 | ||
6 | #include <stdlib.h> | |
7 | #include <stdio.h> | |
8 | #include <ctype.h> | |
9 | #include <signal.h> | |
10 | ||
11 | #include <curses.h> | |
12 | ||
13 | /* | |
14 | * Init and quit | |
15 | */ | |
16 | ||
17 | static void quit(int sig) | |
18 | { | |
19 | endwin(); | |
20 | ||
21 | /* do your non-curses wrapup here */ | |
22 | ||
23 | exit(0); | |
24 | } | |
25 | ||
26 | static void | |
27 | init_colors(void) | |
28 | { | |
29 | start_color(); | |
30 | ||
31 | init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); | |
32 | init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); | |
33 | init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); | |
34 | init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); | |
35 | init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); | |
36 | init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); | |
37 | init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); | |
38 | init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); | |
39 | } | |
40 | ||
41 | static void | |
42 | init(void) | |
43 | { | |
44 | (void) signal(SIGINT, quit); /* arrange interrupts to terminate */ | |
45 | ||
46 | (void) initscr(); /* initialize the curses library */ | |
47 | keypad(stdscr, TRUE); /* enable keyboard mapping */ | |
48 | (void) nonl(); /* tell curses not to do NL->CR/NL on output */ | |
49 | (void) cbreak(); /* take input chars one at a time, no wait for \n */ | |
50 | (void) noecho(); /* don't echo input */ | |
51 | ||
52 | if (has_colors()) | |
53 | init_colors(); | |
54 | } | |
55 | ||
56 | /* | |
57 | * Main | |
58 | */ | |
59 | ||
60 | int | |
61 | main(int argc, char *argv[]) | |
62 | { | |
63 | int x, y; | |
64 | ||
65 | init(); | |
66 | ||
67 | getmaxyx(stdscr, y, x); | |
68 | ||
69 | attrset(COLOR_PAIR(COLOR_GREEN)); | |
70 | ||
71 | addch(ACS_VLINE); | |
72 | printw("%s", "cg-view"); | |
73 | addch(ACS_LTEE); | |
74 | addch(ACS_HLINE); | |
75 | addch(ACS_HLINE); | |
76 | addch(ACS_HLINE); | |
77 | addch(ACS_HLINE); | |
78 | addch(ACS_HLINE); | |
79 | addch(ACS_HLINE); | |
80 | addch(ACS_HLINE); | |
81 | mvprintw(y - 1, 0, "%s", "press 'q' to quit"); | |
82 | ||
83 | { | |
84 | FILE *rev_list = popen("git-rev-list $(git-rev-parse --since=1.month) HEAD", "r"); | |
85 | char buffer[BUFSIZ]; | |
86 | char *line; | |
87 | int lineno = 1; | |
88 | ||
89 | while ((line = fgets(buffer, sizeof(buffer), rev_list))) { | |
90 | move(lineno, 0); | |
91 | printw("%2d: ", lineno++); | |
92 | addch(ACS_LTEE); | |
93 | addch(ACS_HLINE); | |
94 | addstr(line); | |
95 | } | |
96 | } | |
97 | attrset(A_NORMAL); | |
98 | /* scrollok();*/ | |
99 | ||
100 | for (;;) { | |
101 | int c = getch(); /* refresh, accept single keystroke of input */ | |
102 | ||
103 | /* Process the command keystroke */ | |
104 | switch (c) { | |
105 | case 'q': | |
106 | quit(0); | |
107 | return 0; | |
108 | ||
109 | case 's': | |
110 | addstr("Shelling out..."); | |
111 | def_prog_mode(); /* save current tty modes */ | |
112 | endwin(); /* restore original tty modes */ | |
113 | system("sh"); /* run shell */ | |
114 | addstr("returned.\n"); /* prepare return message */ | |
115 | reset_prog_mode(); | |
116 | //refresh(); /* restore save modes, repaint screen */ | |
117 | break; | |
118 | ||
119 | default: | |
120 | if (isprint(c) || isspace(c)) | |
121 | addch(c); | |
122 | } | |
123 | ||
124 | } | |
125 | ||
126 | quit(0); | |
127 | } |