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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
// Compile with: gcc task_tracker.c -Wall -O2 -m64 -lncurses -o task_tracker.x64
#include <inttypes.h>
#include <ncurses.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int selected_task = -1;
struct task_event {
char* name;
time_t start;
time_t end;
};
struct task_info {
char* name;
uint64_t total_seconds;
};
char** tasks_names = NULL;
uint32_t tasks_names_size = 0;
uint32_t tasks_names_capacity = 0;
void add_task(char* name)
{
if (tasks_names_size >= tasks_names_capacity)
{
tasks_names_capacity = tasks_names_capacity == 0 ? 16 : tasks_names_capacity << 1;
tasks_names = realloc(tasks_names, sizeof(char*) * tasks_names_capacity);
/*
uint32_t new_capacity = tasks_names_capacity == 0 ? 16 : tasks_names_capacity << 1;
char** new_memory = malloc(sizeof(char*) * new_capacity);
if (tasks_names != NULL)
{
memcpy(new_memory, tasks_names, sizeof(char*) * tasks_names_capacity);
free(tasks_names);
}
tasks_names_capacity = new_capacity;
tasks_names = (char *[])new_memory;
*/
}
tasks_names[tasks_names_size] = name;
tasks_names_size++;
// TODO Missing the task_info array.
}
void add_task_event(char* name, uint64_t start, uint64_t end)
{
// TODO Missing the task_event array.
}
void fake_data()
{
const char* csv_head = "task_name,start,end";
const char* csv_line[] = {
"PI-0000,1659479138,1659482738",
"PI-0001,1659479127,1659482727",
"XPTO-01 : testing long name,1659479138,1659482738",
"Olá vamos cantar uma canção.,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
"[ TST-00 á],1659479138,1659482738",
"[ XPTO- 01,1659479127,1659482727",
};
// const char* csv_line = "1659479138,1659482738";
// const char* csv_line = "zZ[ ã ]Yy,123";
// char name[] = { 'a', 'b', 'c', '\0' };
char* name;
uint64_t start;
uint64_t end;
printf("--- --- àè.ªãº.éá --- ---\n");
uint32_t lines_count = sizeof(csv_line)/sizeof(char*);
for (uint32_t idx = 0; idx < lines_count; idx++)
{
sscanf(csv_line[idx], "%m[^,\n],%" SCNu64 ",%" SCNu64, &name, &start, &end);
add_task(name);
printf("bazinga: %s : %d : %d\n", name, start, end);
}
printf("### ### --------- ### ###\n");
// tasks_names =
// Free tasks names.
for (uint32_t idx = tasks_names_size; idx > 0; idx--)
{
printf("> %s\n", tasks_names[idx-1]);
free(tasks_names[idx-1]);
}
free(tasks_names);
return;
/*
char *token, *copy, *to_free;
copy = to_free = strdup(csv_line);
while ( token = strsep(&str, ",") )
{
my_fn(token);
}
free(to_free);
*/
// tasks_names = malloc( ...
time_t x = time(NULL);
// x = (time_t)((1U << 32) - 1);
printf("%s\n", ctime(&x));
x = x<<1;
printf("%s\n", ctime(&x));
x += 1;
printf("%s\n", ctime(&x));
x = x<<1;
printf("%s\n", ctime(&x));
x = x<<1;
printf("%s\n", ctime(&x));
x = x<<1;
printf("%s\n", ctime(&x));
x = x<<1;
printf("%s\n", ctime(&x));
}
void draw_table()
{
struct task_info asd;
}
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_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[])
{
fake_data();
return 0;
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;
fake_data();
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);
}
|