24
|
1 |
#include <stdio.h> |
|
2 |
#include <stdlib.h> |
|
3 |
#include <string.h> |
|
4 |
#include <ncurses.h> |
|
5 |
#include <panel.h> |
|
6 |
#include <time.h> |
|
7 |
#include <ctype.h> |
|
8 |
#include <locale.h> |
|
9 |
|
|
10 |
#include "screen.h" |
|
11 |
#include "utils.h" |
47
|
12 |
#include "commands.h" |
24
|
13 |
#include "buddies.h" |
|
14 |
#include "parsecfg.h" |
|
15 |
#include "lang.h" |
|
16 |
#include "list.h" |
47
|
17 |
#include "utf8.h" |
24
|
18 |
|
|
19 |
#define window_entry(n) list_entry(n, window_entry_t, list) |
|
20 |
|
|
21 |
LIST_HEAD(window_list); |
|
22 |
|
|
23 |
typedef struct _window_entry_t { |
|
24 |
WINDOW *win; |
|
25 |
PANEL *panel; |
|
26 |
char *name; |
|
27 |
int nlines; |
|
28 |
char **texto; |
|
29 |
int hidden_msg; |
|
30 |
struct list_head list; |
|
31 |
} window_entry_t; |
|
32 |
|
|
33 |
|
|
34 |
/* Variables globales a SCREEN.C */ |
|
35 |
static WINDOW *rosterWnd, *chatWnd, *inputWnd; |
|
36 |
static WINDOW *logWnd, *logWnd_border; |
|
37 |
static PANEL *rosterPanel, *chatPanel, *inputPanel; |
|
38 |
static PANEL *logPanel, *logPanel_border; |
|
39 |
static int maxY, maxX; |
|
40 |
static window_entry_t *currentWindow; |
|
41 |
|
|
42 |
static int chatmode; |
30
|
43 |
int update_roster; |
24
|
44 |
|
|
45 |
static char inputLine[INPUTLINE_LENGTH+1]; |
|
46 |
static char *ptr_inputline; |
|
47 |
static short int inputline_offset; |
|
48 |
|
|
49 |
|
|
50 |
/* Funciones */ |
|
51 |
|
|
52 |
int scr_WindowHeight(WINDOW * win) |
|
53 |
{ |
|
54 |
int x, y; |
|
55 |
getmaxyx(win, y, x); |
|
56 |
return x; |
|
57 |
} |
|
58 |
|
|
59 |
void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
|
60 |
int Color, chtype box, chtype border) |
|
61 |
{ |
|
62 |
int i, j; |
|
63 |
|
|
64 |
wattrset(win, COLOR_PAIR(Color)); |
|
65 |
for (i = 0; i < height; i++) { |
|
66 |
wmove(win, y + i, x); |
|
67 |
for (j = 0; j < width; j++) |
|
68 |
if (!i && !j) |
|
69 |
waddch(win, border | ACS_ULCORNER); |
|
70 |
else if (i == height - 1 && !j) |
|
71 |
waddch(win, border | ACS_LLCORNER); |
|
72 |
else if (!i && j == width - 1) |
|
73 |
waddch(win, box | ACS_URCORNER); |
|
74 |
else if (i == height - 1 && j == width - 1) |
|
75 |
waddch(win, box | ACS_LRCORNER); |
|
76 |
else if (!i) |
|
77 |
waddch(win, border | ACS_HLINE); |
|
78 |
else if (i == height - 1) |
|
79 |
waddch(win, box | ACS_HLINE); |
|
80 |
else if (!j) |
|
81 |
waddch(win, border | ACS_VLINE); |
|
82 |
else if (j == width - 1) |
|
83 |
waddch(win, box | ACS_VLINE); |
|
84 |
else |
|
85 |
waddch(win, box | ' '); |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
int FindColor(char *name) |
|
90 |
{ |
|
91 |
if (!strcmp(name, "default")) |
|
92 |
return -1; |
|
93 |
if (!strcmp(name, "black")) |
|
94 |
return COLOR_BLACK; |
|
95 |
if (!strcmp(name, "red")) |
|
96 |
return COLOR_RED; |
|
97 |
if (!strcmp(name, "green")) |
|
98 |
return COLOR_GREEN; |
|
99 |
if (!strcmp(name, "yellow")) |
|
100 |
return COLOR_YELLOW; |
|
101 |
if (!strcmp(name, "blue")) |
|
102 |
return COLOR_BLUE; |
|
103 |
if (!strcmp(name, "magenta")) |
|
104 |
return COLOR_MAGENTA; |
|
105 |
if (!strcmp(name, "cyan")) |
|
106 |
return COLOR_CYAN; |
|
107 |
if (!strcmp(name, "white")) |
|
108 |
return COLOR_WHITE; |
|
109 |
|
|
110 |
return -1; |
|
111 |
} |
|
112 |
|
|
113 |
void ParseColors(void) |
|
114 |
{ |
|
115 |
char *colors[11] = { |
|
116 |
"", "", |
|
117 |
"borderlines", |
|
118 |
"jidonlineselected", |
|
119 |
"jidonline", |
|
120 |
"jidofflineselected", |
|
121 |
"jidoffline", |
|
122 |
"text", |
|
123 |
NULL |
|
124 |
}; |
|
125 |
|
|
126 |
char *tmp = malloc(1024); |
|
127 |
char *color1; |
|
128 |
char *background = cfg_read("color_background"); |
|
129 |
char *backselected = cfg_read("color_backselected"); |
|
130 |
int i = 0; |
|
131 |
|
|
132 |
while (colors[i]) { |
|
133 |
sprintf(tmp, "color_%s", colors[i]); |
|
134 |
color1 = cfg_read(tmp); |
|
135 |
|
|
136 |
switch (i + 1) { |
|
137 |
case 1: |
|
138 |
init_pair(1, COLOR_BLACK, COLOR_WHITE); |
|
139 |
break; |
|
140 |
case 2: |
|
141 |
init_pair(2, COLOR_WHITE, COLOR_BLACK); |
|
142 |
break; |
|
143 |
case 3: |
|
144 |
init_pair(3, FindColor(color1), FindColor(background)); |
|
145 |
break; |
|
146 |
case 4: |
|
147 |
init_pair(4, FindColor(color1), FindColor(backselected)); |
|
148 |
break; |
|
149 |
case 5: |
|
150 |
init_pair(5, FindColor(color1), FindColor(background)); |
|
151 |
break; |
|
152 |
case 6: |
|
153 |
init_pair(6, FindColor(color1), FindColor(backselected)); |
|
154 |
break; |
|
155 |
case 7: |
|
156 |
init_pair(7, FindColor(color1), FindColor(background)); |
|
157 |
break; |
|
158 |
case 8: |
|
159 |
init_pair(8, FindColor(color1), FindColor(background)); |
|
160 |
break; |
|
161 |
} |
|
162 |
i++; |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
|
50
|
167 |
window_entry_t *scr_CreatePanel(const char *title, int x, int y, |
|
168 |
int lines, int cols, int dont_show) |
24
|
169 |
{ |
|
170 |
window_entry_t *tmp = calloc(1, sizeof(window_entry_t)); |
|
171 |
|
|
172 |
tmp->win = newwin(lines, cols, y, x); |
|
173 |
tmp->panel = new_panel(tmp->win); |
|
174 |
tmp->name = (char *) calloc(1, 1024); |
|
175 |
strncpy(tmp->name, title, 1024); |
|
176 |
|
|
177 |
scr_draw_box(tmp->win, 0, 0, lines, cols, COLOR_GENERAL, 0, 0); |
|
178 |
//mvwprintw(tmp->win, 0, (cols - (2 + strlen(title))) / 2, " %s ", title); |
|
179 |
if ((!dont_show)) { |
|
180 |
currentWindow = tmp; |
|
181 |
} else { |
|
182 |
if (currentWindow) |
|
183 |
top_panel(currentWindow->panel); |
|
184 |
else |
|
185 |
top_panel(chatPanel); |
|
186 |
} |
|
187 |
|
|
188 |
list_add_tail(&tmp->list, &window_list); |
|
189 |
update_panels(); |
|
190 |
|
|
191 |
return tmp; |
|
192 |
} |
|
193 |
|
|
194 |
void scr_RoolWindow(void) |
|
195 |
{ |
|
196 |
} |
|
197 |
|
50
|
198 |
window_entry_t *scr_SearchWindow(const char *winId) |
24
|
199 |
{ |
|
200 |
struct list_head *pos, *n; |
|
201 |
window_entry_t *search_entry = NULL; |
|
202 |
|
|
203 |
list_for_each_safe(pos, n, &window_list) { |
|
204 |
search_entry = window_entry(pos); |
|
205 |
if (search_entry->name) { |
|
206 |
if (!strcasecmp(search_entry->name, winId)) { |
|
207 |
return search_entry; |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
211 |
return NULL; |
|
212 |
} |
|
213 |
|
50
|
214 |
void scr_ShowWindow(const char *winId) |
24
|
215 |
{ |
|
216 |
int n, width, i; |
|
217 |
window_entry_t *tmp = scr_SearchWindow(winId); |
|
218 |
if (tmp != NULL) { |
|
219 |
top_panel(tmp->panel); |
|
220 |
currentWindow = tmp; |
|
221 |
chatmode = TRUE; |
|
222 |
tmp->hidden_msg = FALSE; |
30
|
223 |
update_roster = TRUE; |
24
|
224 |
width = scr_WindowHeight(tmp->win); |
|
225 |
for (n = 0; n < tmp->nlines; n++) { |
|
226 |
mvwprintw(tmp->win, n + 1, 1, ""); |
|
227 |
for (i = 0; i < width - 2; i++) |
|
228 |
waddch(tmp->win, ' '); |
|
229 |
mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
230 |
} |
|
231 |
//move(CHAT_WIN_HEIGHT - 1, maxX - 1); |
|
232 |
update_panels(); |
|
233 |
doupdate(); |
|
234 |
} else { |
|
235 |
top_panel(chatPanel); |
|
236 |
currentWindow = tmp; |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 |
void scr_ShowBuddyWindow(void) |
|
241 |
{ |
|
242 |
buddy_entry_t *tmp = bud_SelectedInfo(); |
|
243 |
if (tmp->jid != NULL) |
|
244 |
scr_ShowWindow(tmp->jid); |
|
245 |
top_panel(inputPanel); |
|
246 |
} |
|
247 |
|
|
248 |
|
50
|
249 |
void scr_WriteInWindow(const char *winId, char *texto, int TimeStamp, int force_show) |
24
|
250 |
{ |
|
251 |
time_t ahora; |
|
252 |
int n; |
|
253 |
int i; |
|
254 |
int width; |
|
255 |
window_entry_t *tmp; |
|
256 |
int dont_show = FALSE; |
|
257 |
|
|
258 |
tmp = scr_SearchWindow(winId); |
|
259 |
|
|
260 |
if (!chatmode) |
|
261 |
dont_show = TRUE; |
|
262 |
else if ((!force_show) && ((!currentWindow || (currentWindow != tmp)))) |
|
263 |
dont_show = TRUE; |
|
264 |
|
|
265 |
if (tmp == NULL) { |
39
|
266 |
tmp = scr_CreatePanel(winId, ROSTER_WEIGHT, 0, CHAT_WIN_HEIGHT, |
|
267 |
maxX - ROSTER_WEIGHT, dont_show); |
24
|
268 |
tmp->texto = (char **) calloc((CHAT_WIN_HEIGHT+1) * 3, sizeof(char *)); |
|
269 |
for (n = 0; n < CHAT_WIN_HEIGHT * 3; n++) |
|
270 |
tmp->texto[n] = (char *) calloc(1, 1024); |
|
271 |
|
|
272 |
if (TimeStamp) { |
|
273 |
ahora = time(NULL); |
|
274 |
strftime(tmp->texto[tmp->nlines], 1024, "[%H:%M] ", |
|
275 |
localtime(&ahora)); |
|
276 |
strcat(tmp->texto[tmp->nlines], texto); |
|
277 |
} else { |
|
278 |
sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
279 |
} |
|
280 |
tmp->nlines++; |
|
281 |
} else { |
|
282 |
if (tmp->nlines < CHAT_WIN_HEIGHT - 2) { |
|
283 |
if (TimeStamp) { |
|
284 |
ahora = time(NULL); |
|
285 |
strftime(tmp->texto[tmp->nlines], 1024, |
|
286 |
"[%H:%M] ", localtime(&ahora)); |
|
287 |
strcat(tmp->texto[tmp->nlines], texto); |
|
288 |
} else { |
|
289 |
sprintf(tmp->texto[tmp->nlines], " %s", texto); |
|
290 |
} |
|
291 |
tmp->nlines++; |
|
292 |
} else { |
|
293 |
for (n = 0; n < tmp->nlines; n++) { |
|
294 |
memset(tmp->texto[n], 0, 1024); |
|
295 |
strncpy(tmp->texto[n], tmp->texto[n + 1], 1024); |
|
296 |
} |
|
297 |
if (TimeStamp) { |
|
298 |
ahora = time(NULL); |
|
299 |
strftime(tmp->texto[tmp->nlines - 1], 1024, |
|
300 |
"[%H:%M] ", localtime(&ahora)); |
|
301 |
strcat(tmp->texto[tmp->nlines - 1], texto); |
|
302 |
} else { |
|
303 |
sprintf(tmp->texto[tmp->nlines - 1], " %s", texto); |
|
304 |
} |
|
305 |
} |
|
306 |
} |
|
307 |
|
|
308 |
if (!dont_show) { |
|
309 |
top_panel(tmp->panel); |
|
310 |
width = scr_WindowHeight(tmp->win); |
|
311 |
for (n = 0; n < tmp->nlines; n++) { |
|
312 |
mvwprintw(tmp->win, n + 1, 1, ""); |
|
313 |
for (i = 0; i < width - 2; i++) |
|
314 |
waddch(tmp->win, ' '); |
|
315 |
mvwprintw(tmp->win, n + 1, 1, "%s", tmp->texto[n]); |
|
316 |
} |
|
317 |
|
|
318 |
update_panels(); |
|
319 |
doupdate(); |
|
320 |
} else { |
|
321 |
tmp->hidden_msg = TRUE; |
30
|
322 |
update_roster = TRUE; |
24
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
void scr_InitCurses(void) |
|
327 |
{ |
|
328 |
initscr(); |
|
329 |
noecho(); |
|
330 |
raw(); |
35
|
331 |
halfdelay(5); |
24
|
332 |
start_color(); |
|
333 |
use_default_colors(); |
|
334 |
|
|
335 |
ParseColors(); |
|
336 |
|
|
337 |
getmaxyx(stdscr, maxY, maxX); |
|
338 |
inputLine[0] = 0; |
|
339 |
ptr_inputline = inputLine; |
|
340 |
|
35
|
341 |
setlocale(LC_CTYPE, ""); |
24
|
342 |
|
|
343 |
return; |
|
344 |
} |
|
345 |
|
|
346 |
void scr_DrawMainWindow(void) |
|
347 |
{ |
|
348 |
/* Draw main panels */ |
39
|
349 |
rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WEIGHT, 0, 0); |
24
|
350 |
rosterPanel = new_panel(rosterWnd); |
44
|
351 |
scr_draw_box(rosterWnd, 0, 0, CHAT_WIN_HEIGHT, ROSTER_WEIGHT, |
|
352 |
COLOR_GENERAL, 0, 0); |
39
|
353 |
mvwprintw(rosterWnd, 0, (ROSTER_WEIGHT - strlen(i18n("Roster"))) / 2, |
24
|
354 |
i18n("Roster")); |
|
355 |
|
39
|
356 |
chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT, 0, ROSTER_WEIGHT); |
24
|
357 |
chatPanel = new_panel(chatWnd); |
44
|
358 |
scr_draw_box(chatWnd, 0, 0, CHAT_WIN_HEIGHT, maxX - ROSTER_WEIGHT, |
|
359 |
COLOR_GENERAL, 0, 0); |
24
|
360 |
mvwprintw(chatWnd, 1, 1, "This is the status window"); |
|
361 |
|
|
362 |
logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); |
|
363 |
logPanel_border = new_panel(logWnd_border); |
|
364 |
scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
|
365 |
logWnd = derwin(logWnd_border, LOG_WIN_HEIGHT-2, maxX-2, 1, 1); |
|
366 |
logPanel = new_panel(logWnd); |
|
367 |
wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
368 |
|
|
369 |
scrollok(logWnd,TRUE); |
|
370 |
|
|
371 |
inputWnd = newwin(1, maxX, maxY-1, 0); |
|
372 |
inputPanel = new_panel(inputWnd); |
|
373 |
|
|
374 |
bud_DrawRoster(rosterWnd); |
|
375 |
update_panels(); |
|
376 |
doupdate(); |
|
377 |
return; |
|
378 |
} |
|
379 |
|
|
380 |
void scr_TerminateCurses(void) |
|
381 |
{ |
|
382 |
clear(); |
|
383 |
refresh(); |
|
384 |
endwin(); |
|
385 |
return; |
|
386 |
} |
|
387 |
|
50
|
388 |
void scr_WriteMessage(const char *jid, const char *text, char *prefix) |
24
|
389 |
{ |
|
390 |
char **submsgs; |
|
391 |
int n, i; |
47
|
392 |
char *buffer = (char *) malloc(strlen(text) + strlen(text)); |
24
|
393 |
|
47
|
394 |
if (prefix) |
|
395 |
strcpy(buffer, prefix); |
|
396 |
else |
|
397 |
*buffer = 0; |
|
398 |
|
|
399 |
strcat(buffer, text); |
24
|
400 |
|
|
401 |
submsgs = |
44
|
402 |
ut_SplitMessage(buffer, &n, maxX - scr_WindowHeight(rosterWnd) - 14); |
24
|
403 |
|
|
404 |
for (i = 0; i < n; i++) { |
|
405 |
if (i == 0) |
47
|
406 |
scr_WriteInWindow(jid, submsgs[i], TRUE, FALSE); |
24
|
407 |
else |
47
|
408 |
scr_WriteInWindow(jid, submsgs[i], FALSE, FALSE); |
24
|
409 |
} |
|
410 |
|
|
411 |
for (i = 0; i < n; i++) |
|
412 |
free(submsgs[i]); |
|
413 |
free(submsgs); |
|
414 |
free(buffer); |
47
|
415 |
} |
|
416 |
|
50
|
417 |
void scr_WriteIncomingMessage(const char *jidfrom, const char *text) |
47
|
418 |
{ |
|
419 |
char *buffer = utf8_decode(text); |
|
420 |
scr_WriteMessage(jidfrom, buffer, "<== "); |
|
421 |
free(buffer); |
65
|
422 |
top_panel(inputPanel); |
24
|
423 |
update_panels(); |
|
424 |
doupdate(); |
|
425 |
} |
|
426 |
|
50
|
427 |
void scr_WriteOutgoingMessage(const char *jidto, const char *text) |
47
|
428 |
{ |
65
|
429 |
scr_WriteMessage(jidto, text, "--> "); |
47
|
430 |
scr_ShowWindow(jidto); |
65
|
431 |
top_panel(inputPanel); |
47
|
432 |
//refresh(); // XXX ? |
|
433 |
} |
|
434 |
|
24
|
435 |
int scr_Getch(void) |
|
436 |
{ |
|
437 |
int ch; |
|
438 |
// keypad(inputWnd, TRUE); |
|
439 |
ch = wgetch(inputWnd); |
|
440 |
return ch; |
|
441 |
} |
|
442 |
|
|
443 |
WINDOW *scr_GetRosterWindow(void) |
|
444 |
{ |
|
445 |
return rosterWnd; |
|
446 |
} |
|
447 |
|
|
448 |
WINDOW *scr_GetStatusWindow(void) |
|
449 |
{ |
|
450 |
return chatWnd; |
|
451 |
} |
|
452 |
|
|
453 |
WINDOW *scr_GetInputWindow(void) |
|
454 |
{ |
|
455 |
return inputWnd; |
|
456 |
} |
|
457 |
|
44
|
458 |
// scr_LogPrint(...) |
|
459 |
// Display a message in the log window. |
24
|
460 |
void scr_LogPrint(const char *fmt, ...) |
|
461 |
{ |
|
462 |
time_t timestamp; |
|
463 |
char *buffer; |
|
464 |
va_list ap; |
|
465 |
|
|
466 |
buffer = (char *) calloc(1, 4096); |
|
467 |
|
|
468 |
timestamp = time(NULL); |
|
469 |
strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); |
|
470 |
wprintw(logWnd, "\n%s", buffer); |
|
471 |
|
|
472 |
va_start(ap, fmt); |
|
473 |
vsnprintf(buffer, 4096, fmt, ap); |
|
474 |
va_end(ap); |
|
475 |
|
|
476 |
wprintw(logWnd, "%s", buffer); |
|
477 |
free(buffer); |
|
478 |
|
|
479 |
update_panels(); |
|
480 |
doupdate(); |
|
481 |
} |
|
482 |
|
|
483 |
// scr_IsHiddenMessage(jid) |
|
484 |
// Returns TRUE if there is a hidden message in the window |
|
485 |
// for the jid contact. |
50
|
486 |
int scr_IsHiddenMessage(const char *jid) { |
24
|
487 |
window_entry_t *wintmp; |
|
488 |
|
|
489 |
wintmp = scr_SearchWindow(jid); |
|
490 |
if ((wintmp) && (wintmp->hidden_msg)) |
|
491 |
return TRUE; |
|
492 |
|
|
493 |
return FALSE; |
|
494 |
} |
|
495 |
|
|
496 |
// check_offset(int direction) |
|
497 |
// Check inputline_offset value, and make sure the cursor is inside the |
|
498 |
// screen. |
|
499 |
inline void check_offset(int direction) |
|
500 |
{ |
|
501 |
// Left side |
|
502 |
if (inputline_offset && direction <= 0) { |
|
503 |
while (ptr_inputline <= (char*)&inputLine + inputline_offset) { |
|
504 |
if (inputline_offset) { |
|
505 |
inputline_offset -= 5; |
|
506 |
if (inputline_offset < 0) |
|
507 |
inputline_offset = 0; |
|
508 |
} |
|
509 |
} |
|
510 |
} |
|
511 |
// Right side |
|
512 |
if (direction >= 0) { |
|
513 |
while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) |
|
514 |
inputline_offset += 5; |
|
515 |
} |
|
516 |
} |
|
517 |
|
44
|
518 |
// process_key(key) |
|
519 |
// Handle the pressed key, in the command line (bottom). |
29
|
520 |
int process_key(int key) |
24
|
521 |
{ |
|
522 |
if (isprint(key)) { |
|
523 |
char tmpLine[INPUTLINE_LENGTH+1]; |
|
524 |
|
|
525 |
// Check the line isn't too long |
|
526 |
if (strlen(inputLine) >= INPUTLINE_LENGTH) |
|
527 |
return 0; |
|
528 |
|
|
529 |
// Insert char |
|
530 |
strcpy(tmpLine, ptr_inputline); |
|
531 |
*ptr_inputline++ = key; |
|
532 |
strcpy(ptr_inputline, tmpLine); |
|
533 |
check_offset(1); |
|
534 |
} else { |
|
535 |
switch(key) { |
|
536 |
case KEY_BACKSPACE: |
|
537 |
if (ptr_inputline != (char*)&inputLine) { |
42
|
538 |
char *c = --ptr_inputline; |
|
539 |
for ( ; *c ; c++) |
|
540 |
*c = *(c+1); |
24
|
541 |
check_offset(-1); |
|
542 |
} |
|
543 |
break; |
|
544 |
case KEY_DC: |
|
545 |
if (*ptr_inputline) |
|
546 |
strcpy(ptr_inputline, ptr_inputline+1); |
|
547 |
break; |
|
548 |
case KEY_LEFT: |
|
549 |
if (ptr_inputline != (char*)&inputLine) { |
|
550 |
ptr_inputline--; |
|
551 |
check_offset(-1); |
|
552 |
} |
|
553 |
break; |
|
554 |
case KEY_RIGHT: |
|
555 |
if (*ptr_inputline) |
|
556 |
ptr_inputline++; |
|
557 |
check_offset(1); |
|
558 |
break; |
|
559 |
case 9: // Tab |
|
560 |
scr_LogPrint("I'm unable to complete yet"); |
|
561 |
break; |
|
562 |
case '\n': // Enter |
|
563 |
chatmode = TRUE; |
|
564 |
if (inputLine[0] == 0) { |
|
565 |
scr_ShowBuddyWindow(); |
|
566 |
break; |
|
567 |
} |
29
|
568 |
if (process_line(inputLine)) |
24
|
569 |
return 255; |
|
570 |
ptr_inputline = inputLine; |
|
571 |
*ptr_inputline = 0; |
|
572 |
inputline_offset = 0; |
|
573 |
break; |
|
574 |
case KEY_UP: |
|
575 |
bud_RosterUp(); |
|
576 |
if (chatmode) |
|
577 |
scr_ShowBuddyWindow(); |
|
578 |
break; |
|
579 |
case KEY_DOWN: |
|
580 |
bud_RosterDown(); |
|
581 |
if (chatmode) |
|
582 |
scr_ShowBuddyWindow(); |
|
583 |
break; |
|
584 |
case KEY_PPAGE: |
|
585 |
scr_LogPrint("PageUp??"); |
|
586 |
break; |
|
587 |
case KEY_NPAGE: |
|
588 |
scr_LogPrint("PageDown??"); |
|
589 |
break; |
|
590 |
case KEY_HOME: |
|
591 |
case 1: |
|
592 |
ptr_inputline = inputLine; |
|
593 |
inputline_offset = 0; |
|
594 |
break; |
|
595 |
case KEY_END: |
|
596 |
case 5: |
|
597 |
for (; *ptr_inputline; ptr_inputline++) ; |
|
598 |
check_offset(1); |
|
599 |
break; |
|
600 |
case 21: // Ctrl-u |
|
601 |
strcpy(inputLine, ptr_inputline); |
|
602 |
ptr_inputline = inputLine; |
|
603 |
inputline_offset = 0; |
|
604 |
break; |
|
605 |
case KEY_EOL: |
|
606 |
case 11: // Ctrl-k |
|
607 |
*ptr_inputline = 0; |
|
608 |
break; |
|
609 |
case 16: // Ctrl-p |
|
610 |
scr_LogPrint("Ctrl-p not yet implemented"); |
|
611 |
break; |
|
612 |
case 14: // Ctrl-n |
|
613 |
scr_LogPrint("Ctrl-n not yet implemented"); |
|
614 |
break; |
|
615 |
case 27: // ESC |
|
616 |
currentWindow = NULL; |
|
617 |
chatmode = FALSE; |
|
618 |
top_panel(chatPanel); |
|
619 |
top_panel(inputPanel); |
|
620 |
break; |
|
621 |
default: |
|
622 |
scr_LogPrint("Unkown key=%d", key); |
|
623 |
} |
|
624 |
} |
|
625 |
mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
|
626 |
wclrtoeol(inputWnd); |
|
627 |
if (*ptr_inputline) { |
|
628 |
wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); |
|
629 |
} |
|
630 |
update_panels(); |
|
631 |
doupdate(); |
|
632 |
return 0; |
|
633 |
} |