diff options
Diffstat (limited to 'testing/toxic/main.c')
-rw-r--r-- | testing/toxic/main.c | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/testing/toxic/main.c b/testing/toxic/main.c index c596b708..3b45a89f 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c | |||
@@ -50,7 +50,7 @@ void on_request(uint8_t* public_key, uint8_t* data, uint16_t length) { | |||
50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { | 50 | void on_message(int friendnumber, uint8_t* string, uint16_t length) { |
51 | size_t i; | 51 | size_t i; |
52 | 52 | ||
53 | wprintw(prompt->window, "\n(message) %d: %s!\n", friendnumber, string); | 53 | wprintw(prompt->window, "\n(message) %d: %s\n", friendnumber, string); |
54 | 54 | ||
55 | for(i=0; i<w_num; i++) { | 55 | for(i=0; i<w_num; i++) { |
56 | if(windows[i].onMessage != NULL) | 56 | if(windows[i].onMessage != NULL) |
@@ -170,12 +170,12 @@ static void do_tox() { | |||
170 | doMessenger(); | 170 | doMessenger(); |
171 | } | 171 | } |
172 | 172 | ||
173 | static void load_data() { | 173 | static void load_data(char *path) { |
174 | FILE* fd; | 174 | FILE* fd; |
175 | size_t len; | 175 | size_t len; |
176 | uint8_t* buf; | 176 | uint8_t* buf; |
177 | 177 | ||
178 | if((fd = fopen("data", "r")) != NULL) { | 178 | if((fd = fopen(path, "r")) != NULL) { |
179 | fseek(fd, 0, SEEK_END); | 179 | fseek(fd, 0, SEEK_END); |
180 | len = ftell(fd); | 180 | len = ftell(fd); |
181 | fseek(fd, 0, SEEK_SET); | 181 | fseek(fd, 0, SEEK_SET); |
@@ -213,7 +213,7 @@ static void load_data() { | |||
213 | 213 | ||
214 | Messenger_save(buf); | 214 | Messenger_save(buf); |
215 | 215 | ||
216 | fd = fopen("data", "w"); | 216 | fd = fopen(path, "w"); |
217 | if(fd == NULL) { | 217 | if(fd == NULL) { |
218 | fprintf(stderr, "fopen() failed.\n"); | 218 | fprintf(stderr, "fopen() failed.\n"); |
219 | 219 | ||
@@ -280,35 +280,38 @@ void prepare_window(WINDOW* w) { | |||
280 | wresize(w, LINES-2, COLS); | 280 | wresize(w, LINES-2, COLS); |
281 | } | 281 | } |
282 | 282 | ||
283 | /* | ||
284 | * Draws cursor relative to input on prompt window. | ||
285 | * Removes cursor on friends window and chat windows. | ||
286 | * | ||
287 | * TODO: Make it work for chat windows | ||
288 | */ | ||
289 | void position_cursor(WINDOW* w, char* title) | ||
290 | { | ||
291 | curs_set(1); | ||
292 | if (strcmp(title, "[prompt]") == 0) { // main/prompt window | ||
293 | int x, y; | ||
294 | getyx(w, y, x); | ||
295 | move(y, x); | ||
296 | } | ||
297 | else if (strcmp(title, "[friends]") == 0) // friends window | ||
298 | curs_set(0); | ||
299 | else // any other window (i.e chat) | ||
300 | curs_set(0); | ||
301 | } | ||
302 | |||
303 | int main(int argc, char* argv[]) { | 283 | int main(int argc, char* argv[]) { |
304 | int ch; | 284 | int ch; |
285 | int i = 0; | ||
286 | int f_flag = 0; | ||
287 | char *filename = "data"; | ||
305 | ToxWindow* a; | 288 | ToxWindow* a; |
306 | 289 | ||
290 | for(i = 0; i < argc; i++) { | ||
291 | if(argv[i][0] == '-') { | ||
292 | if(argv[i][1] == 'f') { | ||
293 | if(argv[i + 1] != NULL) | ||
294 | filename = argv[i + 1]; | ||
295 | else { | ||
296 | f_flag = -1; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | |||
307 | init_term(); | 302 | init_term(); |
308 | init_tox(); | 303 | init_tox(); |
309 | load_data(); | 304 | load_data(filename); |
310 | init_windows(); | 305 | init_windows(); |
311 | 306 | ||
307 | if(f_flag == -1) { | ||
308 | attron(COLOR_PAIR(3) | A_BOLD); | ||
309 | wprintw(prompt->window, "You passed '-f' without giving an argument!\n" | ||
310 | "defaulting to 'data' for a keyfile...\n"); | ||
311 | attroff(COLOR_PAIR(3) | A_BOLD); | ||
312 | } | ||
313 | |||
314 | |||
312 | while(true) { | 315 | while(true) { |
313 | // Update tox. | 316 | // Update tox. |
314 | do_tox(); | 317 | do_tox(); |
@@ -317,9 +320,8 @@ int main(int argc, char* argv[]) { | |||
317 | a = &windows[w_active]; | 320 | a = &windows[w_active]; |
318 | prepare_window(a->window); | 321 | prepare_window(a->window); |
319 | a->blink = false; | 322 | a->blink = false; |
320 | a->onDraw(a); | ||
321 | draw_bar(); | 323 | draw_bar(); |
322 | position_cursor(a->window, a->title); | 324 | a->onDraw(a); |
323 | 325 | ||
324 | // Handle input. | 326 | // Handle input. |
325 | ch = getch(); | 327 | ch = getch(); |