Mercurial > hg > nnchat
annotate ui.c @ 707:11eb7c30889e
Adjust to fit new th_ioctx API.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2020 17:01:22 +0200 |
parents | f3b119599b3a |
children | ff1af7410bba |
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 |
668 | 4 * (C) Copyright 2008-2016 Tecnic Software productions (TNSP) |
466
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 |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
13 BOOL appCursesInit = FALSE, appQuitFlag = 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 { |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
31 nn_window_t *win; |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
33 if ((win = th_malloc0(sizeof(nn_window_t))) == NULL) |
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
34 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
|
35 |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
36 win->data = th_ringbuf_new(SET_BACKBUF_LEN, nn_line_free); |
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
37 if (win->data == NULL) |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 { |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
39 th_free(win); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 return NULL; |
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 |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
43 win->id = th_strdup(id); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
701
f3b119599b3a
Slight code cleanup on aisle nn_window_new().
Matti Hamalainen <ccr@tnsp.org>
parents:
700
diff
changeset
|
45 return win; |
466
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 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
|
50 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 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
|
52 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 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
|
54 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
|
55 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
|
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 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
|
61 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 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
|
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 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
|
67 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 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
|
69 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
|
70 else |
495 | 71 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
|
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
75 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
|
76 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
77 // 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
|
78 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
|
79 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
|
80 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
81 // 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
|
82 initscr(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 raw(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 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
|
85 noecho(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 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
|
87 timeout(delay); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
88 scrollok(stdscr, FALSE); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
89 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
|
90 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 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
|
92 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
93 start_color(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
94 |
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( 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 |
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(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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
113 appCursesInit = TRUE; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
114 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
|
115 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 #ifdef PDCURSES |
495 | 117 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
|
118 #endif |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 currWin = chatWindows[0]; |
700 | 124 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 return TRUE; |
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 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
|
130 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 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
|
134 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
|
135 |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
136 if (appCursesInit) |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 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
|
139 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
|
140 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 endwin(); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 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
|
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
147 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
|
148 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
149 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
|
150 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
151 |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
152 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 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
|
154 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 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
|
158 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 return NULL; |
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 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
|
170 { |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
171 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
|
172 int i; |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
173 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 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
|
175 return FALSE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 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
|
178 return FALSE; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
180 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
|
181 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 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
|
183 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
|
184 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
185 res->num = i; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
186 chatWindows[i] = res; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
187 if (curwin) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
188 currWin = res; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
189 return TRUE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
190 } |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 return FALSE; |
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 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
|
197 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 int i; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 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
|
200 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 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
|
202 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
|
203 { |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
204 chatWindows[i] = NULL; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
540
diff
changeset
|
205 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
|
206 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
|
207 return; |
466
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 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
211 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
212 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
|
213 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
214 int val = 0; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
215 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
216 while (**s >= '0' && **s <= '9') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
217 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
218 val *= 10; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
219 val += (**s - '0'); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
220 (*s)++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
221 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
222 if (**s != '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
223 return FALSE; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
224 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
225 if (val < 9) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
226 *col = A_DIM | COLOR_PAIR(val); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
227 else if (val < 30) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
228 *col = A_BOLD | COLOR_PAIR(val - 9); |
700 | 229 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
230 return TRUE; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
231 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
232 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
234 #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
|
235 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
236 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
|
237 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
238 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
|
239 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
240 *bufsize += TH_BUFGROW; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
241 *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
|
242 if (*buf == NULL) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
243 return FALSE; |
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 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
246 (*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
|
247 (*len)++; |
700 | 248 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
249 return TRUE; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
250 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
251 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
253 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
|
254 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 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
|
256 int col = 0; |
700 | 257 |
576
414d11df07ce
Gracefully handle error situations when the main UI has not yet been
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
258 if (win == NULL) |
414d11df07ce
Gracefully handle error situations when the main UI has not yet been
Matti Hamalainen <ccr@tnsp.org>
parents:
571
diff
changeset
|
259 return -16; |
700 | 260 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 while (*s) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
263 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
|
264 { |
634
5269a8cdbd96
Use th_malloc0(n) instead of th_calloc(1, n).
Matti Hamalainen <ccr@tnsp.org>
parents:
631
diff
changeset
|
265 win->line = th_malloc0(sizeof(nn_line_t)); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
266 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
|
267 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
|
268 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
269 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
270 if (*s == '½') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
271 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 s++; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 if (*s == '½') |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
274 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
275 QPUTCH(*s); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
276 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
277 else |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
278 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
279 if (!nnwin_get_color(&s, &col)) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
280 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
|
281 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 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
|
284 { |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
289 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
|
290 { |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
291 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
|
292 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 s++; |
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 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
297 return 0; |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
298 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
301 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
|
302 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
303 const char *s = fmt; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
304 int col = 0; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
305 while (*s) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
306 { |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
307 if (clip && getcurx(win) >= scrWidth) |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
308 return; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
309 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
310 if (*s == '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
311 { |
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 if (*s == '½') |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
314 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
315 waddch(win, ((unsigned char) *s) | col); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
316 s++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
317 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
318 else |
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 if (!nnwin_get_color(&s, &col)) |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
321 return; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
322 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
323 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
324 else |
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 waddch(win, ((unsigned char) *s) | col); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
327 s++; |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
328 } |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
329 } |
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 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
332 |
690
6fa9c36d0634
Adjust to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
668
diff
changeset
|
333 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, const char *username, const unsigned int usercolor) |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
334 { |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
335 int sx, sy; |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
336 BOOL changed = FALSE; |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
337 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
338 // 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
|
339 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
|
340 { |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
341 // Save cursor position |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
342 getyx(stdscr, sy, sx); |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
343 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
344 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
|
345 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
|
346 werase(stdscr); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
347 force = TRUE; |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
348 changed = TRUE; |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
349 } |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
350 else |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
351 { |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
352 // Save cursor position |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
353 getyx(stdscr, sy, sx); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
354 } |
700 | 355 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 // 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
|
357 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
|
358 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
359 int y, offs; |
659
fc19ab0334b1
Match th-libs API changes for ringbuffers.
Matti Hamalainen <ccr@tnsp.org>
parents:
634
diff
changeset
|
360 th_ringbuf_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
|
361 |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
362 changed = TRUE; |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
363 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
364 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
|
365 { |
540
658c188101a6
Silence a warning by typecasting to correct type from void.
Matti Hamalainen <ccr@tnsp.org>
parents:
535
diff
changeset
|
366 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
|
367 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
|
368 { |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
369 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
|
370 size_t pos; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
371 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
372 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
|
373 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
|
374 y -= 1; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
375 |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
376 if (y < 0) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
377 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
378 size_t r; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
379 int x; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
380 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
|
381 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
382 if (++x >= scrWidth) |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
383 { |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
384 x = 0; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
385 r++; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
386 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
387 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
388 y = 0; |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
389 } |
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
390 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
391 wmove(stdscr, y, 0); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
392 |
504
60e04709ce0f
Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents:
503
diff
changeset
|
393 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
|
394 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
|
395 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
396 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
397 |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
398 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
|
399 } |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
400 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
401 // Update statusline |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
402 if (changed || force) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
403 { |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
404 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
|
405 int i; |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
406 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
407 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
|
408 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
409 #if 0 |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
410 snprintf(tmpStr, sizeof(tmpStr), |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
411 " ½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
|
412 tmpStamp, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
413 username, |
700 | 414 usercolor, |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
415 currWin->num + 1, |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
416 currWin->id != NULL ? currWin->id : "MAIN", |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
417 currWin->pos); |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
418 #else |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
419 snprintf(tmpStr, sizeof(tmpStr), |
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
420 " %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
|
421 tmpStamp, |
527
436e86afa70a
If username has not yet been set, show - instead of (null).
Matti Hamalainen <ccr@tnsp.org>
parents:
513
diff
changeset
|
422 username != NULL ? username : "-", |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
423 usercolor, |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
424 currWin != NULL ? currWin->num + 1 : 0, |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
425 (currWin != NULL && currWin->id != NULL) ? currWin->id : "MAIN", |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
426 currWin != NULL ? currWin->pos : 0); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
427 #endif |
700 | 428 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
429 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
|
430 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
|
431 wclrtoeol(stdscr); |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
432 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
|
433 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
434 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
|
435 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
436 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
|
437 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
438 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
|
439 waddstr(stdscr, tmpStr); |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
440 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
441 } |
700 | 442 |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
443 // Restore cursor position |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
444 wmove(stdscr, sy, sx); |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
445 } |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
446 |
503
bac3f9af112c
More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
447 // Update editbuf if needed |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
448 if (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
|
449 { |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
450 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
|
451 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
|
452 |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
453 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
|
454 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
|
455 wbkgdset(stdscr, COLOR_PAIR(0)); |
513 | 456 |
457 ebuf->dirty = FALSE; | |
458 if (mask) | |
459 { | |
460 size_t i; | |
461 for (i = 0; i < ebuf->len; i++) | |
462 waddch(stdscr, '*'); | |
463 } | |
464 else | |
465 { | |
466 char *tmp; | |
467 ebuf->data[ebuf->len] = 0; | |
468 tmp = nn_username_decode(th_strdup(ebuf->data)); | |
469 waddnstr(stdscr, tmp, ebuf->len); | |
470 th_free(tmp); | |
471 } | |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
472 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
|
473 |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
474 changed = TRUE; |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
475 } |
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
496
diff
changeset
|
476 |
585
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
477 if (changed) |
199fd3371035
Improve screen update economy by only refreshing when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
478 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
|
479 } |
513 | 480 |
481 | |
482 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState, | |
483 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *)) | |
484 { | |
485 int c, cnt = 0; | |
700 | 486 |
513 | 487 // Handle several buffered keypresses at once |
488 do | |
489 { | |
490 c = wgetch(stdscr); | |
700 | 491 |
492 /* Handle various problematic cases where terminal | |
513 | 493 * keycodes do not get properly translated by curses |
494 */ | |
495 if (c == 10 || c == 13) | |
496 c = KEY_ENTER; | |
497 else | |
498 if (c == 0x1b) | |
499 { | |
500 // ^[O | |
501 c = wgetch(stdscr); | |
502 if (c == 'O') | |
503 { | |
504 c = wgetch(stdscr); | |
505 switch (c) | |
506 { | |
507 case 'd': | |
508 c = 0x204; | |
509 break; | |
510 case 'c': | |
511 c = 0x206; | |
512 break; | |
513 default: | |
514 editState->debugMsg("Unhandled ESC-O key sequence 0x%02x\n", c); | |
515 break; | |
516 } | |
517 } | |
518 // ^[[ | |
519 else if (c == '[') | |
520 { | |
521 c = wgetch(stdscr); | |
522 switch (c) | |
523 { | |
524 case 0x31: | |
525 c = wgetch(stdscr); | |
526 if (c >= 0x31 && c <= 0x39) | |
527 c = KEY_F(c - 0x30); | |
528 else | |
529 c = ERR; | |
530 break; | |
531 | |
532 case 0x32: | |
533 c = KEY_IC; | |
534 break; | |
535 case 0x33: | |
536 c = KEY_DC; | |
537 break; | |
538 | |
539 case 0x35: | |
540 c = KEY_PPAGE; | |
541 break; | |
542 case 0x36: | |
543 c = KEY_NPAGE; | |
544 break; | |
545 | |
546 case 0x37: | |
547 c = KEY_HOME; | |
548 break; | |
549 case 0x38: | |
550 c = KEY_END; | |
551 break; | |
552 | |
553 default: | |
554 editState->debugMsg("Unhandled ESC-[*~ key sequence 0x%02x\n", c); | |
555 c = ERR; | |
556 break; | |
557 } | |
558 // Get the trailing ~ | |
559 if (c != ERR) | |
560 wgetch(stdscr); | |
561 } | |
562 else | |
563 if (c >= 0x31 && c <= 0x39) | |
564 { | |
565 c = c - 0x30 + 0x5000; | |
566 } | |
567 else | |
568 { | |
569 editState->debugMsg("Unhandled ESC key sequence 0x%02x\n", c); | |
570 } | |
571 } | |
572 #if defined(__WIN32) && defined(PDCURSES) | |
573 else | |
574 if (c >= 0x198 && c <= 0x1a0) | |
575 { | |
576 c = c - 0x198 + 0x5000; | |
577 } | |
578 #endif | |
579 | |
580 switch (c) | |
581 { | |
582 #ifdef KEY_RESIZE | |
583 case KEY_RESIZE: | |
584 resize_term(0, 0); | |
585 erase(); | |
586 timeout(SET_DELAY); | |
587 nnwin_reset(); | |
588 editState->update = TRUE; | |
589 break; | |
590 #endif | |
591 | |
592 case 0x204: // ctrl+left arrow = Skip words left | |
593 case 0x20b: | |
594 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1])) | |
595 editBuf->pos--; | |
596 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1])) | |
597 editBuf->pos--; | |
598 editBuf->dirty = TRUE; | |
599 break; | |
600 | |
601 case 0x206: // ctrl+right arrow = Skip words right | |
602 case 0x210: | |
603 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos])) | |
604 editBuf->pos++; | |
605 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos])) | |
606 editBuf->pos++; | |
607 editBuf->dirty = TRUE; | |
608 break; | |
609 | |
610 case KEY_HOME: | |
611 nn_editbuf_setpos(editBuf, 0); | |
612 break; | |
613 case KEY_END: | |
614 nn_editbuf_setpos(editBuf, editBuf->len); | |
615 break; | |
616 case KEY_LEFT: | |
617 nn_editbuf_setpos(editBuf, editBuf->pos - 1); | |
618 break; | |
619 case KEY_RIGHT: | |
620 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
621 break; | |
622 | |
623 case KEY_BACKSPACE: | |
624 case 0x08: | |
625 case 0x7f: | |
568
afb4caf32bdf
Editline Backspace handling was wonky, we didn't check for edit position to be > 0. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
626 if (editBuf->pos > 0) |
afb4caf32bdf
Editline Backspace handling was wonky, we didn't check for edit position to be > 0. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
627 { |
afb4caf32bdf
Editline Backspace handling was wonky, we didn't check for edit position to be > 0. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
628 nn_editbuf_delete(editBuf, editBuf->pos - 1); |
afb4caf32bdf
Editline Backspace handling was wonky, we didn't check for edit position to be > 0. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
629 nn_editbuf_setpos(editBuf, editBuf->pos - 1); |
afb4caf32bdf
Editline Backspace handling was wonky, we didn't check for edit position to be > 0. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
630 } |
513 | 631 break; |
632 | |
633 case KEY_DC: // Delete character | |
634 nn_editbuf_delete(editBuf, editBuf->pos); | |
635 break; | |
636 | |
637 case KEY_IC: // Ins = Toggle insert / overwrite mode | |
638 editState->insertMode = !editState->insertMode; | |
639 break; | |
640 | |
641 case KEY_F(2): // F2 = Clear editbuffer | |
642 nn_editbuf_clear(editBuf); | |
643 break; | |
644 | |
645 case 0x0c: // Ctrl + L | |
646 editState->update = TRUE; | |
647 break; | |
648 | |
649 case ERR: | |
650 // Ignore | |
651 break; | |
652 | |
653 default: | |
654 if (!callback(c, editBuf, editState)) | |
655 { | |
656 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) | |
657 { | |
658 if (editState->insertMode) | |
659 nn_editbuf_insert(editBuf, editBuf->pos, c); | |
660 else | |
661 nn_editbuf_write(editBuf, editBuf->pos, c); | |
662 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
663 } | |
664 else | |
665 editState->debugMsg("Unhandled key: 0x%02x\n", c); | |
666 } | |
667 break; | |
668 } | |
669 } | |
670 while (c != ERR && ++cnt < 10); | |
671 } | |
672 | |
673 | |
674 | |
675 char *nnwin_prompt_requester(BOOL allowEmpty, nn_editstate_t *editState, | |
676 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *), | |
677 void (*update)(nn_editbuf_t *, nn_editstate_t *)) | |
678 { | |
679 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); | |
680 char *res; | |
681 | |
682 editState->done = FALSE; | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
568
diff
changeset
|
683 while (!editState->isError && !appQuitFlag && !editState->done) |
513 | 684 { |
685 nnwin_input_process(editBuf, editState, callback); | |
686 update(editBuf, editState); | |
700 | 687 } |
688 | |
513 | 689 if (allowEmpty || editBuf->len > 0) |
690 res = nn_editbuf_get_string(editBuf, 0, editBuf->len); | |
691 else | |
692 res = NULL; | |
693 | |
694 nn_editbuf_free(editBuf); | |
700 | 695 |
513 | 696 return res; |
697 } |