Mercurial > hg > nnchat
annotate ui.c @ 541:44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
separately. A log file directory can be set in configuration. Room log files
are always of format room_%d.ext. Log file extension can be set, default is
".log".
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 11 Nov 2012 18:32:42 +0200 |
parents | 658c188101a6 |
children | afb4caf32bdf |
rev | line source |
---|---|
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Written by Matti 'ccr' Hämäläinen |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 */ |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 #include "util.h" |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "ui.h" |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
9 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 nn_window_t *chatWindows[SET_MAX_WINDOWS], |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 *currWin = NULL; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 BOOL cursesInit = FALSE; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
14 int cursorVisible = ERR, |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
15 scrWidth, scrHeight; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
507 | 18 static void nn_line_free(void *ptr) |
19 { | |
20 nn_line_t *line = (nn_line_t *) ptr; | |
21 if (line != NULL) | |
22 { | |
23 th_free(line->buf); | |
24 th_free(line); | |
25 } | |
26 } | |
27 | |
28 | |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 static nn_window_t *nn_window_new(const char *id) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 nn_window_t *res = th_calloc(1, sizeof(nn_window_t)); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 if (res == NULL) return NULL; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 |
507 | 35 res->data = th_ringbuf_new(NN_BACKBUF_LEN, nn_line_free); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 if (res->data == NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 th_free(res); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 return NULL; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 res->id = th_strdup(id); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 return res; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 static void nn_window_free(nn_window_t *win) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 if (win != NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 th_ringbuf_free(win->data); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 th_free(win->id); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 th_free(win); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 nn_window_t *nnwin_main_window() |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 return chatWindows[0]; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 nn_window_t *nnwin_get(const int index) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 if (index >= 1 && index <= SET_MAX_WINDOWS) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 return chatWindows[index - 1]; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 else |
495 | 70 return NULL; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
74 BOOL nnwin_init(int delay) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
76 // Sanity check the terminal size |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
77 if (LINES < 0 || LINES > 1000) LINES = 24; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
78 if (COLS < 0 || COLS > 1000) COLS = 80; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
80 // Initialize (n)curses library and terminal settings |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 initscr(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 raw(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 keypad(stdscr, TRUE); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 noecho(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 meta(stdscr, TRUE); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 timeout(delay); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
87 scrollok(stdscr, FALSE); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
88 cursorVisible = curs_set(1); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
89 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 if (has_colors()) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 start_color(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 init_pair( 1, COLOR_RED, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 init_pair( 2, COLOR_GREEN, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 init_pair( 3, COLOR_YELLOW, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 init_pair( 4, COLOR_BLUE, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 init_pair( 5, COLOR_MAGENTA, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 init_pair( 6, COLOR_CYAN, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 init_pair( 7, COLOR_WHITE, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
101 init_pair( 8, COLOR_BLACK, COLOR_BLACK); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
102 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 init_pair(10, COLOR_BLACK, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 init_pair(11, COLOR_WHITE, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 init_pair(12, COLOR_GREEN, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 init_pair(13, COLOR_YELLOW, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 init_pair(14, COLOR_BLUE, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 init_pair(15, COLOR_MAGENTA, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 init_pair(16, COLOR_CYAN, COLOR_RED); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
110 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 cursesInit = TRUE; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
113 nnwin_reset(); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
115 #ifdef PDCURSES |
495 | 116 PDC_set_title("NNChat v" NN_VERSION); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 #endif |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
118 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 memset(chatWindows, 0, sizeof(chatWindows)); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 chatWindows[0] = nn_window_new(NULL); |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
121 nn_log_open(chatWindows[0]); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 currWin = chatWindows[0]; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 return TRUE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 void nnwin_shutdown() |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 for (i = 0; i < SET_MAX_WINDOWS; i++) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 nn_window_free(chatWindows[i]); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 if (cursesInit) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 if (cursorVisible != ERR) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 curs_set(cursorVisible); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 endwin(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 THMSG(1, "NCurses deinitialized.\n"); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
146 void nnwin_reset(void) |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
147 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
148 getmaxyx(stdscr, scrHeight, scrWidth); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
149 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
150 |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
151 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
152 nn_window_t *nnwin_find(const char *id) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 for (i = 0; i < SET_MAX_WINDOWS; i++) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 if (chatWindows[i] != NULL && |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 chatWindows[i]->id != NULL && |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 th_strcasecmp(id, chatWindows[i]->id) == 0) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 return chatWindows[i]; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 return NULL; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 BOOL nnwin_open(const char *name, BOOL curwin) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 { |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
170 nn_window_t *res; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 int i; |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
172 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 if (name == NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 return FALSE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 if ((res = nn_window_new(name)) == NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 return FALSE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
179 nn_log_open(res); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
180 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 for (i = 1; i < SET_MAX_WINDOWS; i++) |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
182 if (chatWindows[i] == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
183 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
184 res->num = i; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
185 chatWindows[i] = res; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
186 if (curwin) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
187 currWin = res; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
188 return TRUE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
189 } |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 return FALSE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 void nnwin_close(nn_window_t *win) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 if (win == NULL) return; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 for (i = 1; i < SET_MAX_WINDOWS; i++) |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
201 if (chatWindows[i] == win) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
202 { |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
203 chatWindows[i] = NULL; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
204 nn_log_close(win); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
205 nn_window_free(win); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
206 return; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
210 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
211 static BOOL nnwin_get_color(char const **s, int *col) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
212 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
213 int val = 0; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
214 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
215 while (**s >= '0' && **s <= '9') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
216 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
217 val *= 10; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
218 val += (**s - '0'); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
219 (*s)++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
220 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
221 if (**s != '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
222 return FALSE; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
223 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
224 if (val < 9) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
225 *col = A_DIM | COLOR_PAIR(val); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
226 else if (val < 30) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
227 *col = A_BOLD | COLOR_PAIR(val - 9); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
228 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
229 return TRUE; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
230 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
231 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
233 #define QPUTCH(ch) nnwin_putch(&(win->line->buf), &(win->line->bufsize), &(win->line->len), col, ch) |
508
f71c59cbc5a7
Remove useless check from nnwin_putch().
Matti Hamalainen <ccr@tnsp.org>
parents:
507
diff
changeset
|
234 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
235 static BOOL nnwin_putch(int **buf, size_t *bufsize, size_t *len, int color, char ch) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
236 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
237 if (*buf == NULL || *len + 1 >= *bufsize) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
238 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
239 *bufsize += TH_BUFGROW; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
240 *buf = (int *) th_realloc(*buf, *bufsize * sizeof(int)); |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
241 if (*buf == NULL) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
242 return FALSE; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
243 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
244 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
245 (*buf)[*len] = ((unsigned char) ch) | color; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
246 (*len)++; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
247 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
248 return TRUE; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
249 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
250 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
252 int nnwin_print(nn_window_t *win, const char *fmt) |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 const char *s = fmt; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 int col = 0; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
256 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
257 while (*s) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
258 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
259 if (win->line == NULL) |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
261 win->line = th_calloc(1, sizeof(nn_line_t)); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
262 if (win->line == NULL) |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
263 return -15; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 if (*s == '½') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
268 s++; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 if (*s == '½') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 QPUTCH(*s); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 else |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
275 if (!nnwin_get_color(&s, &col)) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
276 return -1; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
279 else if (*s == '\n') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
280 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
281 th_ringbuf_add(win->data, win->line); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
282 win->line = NULL; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 win->dirty = TRUE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
284 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
285 else if (*s != '\r') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
286 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
287 QPUTCH((unsigned char) *s == 255 ? ' ' : *s); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
288 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
290 s++; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
292 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 return 0; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
296 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
297 static void nnwin_print_str(WINDOW *win, const char *fmt, BOOL clip) |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
299 const char *s = fmt; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
300 int col = 0; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
301 while (*s) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
302 { |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
303 if (clip && getcurx(win) >= scrWidth) |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
304 return; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
305 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
306 if (*s == '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
307 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
308 s++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
309 if (*s == '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
310 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
311 waddch(win, ((unsigned char) *s) | col); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
312 s++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
313 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
314 else |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
315 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
316 if (!nnwin_get_color(&s, &col)) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
317 return; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
318 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
319 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
320 else |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
321 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
322 waddch(win, ((unsigned char) *s) | col); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
323 s++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
324 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
325 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
326 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
327 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
328 |
513 | 329 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *username, int usercolor) |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
330 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
331 int sx, sy; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
332 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
333 // Save cursor position |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
334 getyx(stdscr, sy, sx); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
335 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
336 // Clear screen if forced or main or editbuf are dirty |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
337 if (force || (currWin != NULL && currWin->dirty) || (ebuf != NULL && ebuf->dirty)) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
338 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
339 wattrset(stdscr, A_NORMAL); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
340 wbkgdset(stdscr, COLOR_PAIR(0)); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
341 werase(stdscr); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
342 force = TRUE; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
343 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
344 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 // Check if update is forced or if the window is dirty |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
346 if (currWin != NULL && (force || currWin->dirty)) |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
347 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
348 int y, offs; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
349 qringbuf_t *buf = currWin->data; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
351 for (y = scrHeight - 4, offs = buf->size - 1 - currWin->pos; offs >= 0 && y > 0; offs--) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
352 { |
540
658c188101a6
Silence a warning by typecasting to correct type from void.
Matti Hamalainen <ccr@tnsp.org>
parents:
535
diff
changeset
|
353 nn_line_t *line = (nn_line_t *) buf->data[offs]; |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
354 if (line != NULL) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
355 { |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
356 const int *s = line->buf; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
357 size_t pos; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
358 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
359 y -= (line->len / scrWidth); |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
360 if (line->len % scrWidth != 0) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
361 y -= 1; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
362 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
363 if (y < 0) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
364 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
365 size_t r; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
366 int x; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
367 for (r = -y, x = 0, pos = 0; r && pos < line->len; pos++) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
368 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
369 if (++x >= scrWidth) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
370 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
371 x = 0; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
372 r++; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
373 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
374 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
375 y = 0; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
376 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
377 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
378 wmove(stdscr, y, 0); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
379 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
380 for (pos = 0; pos < line->len; pos++) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
381 waddch(stdscr, s[pos]); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
382 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
383 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
384 |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
385 currWin->dirty = FALSE; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
387 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
388 // Update statusline |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
389 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
390 char tmpStamp[32], tmpStr[128]; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
391 int i; |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
392 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
393 str_get_timestamp(tmpStamp, sizeof(tmpStamp), "%H:%M:%S"); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
394 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
395 #if 0 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
396 snprintf(tmpStr, sizeof(tmpStr), |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
397 " ½10½%s½13½ | ½16½%s½13½ | ½11½#%06x½13½ | WIN: %d: %s / %d | ½11½", |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
398 tmpStamp, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
399 username, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
400 usercolor, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
401 currWin->num + 1, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
402 currWin->id != NULL ? currWin->id : "MAIN", |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
403 currWin->pos); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
404 #else |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
405 snprintf(tmpStr, sizeof(tmpStr), |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
406 " %s | %s | #%06x | WIN: %d: %s / %d | ", |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
407 tmpStamp, |
527
436e86afa70a
If username has not yet been set, show - instead of (null).
Matti Hamalainen <ccr@tnsp.org>
parents:
513
diff
changeset
|
408 username != NULL ? username : "-", |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
409 usercolor, |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
410 currWin != NULL ? currWin->num + 1 : 0, |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
411 (currWin != NULL && currWin->id != NULL) ? currWin->id : "MAIN", |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
412 currWin != NULL ? currWin->pos : 0); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
413 #endif |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
414 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
415 wmove(stdscr, scrHeight - 4, 0); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
416 wbkgdset(stdscr, COLOR_PAIR(10)); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
417 wclrtoeol(stdscr); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
418 nnwin_print_str(stdscr, tmpStr, TRUE); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
419 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
420 for (i = 0; i < SET_MAX_WINDOWS; i++) |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
421 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
422 if (chatWindows[i] != NULL && chatWindows[i]->dirty) |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
423 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
424 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
425 waddstr(stdscr, tmpStr); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
426 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
427 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
428 } |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
429 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
430 // Restore cursor position |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
431 wmove(stdscr, sy, sx); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
432 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
433 // Update editbuf if needed |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
434 if (cursesInit && ebuf != NULL && (force || ebuf->dirty)) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
435 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
436 int yoffs = ebuf->pos / scrWidth, |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
437 xoffs = ebuf->pos % scrWidth; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
438 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
439 wmove(stdscr, scrHeight - 3, 0); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
440 wattrset(stdscr, A_NORMAL); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
441 wbkgdset(stdscr, COLOR_PAIR(0)); |
513 | 442 |
443 ebuf->dirty = FALSE; | |
444 if (mask) | |
445 { | |
446 size_t i; | |
447 for (i = 0; i < ebuf->len; i++) | |
448 waddch(stdscr, '*'); | |
449 } | |
450 else | |
451 { | |
452 char *tmp; | |
453 ebuf->data[ebuf->len] = 0; | |
454 tmp = nn_username_decode(th_strdup(ebuf->data)); | |
455 waddnstr(stdscr, tmp, ebuf->len); | |
456 th_free(tmp); | |
457 } | |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
458 wmove(stdscr, scrHeight - 3 + yoffs, xoffs); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
459 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
460 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
461 |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
462 wrefresh(stdscr); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
463 } |
513 | 464 |
465 | |
466 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, | |
467 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) | |
468 { | |
469 int c, cnt = 0; | |
470 | |
471 // Handle several buffered keypresses at once | |
472 do | |
473 { | |
474 c = wgetch(stdscr); | |
475 | |
476 /* Handle various problematic cases where terminal | |
477 * keycodes do not get properly translated by curses | |
478 */ | |
479 if (c == 10 || c == 13) | |
480 c = KEY_ENTER; | |
481 else | |
482 if (c == 0x1b) | |
483 { | |
484 // ^[O | |
485 c = wgetch(stdscr); | |
486 if (c == 'O') | |
487 { | |
488 c = wgetch(stdscr); | |
489 switch (c) | |
490 { | |
491 case 'd': | |
492 c = 0x204; | |
493 break; | |
494 case 'c': | |
495 c = 0x206; | |
496 break; | |
497 default: | |
498 editState->debugMsg("Unhandled ESC-O key sequence 0x%02x\n", c); | |
499 break; | |
500 } | |
501 } | |
502 // ^[[ | |
503 else if (c == '[') | |
504 { | |
505 c = wgetch(stdscr); | |
506 switch (c) | |
507 { | |
508 case 0x31: | |
509 c = wgetch(stdscr); | |
510 if (c >= 0x31 && c <= 0x39) | |
511 c = KEY_F(c - 0x30); | |
512 else | |
513 c = ERR; | |
514 break; | |
515 | |
516 case 0x32: | |
517 c = KEY_IC; | |
518 break; | |
519 case 0x33: | |
520 c = KEY_DC; | |
521 break; | |
522 | |
523 case 0x35: | |
524 c = KEY_PPAGE; | |
525 break; | |
526 case 0x36: | |
527 c = KEY_NPAGE; | |
528 break; | |
529 | |
530 case 0x37: | |
531 c = KEY_HOME; | |
532 break; | |
533 case 0x38: | |
534 c = KEY_END; | |
535 break; | |
536 | |
537 default: | |
538 editState->debugMsg("Unhandled ESC-[*~ key sequence 0x%02x\n", c); | |
539 c = ERR; | |
540 break; | |
541 } | |
542 // Get the trailing ~ | |
543 if (c != ERR) | |
544 wgetch(stdscr); | |
545 } | |
546 else | |
547 if (c >= 0x31 && c <= 0x39) | |
548 { | |
549 c = c - 0x30 + 0x5000; | |
550 } | |
551 else | |
552 { | |
553 editState->debugMsg("Unhandled ESC key sequence 0x%02x\n", c); | |
554 } | |
555 } | |
556 #if defined(__WIN32) && defined(PDCURSES) | |
557 else | |
558 if (c >= 0x198 && c <= 0x1a0) | |
559 { | |
560 c = c - 0x198 + 0x5000; | |
561 } | |
562 #endif | |
563 | |
564 switch (c) | |
565 { | |
566 #ifdef KEY_RESIZE | |
567 case KEY_RESIZE: | |
568 resize_term(0, 0); | |
569 erase(); | |
570 timeout(SET_DELAY); | |
571 nnwin_reset(); | |
572 editState->update = TRUE; | |
573 break; | |
574 #endif | |
575 | |
576 case 0x204: // ctrl+left arrow = Skip words left | |
577 case 0x20b: | |
578 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1])) | |
579 editBuf->pos--; | |
580 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1])) | |
581 editBuf->pos--; | |
582 editBuf->dirty = TRUE; | |
583 break; | |
584 | |
585 case 0x206: // ctrl+right arrow = Skip words right | |
586 case 0x210: | |
587 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos])) | |
588 editBuf->pos++; | |
589 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos])) | |
590 editBuf->pos++; | |
591 editBuf->dirty = TRUE; | |
592 break; | |
593 | |
594 case KEY_HOME: | |
595 nn_editbuf_setpos(editBuf, 0); | |
596 break; | |
597 case KEY_END: | |
598 nn_editbuf_setpos(editBuf, editBuf->len); | |
599 break; | |
600 case KEY_LEFT: | |
601 nn_editbuf_setpos(editBuf, editBuf->pos - 1); | |
602 break; | |
603 case KEY_RIGHT: | |
604 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
605 break; | |
606 | |
607 case KEY_BACKSPACE: | |
608 case 0x08: | |
609 case 0x7f: | |
610 nn_editbuf_delete(editBuf, editBuf->pos - 1); | |
611 nn_editbuf_setpos(editBuf, editBuf->pos - 1); | |
612 break; | |
613 | |
614 case KEY_DC: // Delete character | |
615 nn_editbuf_delete(editBuf, editBuf->pos); | |
616 break; | |
617 | |
618 case KEY_IC: // Ins = Toggle insert / overwrite mode | |
619 editState->insertMode = !editState->insertMode; | |
620 break; | |
621 | |
622 case KEY_F(2): // F2 = Clear editbuffer | |
623 nn_editbuf_clear(editBuf); | |
624 break; | |
625 | |
626 case 0x0c: // Ctrl + L | |
627 editState->update = TRUE; | |
628 break; | |
629 | |
630 case ERR: | |
631 // Ignore | |
632 break; | |
633 | |
634 default: | |
635 if (!callback(c, editBuf, editState)) | |
636 { | |
637 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) | |
638 { | |
639 if (editState->insertMode) | |
640 nn_editbuf_insert(editBuf, editBuf->pos, c); | |
641 else | |
642 nn_editbuf_write(editBuf, editBuf->pos, c); | |
643 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
644 } | |
645 else | |
646 editState->debugMsg("Unhandled key: 0x%02x\n", c); | |
647 } | |
648 break; | |
649 } | |
650 } | |
651 while (c != ERR && ++cnt < 10); | |
652 } | |
653 | |
654 | |
655 | |
656 char *nnwin_prompt_requester(BOOL allowEmpty, nn_editstate_t *editState, | |
657 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *), | |
658 void (*update)(nn_editbuf_t *, nn_editstate_t *)) | |
659 { | |
660 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); | |
661 char *res; | |
662 | |
663 editState->done = FALSE; | |
664 while (!editState->isError && !editState->exitProg && !editState->done) | |
665 { | |
666 nnwin_input_process(editBuf, editState, callback); | |
667 update(editBuf, editState); | |
668 } | |
669 | |
670 if (allowEmpty || editBuf->len > 0) | |
671 res = nn_editbuf_get_string(editBuf, 0, editBuf->len); | |
672 else | |
673 res = NULL; | |
674 | |
675 nn_editbuf_free(editBuf); | |
676 | |
677 return res; | |
678 } |