Mercurial > hg > nnchat
comparison ui.c @ 700:f3ec1cb11cea
Trim whitespace.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 17 Jan 2020 20:03:41 +0200 |
parents | 6fa9c36d0634 |
children | f3b119599b3a |
comparison
equal
deleted
inserted
replaced
699:e9232ce52bf8 | 700:f3ec1cb11cea |
---|---|
118 | 118 |
119 memset(chatWindows, 0, sizeof(chatWindows)); | 119 memset(chatWindows, 0, sizeof(chatWindows)); |
120 chatWindows[0] = nn_window_new(NULL); | 120 chatWindows[0] = nn_window_new(NULL); |
121 nn_log_open(chatWindows[0]); | 121 nn_log_open(chatWindows[0]); |
122 currWin = chatWindows[0]; | 122 currWin = chatWindows[0]; |
123 | 123 |
124 return TRUE; | 124 return TRUE; |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 void nnwin_shutdown() | 128 void nnwin_shutdown() |
223 | 223 |
224 if (val < 9) | 224 if (val < 9) |
225 *col = A_DIM | COLOR_PAIR(val); | 225 *col = A_DIM | COLOR_PAIR(val); |
226 else if (val < 30) | 226 else if (val < 30) |
227 *col = A_BOLD | COLOR_PAIR(val - 9); | 227 *col = A_BOLD | COLOR_PAIR(val - 9); |
228 | 228 |
229 return TRUE; | 229 return TRUE; |
230 } | 230 } |
231 | 231 |
232 | 232 |
233 #define QPUTCH(ch) nnwin_putch(&(win->line->buf), &(win->line->bufsize), &(win->line->len), col, ch) | 233 #define QPUTCH(ch) nnwin_putch(&(win->line->buf), &(win->line->bufsize), &(win->line->len), col, ch) |
242 return FALSE; | 242 return FALSE; |
243 } | 243 } |
244 | 244 |
245 (*buf)[*len] = ((unsigned char) ch) | color; | 245 (*buf)[*len] = ((unsigned char) ch) | color; |
246 (*len)++; | 246 (*len)++; |
247 | 247 |
248 return TRUE; | 248 return TRUE; |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 int nnwin_print(nn_window_t *win, const char *fmt) | 252 int nnwin_print(nn_window_t *win, const char *fmt) |
253 { | 253 { |
254 const char *s = fmt; | 254 const char *s = fmt; |
255 int col = 0; | 255 int col = 0; |
256 | 256 |
257 if (win == NULL) | 257 if (win == NULL) |
258 return -16; | 258 return -16; |
259 | 259 |
260 while (*s) | 260 while (*s) |
261 { | 261 { |
262 if (win->line == NULL) | 262 if (win->line == NULL) |
263 { | 263 { |
264 win->line = th_malloc0(sizeof(nn_line_t)); | 264 win->line = th_malloc0(sizeof(nn_line_t)); |
349 else | 349 else |
350 { | 350 { |
351 // Save cursor position | 351 // Save cursor position |
352 getyx(stdscr, sy, sx); | 352 getyx(stdscr, sy, sx); |
353 } | 353 } |
354 | 354 |
355 // Check if update is forced or if the window is dirty | 355 // Check if update is forced or if the window is dirty |
356 if (currWin != NULL && (force || currWin->dirty)) | 356 if (currWin != NULL && (force || currWin->dirty)) |
357 { | 357 { |
358 int y, offs; | 358 int y, offs; |
359 th_ringbuf_t *buf = currWin->data; | 359 th_ringbuf_t *buf = currWin->data; |
408 #if 0 | 408 #if 0 |
409 snprintf(tmpStr, sizeof(tmpStr), | 409 snprintf(tmpStr, sizeof(tmpStr), |
410 " ½10½%s½13½ | ½16½%s½13½ | ½11½#%06x½13½ | WIN: %d: %s / %d | ½11½", | 410 " ½10½%s½13½ | ½16½%s½13½ | ½11½#%06x½13½ | WIN: %d: %s / %d | ½11½", |
411 tmpStamp, | 411 tmpStamp, |
412 username, | 412 username, |
413 usercolor, | 413 usercolor, |
414 currWin->num + 1, | 414 currWin->num + 1, |
415 currWin->id != NULL ? currWin->id : "MAIN", | 415 currWin->id != NULL ? currWin->id : "MAIN", |
416 currWin->pos); | 416 currWin->pos); |
417 #else | 417 #else |
418 snprintf(tmpStr, sizeof(tmpStr), | 418 snprintf(tmpStr, sizeof(tmpStr), |
422 usercolor, | 422 usercolor, |
423 currWin != NULL ? currWin->num + 1 : 0, | 423 currWin != NULL ? currWin->num + 1 : 0, |
424 (currWin != NULL && currWin->id != NULL) ? currWin->id : "MAIN", | 424 (currWin != NULL && currWin->id != NULL) ? currWin->id : "MAIN", |
425 currWin != NULL ? currWin->pos : 0); | 425 currWin != NULL ? currWin->pos : 0); |
426 #endif | 426 #endif |
427 | 427 |
428 wmove(stdscr, scrHeight - 4, 0); | 428 wmove(stdscr, scrHeight - 4, 0); |
429 wbkgdset(stdscr, COLOR_PAIR(10)); | 429 wbkgdset(stdscr, COLOR_PAIR(10)); |
430 wclrtoeol(stdscr); | 430 wclrtoeol(stdscr); |
431 nnwin_print_str(stdscr, tmpStr, TRUE); | 431 nnwin_print_str(stdscr, tmpStr, TRUE); |
432 | 432 |
436 { | 436 { |
437 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); | 437 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); |
438 waddstr(stdscr, tmpStr); | 438 waddstr(stdscr, tmpStr); |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 // Restore cursor position | 442 // Restore cursor position |
443 wmove(stdscr, sy, sx); | 443 wmove(stdscr, sy, sx); |
444 } | 444 } |
445 | 445 |
446 // Update editbuf if needed | 446 // Update editbuf if needed |
480 | 480 |
481 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, | 481 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, |
482 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) | 482 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) |
483 { | 483 { |
484 int c, cnt = 0; | 484 int c, cnt = 0; |
485 | 485 |
486 // Handle several buffered keypresses at once | 486 // Handle several buffered keypresses at once |
487 do | 487 do |
488 { | 488 { |
489 c = wgetch(stdscr); | 489 c = wgetch(stdscr); |
490 | 490 |
491 /* Handle various problematic cases where terminal | 491 /* Handle various problematic cases where terminal |
492 * keycodes do not get properly translated by curses | 492 * keycodes do not get properly translated by curses |
493 */ | 493 */ |
494 if (c == 10 || c == 13) | 494 if (c == 10 || c == 13) |
495 c = KEY_ENTER; | 495 c = KEY_ENTER; |
496 else | 496 else |
681 editState->done = FALSE; | 681 editState->done = FALSE; |
682 while (!editState->isError && !appQuitFlag && !editState->done) | 682 while (!editState->isError && !appQuitFlag && !editState->done) |
683 { | 683 { |
684 nnwin_input_process(editBuf, editState, callback); | 684 nnwin_input_process(editBuf, editState, callback); |
685 update(editBuf, editState); | 685 update(editBuf, editState); |
686 } | 686 } |
687 | 687 |
688 if (allowEmpty || editBuf->len > 0) | 688 if (allowEmpty || editBuf->len > 0) |
689 res = nn_editbuf_get_string(editBuf, 0, editBuf->len); | 689 res = nn_editbuf_get_string(editBuf, 0, editBuf->len); |
690 else | 690 else |
691 res = NULL; | 691 res = NULL; |
692 | 692 |
693 nn_editbuf_free(editBuf); | 693 nn_editbuf_free(editBuf); |
694 | 694 |
695 return res; | 695 return res; |
696 } | 696 } |