annotate ui.c @ 513:ef5a2aa8382b

Refactor input handling.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2012 22:16:42 +0300
parents f71c59cbc5a7
children 436e86afa70a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
18 static void nn_line_free(void *ptr)
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
19 {
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
20 nn_line_t *line = (nn_line_t *) ptr;
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
21 if (line != NULL)
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
22 {
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
23 th_free(line->buf);
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
24 th_free(line);
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
25 }
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
26 }
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
27
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
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
e644d373afb9 Fix a memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
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
f8fc6d18bcdb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
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
f8fc6d18bcdb Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
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);
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 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
122
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return TRUE;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
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 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
128 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 int i;
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 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
132 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
133
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 if (cursesInit)
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 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
137 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
138
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 endwin();
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 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
141 }
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
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
145 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
146 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
147 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
148 }
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
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 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
152 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 int i;
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 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
156 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 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
158 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
159 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
160 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
161 }
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 return NULL;
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
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 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
168 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 int i;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 nn_window_t *res;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 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
172 return FALSE;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 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
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 for (i = 1; 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
178 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
179 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 res->num = i;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 chatWindows[i] = res;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 if (curwin)
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 currWin = res;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 return TRUE;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 return FALSE;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
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 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
192 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 int i;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 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
195
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 for (i = 1; i < SET_MAX_WINDOWS; i++)
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
197 {
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 if (chatWindows[i] == win)
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 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
201 nn_window_free(win);
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 return;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
207
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
208 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
209 {
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
210 int val = 0;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
211
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
212 while (**s >= '0' && **s <= '9')
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 val *= 10;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
215 val += (**s - '0');
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
216 (*s)++;
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 if (**s != '½')
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
219 return FALSE;
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 (val < 9)
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
222 *col = A_DIM | COLOR_PAIR(val);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
223 else if (val < 30)
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
224 *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
225
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
226 return TRUE;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
227 }
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
228
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
230 #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
231
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
232 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
233 {
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
234 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
235 {
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
236 *bufsize += TH_BUFGROW;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
237 *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
238 if (*buf == NULL)
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
239 return FALSE;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
240 }
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
241
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
242 (*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
243 (*len)++;
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 return TRUE;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
246 }
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
247
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
249 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
250 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 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
252 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
253
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 while (*s)
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 {
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
256 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
257 {
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
258 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
259 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
260 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
261 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 if (*s == '½')
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 s++;
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 QPUTCH(*s);
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 else
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 {
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
272 if (!nnwin_get_color(&s, &col))
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
273 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
274 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 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
277 {
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
278 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
279 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
280 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
281 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 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
283 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 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
285 }
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 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 return 0;
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
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
294 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
295 {
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
296 const char *s = fmt;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
297 int col = 0;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
298 while (*s)
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
299 {
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
300 if (clip && getcurx(win) >= scrWidth)
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
301 return;
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
302
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
303 if (*s == '½')
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
304 {
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
305 s++;
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 waddch(win, ((unsigned char) *s) | col);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
309 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 else
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
312 {
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
313 if (!nnwin_get_color(&s, &col))
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
314 return;
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 }
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
317 else
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 waddch(win, ((unsigned char) *s) | col);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
320 s++;
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 }
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
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
325
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
326 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
327 {
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
328 int sx, sy;
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 // Save cursor position
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
331 getyx(stdscr, sy, sx);
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 // 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
334 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
335 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
336 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
337 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
338 werase(stdscr);
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
339 force = TRUE;
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
340 }
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
341
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 // 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
343 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
344 {
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
345 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
346 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
347
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
348 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
349 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
350 nn_line_t *line = buf->data[offs];
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
351 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
352 {
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
353 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
354 size_t pos;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
355
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
356 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
357 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
358 y -= 1;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
359
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
360 if (y < 0)
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
361 {
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
362 size_t r;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
363 int x;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
364 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
365 {
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
366 if (++x >= scrWidth)
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
367 {
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
368 x = 0;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
369 r++;
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 }
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
372 y = 0;
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
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
375 wmove(stdscr, y, 0);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
376
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 503
diff changeset
377 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
378 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
379 }
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
380 }
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
381
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
382 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
383 }
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
385 // Update statusline
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
386 {
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
387 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
388 int i;
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 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
391
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
392 #if 0
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
393 snprintf(tmpStr, sizeof(tmpStr),
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
394 " ½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
395 tmpStamp,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
396 username,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
397 usercolor,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
398 currWin->num + 1,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
399 currWin->id != NULL ? currWin->id : "MAIN",
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
400 currWin->pos);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
401 #else
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
402 snprintf(tmpStr, sizeof(tmpStr),
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
403 " %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
404 tmpStamp,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
405 username,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
406 usercolor,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
407 currWin->num + 1,
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
408 currWin->id != NULL ? currWin->id : "MAIN",
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
409 currWin->pos);
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
410 #endif
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
411
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
412 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
413 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
414 wclrtoeol(stdscr);
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
415 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
416
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
417 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
418 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
419 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
420 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
421 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
422 waddstr(stdscr, tmpStr);
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 }
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
425 }
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
426
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
427 // Restore cursor position
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
428 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
429
503
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
430 // Update editbuf if needed
bac3f9af112c More work on curses cleanup. Almost working now.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
431 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
432 {
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
433 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
434 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
435
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
436 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
437 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
438 wbkgdset(stdscr, COLOR_PAIR(0));
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
439
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
440 ebuf->dirty = FALSE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
441 if (mask)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
442 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
443 size_t i;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
444 for (i = 0; i < ebuf->len; i++)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
445 waddch(stdscr, '*');
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
446 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
447 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
448 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
449 char *tmp;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
450 ebuf->data[ebuf->len] = 0;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
451 tmp = nn_username_decode(th_strdup(ebuf->data));
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
452 waddnstr(stdscr, tmp, ebuf->len);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
453 th_free(tmp);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
454 }
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
455 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
456
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
457 }
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
458
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 496
diff changeset
459 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
460 }
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
461
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
462
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
463 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState,
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
464 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
465 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
466 int c, cnt = 0;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
467
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
468 // Handle several buffered keypresses at once
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
469 do
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
470 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
471 c = wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
472
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
473 /* Handle various problematic cases where terminal
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
474 * keycodes do not get properly translated by curses
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
475 */
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
476 if (c == 10 || c == 13)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
477 c = KEY_ENTER;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
478 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
479 if (c == 0x1b)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
480 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
481 // ^[O
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
482 c = wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
483 if (c == 'O')
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
484 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
485 c = wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
486 switch (c)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
487 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
488 case 'd':
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
489 c = 0x204;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
490 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
491 case 'c':
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
492 c = 0x206;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
493 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
494 default:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
495 editState->debugMsg("Unhandled ESC-O key sequence 0x%02x\n", c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
496 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
497 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
498 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
499 // ^[[
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
500 else if (c == '[')
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
501 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
502 c = wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
503 switch (c)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
504 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
505 case 0x31:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
506 c = wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
507 if (c >= 0x31 && c <= 0x39)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
508 c = KEY_F(c - 0x30);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
509 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
510 c = ERR;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
511 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
512
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
513 case 0x32:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
514 c = KEY_IC;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
515 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
516 case 0x33:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
517 c = KEY_DC;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
518 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
519
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
520 case 0x35:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
521 c = KEY_PPAGE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
522 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
523 case 0x36:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
524 c = KEY_NPAGE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
525 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
526
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
527 case 0x37:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
528 c = KEY_HOME;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
529 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
530 case 0x38:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
531 c = KEY_END;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
532 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
533
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
534 default:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
535 editState->debugMsg("Unhandled ESC-[*~ key sequence 0x%02x\n", c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
536 c = ERR;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
537 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
538 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
539 // Get the trailing ~
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
540 if (c != ERR)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
541 wgetch(stdscr);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
542 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
543 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
544 if (c >= 0x31 && c <= 0x39)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
545 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
546 c = c - 0x30 + 0x5000;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
547 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
548 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
549 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
550 editState->debugMsg("Unhandled ESC key sequence 0x%02x\n", c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
551 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
552 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
553 #if defined(__WIN32) && defined(PDCURSES)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
554 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
555 if (c >= 0x198 && c <= 0x1a0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
556 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
557 c = c - 0x198 + 0x5000;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
558 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
559 #endif
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
560
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
561 switch (c)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
562 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
563 #ifdef KEY_RESIZE
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
564 case KEY_RESIZE:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
565 resize_term(0, 0);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
566 erase();
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
567 timeout(SET_DELAY);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
568 nnwin_reset();
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
569 editState->update = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
570 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
571 #endif
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
572
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
573 case 0x204: // ctrl+left arrow = Skip words left
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
574 case 0x20b:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
575 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1]))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
576 editBuf->pos--;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
577 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1]))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
578 editBuf->pos--;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
579 editBuf->dirty = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
580 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
581
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
582 case 0x206: // ctrl+right arrow = Skip words right
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
583 case 0x210:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
584 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos]))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
585 editBuf->pos++;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
586 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos]))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
587 editBuf->pos++;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
588 editBuf->dirty = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
589 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
590
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
591 case KEY_HOME:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
592 nn_editbuf_setpos(editBuf, 0);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
593 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
594 case KEY_END:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
595 nn_editbuf_setpos(editBuf, editBuf->len);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
596 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
597 case KEY_LEFT:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
598 nn_editbuf_setpos(editBuf, editBuf->pos - 1);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
599 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
600 case KEY_RIGHT:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
601 nn_editbuf_setpos(editBuf, editBuf->pos + 1);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
602 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
603
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
604 case KEY_BACKSPACE:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
605 case 0x08:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
606 case 0x7f:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
607 nn_editbuf_delete(editBuf, editBuf->pos - 1);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
608 nn_editbuf_setpos(editBuf, editBuf->pos - 1);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
609 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
610
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
611 case KEY_DC: // Delete character
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
612 nn_editbuf_delete(editBuf, editBuf->pos);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
613 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
614
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
615 case KEY_IC: // Ins = Toggle insert / overwrite mode
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
616 editState->insertMode = !editState->insertMode;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
617 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
618
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
619 case KEY_F(2): // F2 = Clear editbuffer
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
620 nn_editbuf_clear(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
621 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
622
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
623 case 0x0c: // Ctrl + L
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
624 editState->update = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
625 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
626
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
627 case ERR:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
628 // Ignore
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
629 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
630
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
631 default:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
632 if (!callback(c, editBuf, editState))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
633 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
634 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
635 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
636 if (editState->insertMode)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
637 nn_editbuf_insert(editBuf, editBuf->pos, c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
638 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
639 nn_editbuf_write(editBuf, editBuf->pos, c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
640 nn_editbuf_setpos(editBuf, editBuf->pos + 1);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
641 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
642 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
643 editState->debugMsg("Unhandled key: 0x%02x\n", c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
644 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
645 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
646 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
647 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
648 while (c != ERR && ++cnt < 10);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
649 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
650
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
651
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
652
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
653 char *nnwin_prompt_requester(BOOL allowEmpty, nn_editstate_t *editState,
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
654 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *),
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
655 void (*update)(nn_editbuf_t *, nn_editstate_t *))
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
656 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
657 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
658 char *res;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
659
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
660 editState->done = FALSE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
661 while (!editState->isError && !editState->exitProg && !editState->done)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
662 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
663 nnwin_input_process(editBuf, editState, callback);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
664 update(editBuf, editState);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
665 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
666
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
667 if (allowEmpty || editBuf->len > 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
668 res = nn_editbuf_get_string(editBuf, 0, editBuf->len);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
669 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
670 res = NULL;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
671
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
672 nn_editbuf_free(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
673
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
674 return res;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
675 }