aboutsummaryrefslogtreecommitdiff
path: root/task_tracker.c
blob: 99846184fa0c83819d1553a3e7b66daf3b0d6450 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Compile with: gcc task_tracker.c -O2 -m64 -lncurses -o task_tracker.x64

#include <string.h>
#include <ncurses.h>


void draw_header()
{
	const char *table_headers[] = { "Task", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Total" };
	const int table_headers_size = sizeof(table_headers)/sizeof(char*);
	
	int row,col;                        /* to store the number of rows and the number of colums of the screen */
	initscr();							/* start the curses mode */
	getmaxyx(stdscr,row,col);			/* get the number of rows and columns */
	
	mvaddch(0, 0, ACS_ULCORNER);
	for (int idx = 0; idx < table_headers_size; idx++) {
		if (idx > 0) {
			addch(ACS_TTEE);
// 			printw(" %c", ACS_PLUS);
		}
		addch(ACS_HLINE);
		printw(" %s ", table_headers[idx]);
		addch(ACS_HLINE);
		
	}
	
	int cursor_y, cursor_x;
	getyx(stdscr, cursor_y, cursor_x);
	for (int idx = cursor_x; idx < col-1; idx++) {
		addch(ACS_HLINE);
	}
	addch(ACS_URCORNER);
}

void draw_table()
{

}

void draw_footer()
{
	const char *app_name = "Task Tracker";
	const char *app_version = "v1.0";
	
	int row, col;                        /* to store the number of rows and the number of colums of the screen */
	initscr();							/* start the curses mode */
	getmaxyx(stdscr,row,col);			/* get the number of rows and columns */
	
	printw("Row %d", row);
	
	mvaddch(row-1, 0, ACS_LLCORNER);
	addch(' ');
	printw(app_name);
	addch(' ');
	for (int idx = strlen(app_name) + 3; idx < col - strlen(app_version) - 3; idx ++) {
		addch(ACS_HLINE);
	}
	addch(' ');
	printw(app_version);
	addch(' ');
	addch(ACS_LRCORNER);
}


WINDOW *create_newwin(int height, int width, int starty, int startx);
void destroy_win(WINDOW *local_win);

int main(int argc, char *argv[])
{	WINDOW *my_win;
	int startx, starty, width, height;
	int ch;

	initscr();			/* Start curses mode 		*/
	cbreak();			/* Line buffering disabled, Pass on
					 * everty thing to me 		*/
	keypad(stdscr, TRUE);		/* I need that nifty F1 	*/
    curs_set(0);        // Set cursor invisible.

	height = 3;
	width = 10;
	starty = (LINES - height) / 2;	/* Calculating for a center placement */
	startx = (COLS - width) / 2;	/* of the window		*/
	printw("Press F1 to exit");
	refresh();
	my_win = create_newwin(height, width, starty, startx);
    
					int rows;
				int colums;
	
	ch = KEY_RESIZE;
	do {
        switch(ch)
		{
			case KEY_RESIZE:
				erase();
				break;
			
			case KEY_LEFT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty,--startx);
				break;
			
			case KEY_RIGHT:
				destroy_win(my_win);
				my_win = create_newwin(height, width, starty,++startx);
				break;
			
			case KEY_UP:
				destroy_win(my_win);
				my_win = create_newwin(height, width, --starty,startx);
				break;
			
			case KEY_DOWN:
				destroy_win(my_win);
				my_win = create_newwin(height, width, ++starty,startx);
				break;	
		}
		
		draw_header();
		draw_table();
		draw_footer();
	
	} while((ch = getch()) != KEY_F(1));
	
	endwin();
	return 0;
}



WINDOW *create_newwin(int height, int width, int starty, int startx)
{	WINDOW *local_win;

	local_win = newwin(height, width, starty, startx);
	box(local_win, 0 , 0);		/* 0, 0 gives default characters 
					 * for the vertical and horizontal
					 * lines			*/
	wrefresh(local_win);		/* Show that box 		*/

	return local_win;
}

void destroy_win(WINDOW *local_win)
{	
	/* box(local_win, ' ', ' '); : This won't produce the desired
	 * result of erasing the window. It will leave it's four corners 
	 * and so an ugly remnant of window. 
	 */
	wborder(local_win, ' ', ' ', ' ',' ',' ',' ',' ',' ');
	/* The parameters taken are 
	 * 1. win: the window on which to operate
	 * 2. ls: character to be used for the left side of the window 
	 * 3. rs: character to be used for the right side of the window 
	 * 4. ts: character to be used for the top side of the window 
	 * 5. bs: character to be used for the bottom side of the window 
	 * 6. tl: character to be used for the top left corner of the window 
	 * 7. tr: character to be used for the top right corner of the window 
	 * 8. bl: character to be used for the bottom left corner of the window 
	 * 9. br: character to be used for the bottom right corner of the window
	 */
	wrefresh(local_win);
	delwin(local_win);
}