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" |
81
|
11 #include "hbuf.h" |
47
|
12 #include "commands.h" |
95
|
13 #include "compl.h" |
81
|
14 #include "roster.h" |
180
|
15 #include "histolog.h" |
24
|
16 #include "parsecfg.h" |
81
|
17 #include "utils.h" |
24
|
18 #include "list.h" |
|
19 |
|
20 #define window_entry(n) list_entry(n, window_entry_t, list) |
|
21 |
151
|
22 inline void check_offset(int); |
|
23 |
24
|
24 LIST_HEAD(window_list); |
|
25 |
|
26 typedef struct _window_entry_t { |
|
27 WINDOW *win; |
108
|
28 PANEL *panel; |
|
29 char *name; |
|
30 GList *hbuf; |
181
|
31 GList *top; // If top is NULL, we'll display the last lines |
|
32 char cleared; // For ex, user has issued a /clear command... |
24
|
33 struct list_head list; |
|
34 } window_entry_t; |
|
35 |
|
36 |
|
37 static WINDOW *rosterWnd, *chatWnd, *inputWnd; |
|
38 static WINDOW *logWnd, *logWnd_border; |
|
39 static PANEL *rosterPanel, *chatPanel, *inputPanel; |
|
40 static PANEL *logPanel, *logPanel_border; |
|
41 static int maxY, maxX; |
|
42 static window_entry_t *currentWindow; |
|
43 |
|
44 static int chatmode; |
30
|
45 int update_roster; |
24
|
46 |
174
|
47 static char inputLine[INPUTLINE_LENGTH+1]; |
|
48 static char *ptr_inputline; |
|
49 static short int inputline_offset; |
|
50 static int completion_started; |
173
|
51 static GList *cmdhisto; |
|
52 static GList *cmdhisto_cur; |
174
|
53 static char cmdhisto_backup[INPUTLINE_LENGTH+1]; |
24
|
54 |
|
55 |
99
|
56 /* Functions */ |
24
|
57 |
74
|
58 int scr_WindowWidth(WINDOW * win) |
24
|
59 { |
|
60 int x, y; |
|
61 getmaxyx(win, y, x); |
|
62 return x; |
|
63 } |
|
64 |
74
|
65 void scr_clear_box(WINDOW *win, int y, int x, int height, int width, int Color) |
|
66 { |
|
67 int i, j; |
|
68 |
|
69 wattrset(win, COLOR_PAIR(Color)); |
|
70 for (i = 0; i < height; i++) { |
|
71 wmove(win, y + i, x); |
|
72 for (j = 0; j < width; j++) |
|
73 wprintw(win, " "); |
|
74 } |
|
75 } |
|
76 |
24
|
77 void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
|
78 int Color, chtype box, chtype border) |
|
79 { |
|
80 int i, j; |
|
81 |
|
82 wattrset(win, COLOR_PAIR(Color)); |
|
83 for (i = 0; i < height; i++) { |
|
84 wmove(win, y + i, x); |
|
85 for (j = 0; j < width; j++) |
|
86 if (!i && !j) |
|
87 waddch(win, border | ACS_ULCORNER); |
|
88 else if (i == height - 1 && !j) |
|
89 waddch(win, border | ACS_LLCORNER); |
|
90 else if (!i && j == width - 1) |
|
91 waddch(win, box | ACS_URCORNER); |
|
92 else if (i == height - 1 && j == width - 1) |
|
93 waddch(win, box | ACS_LRCORNER); |
|
94 else if (!i) |
|
95 waddch(win, border | ACS_HLINE); |
|
96 else if (i == height - 1) |
|
97 waddch(win, box | ACS_HLINE); |
|
98 else if (!j) |
|
99 waddch(win, border | ACS_VLINE); |
|
100 else if (j == width - 1) |
|
101 waddch(win, box | ACS_VLINE); |
|
102 else |
|
103 waddch(win, box | ' '); |
|
104 } |
|
105 } |
|
106 |
|
107 int FindColor(char *name) |
|
108 { |
|
109 if (!strcmp(name, "default")) |
|
110 return -1; |
|
111 if (!strcmp(name, "black")) |
|
112 return COLOR_BLACK; |
|
113 if (!strcmp(name, "red")) |
|
114 return COLOR_RED; |
|
115 if (!strcmp(name, "green")) |
|
116 return COLOR_GREEN; |
|
117 if (!strcmp(name, "yellow")) |
|
118 return COLOR_YELLOW; |
|
119 if (!strcmp(name, "blue")) |
|
120 return COLOR_BLUE; |
|
121 if (!strcmp(name, "magenta")) |
|
122 return COLOR_MAGENTA; |
|
123 if (!strcmp(name, "cyan")) |
|
124 return COLOR_CYAN; |
|
125 if (!strcmp(name, "white")) |
|
126 return COLOR_WHITE; |
|
127 |
|
128 return -1; |
|
129 } |
|
130 |
|
131 void ParseColors(void) |
|
132 { |
|
133 char *colors[11] = { |
|
134 "", "", |
|
135 "borderlines", |
|
136 "jidonline", |
139
|
137 "newmsg", |
24
|
138 "jidofflineselected", |
|
139 "jidoffline", |
|
140 "text", |
|
141 NULL |
|
142 }; |
|
143 |
|
144 char *tmp = malloc(1024); |
|
145 char *color1; |
|
146 char *background = cfg_read("color_background"); |
|
147 char *backselected = cfg_read("color_backselected"); |
|
148 int i = 0; |
|
149 |
|
150 while (colors[i]) { |
|
151 sprintf(tmp, "color_%s", colors[i]); |
|
152 color1 = cfg_read(tmp); |
|
153 |
|
154 switch (i + 1) { |
|
155 case 1: |
|
156 init_pair(1, COLOR_BLACK, COLOR_WHITE); |
|
157 break; |
|
158 case 2: |
|
159 init_pair(2, COLOR_WHITE, COLOR_BLACK); |
|
160 break; |
|
161 case 3: |
|
162 init_pair(3, FindColor(color1), FindColor(background)); |
|
163 break; |
|
164 case 4: |
|
165 init_pair(4, FindColor(color1), FindColor(backselected)); |
|
166 break; |
|
167 case 5: |
|
168 init_pair(5, FindColor(color1), FindColor(background)); |
|
169 break; |
|
170 case 6: |
|
171 init_pair(6, FindColor(color1), FindColor(backselected)); |
|
172 break; |
|
173 case 7: |
|
174 init_pair(7, FindColor(color1), FindColor(background)); |
|
175 break; |
|
176 case 8: |
|
177 init_pair(8, FindColor(color1), FindColor(background)); |
|
178 break; |
|
179 } |
|
180 i++; |
|
181 } |
|
182 } |
|
183 |
|
184 |
151
|
185 window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
24
|
186 { |
151
|
187 int x; |
|
188 int y; |
|
189 int lines; |
|
190 int cols; |
153
|
191 window_entry_t *tmp; |
|
192 |
|
193 do { |
|
194 tmp = calloc(1, sizeof(window_entry_t)); |
|
195 } while (!tmp); |
24
|
196 |
151
|
197 // Dimensions |
|
198 x = ROSTER_WIDTH; |
|
199 y = 0; |
|
200 lines = CHAT_WIN_HEIGHT; |
|
201 cols = maxX - ROSTER_WIDTH; |
|
202 |
24
|
203 tmp->win = newwin(lines, cols, y, x); |
154
|
204 while (!tmp->win) { |
|
205 usleep(250); |
|
206 tmp->win = newwin(lines, cols, y, x); |
|
207 } |
168
|
208 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL)); |
24
|
209 tmp->panel = new_panel(tmp->win); |
153
|
210 tmp->name = (char *) calloc(1, 96); |
|
211 strncpy(tmp->name, title, 96); |
24
|
212 |
143
|
213 if (!dont_show) { |
24
|
214 currentWindow = tmp; |
|
215 } else { |
|
216 if (currentWindow) |
|
217 top_panel(currentWindow->panel); |
|
218 else |
|
219 top_panel(chatPanel); |
|
220 } |
143
|
221 update_panels(); |
24
|
222 |
181
|
223 // Load buddy history from file (if enabled) |
178
|
224 hlog_read_history(title, &tmp->hbuf, maxX - scr_WindowWidth(rosterWnd) - 14); |
181
|
225 |
24
|
226 list_add_tail(&tmp->list, &window_list); |
|
227 |
|
228 return tmp; |
|
229 } |
|
230 |
50
|
231 window_entry_t *scr_SearchWindow(const char *winId) |
24
|
232 { |
|
233 struct list_head *pos, *n; |
|
234 window_entry_t *search_entry = NULL; |
|
235 |
|
236 list_for_each_safe(pos, n, &window_list) { |
|
237 search_entry = window_entry(pos); |
|
238 if (search_entry->name) { |
|
239 if (!strcasecmp(search_entry->name, winId)) { |
|
240 return search_entry; |
|
241 } |
|
242 } |
|
243 } |
|
244 return NULL; |
|
245 } |
|
246 |
143
|
247 // scr_UpdateWindow() |
|
248 // (Re-)Display the given chat window. |
74
|
249 void scr_UpdateWindow(window_entry_t *win_entry) |
|
250 { |
|
251 int n; |
|
252 int width; |
|
253 char **lines; |
|
254 GList *hbuf_head; |
|
255 |
108
|
256 width = scr_WindowWidth(win_entry->win); |
|
257 |
|
258 // Should the window be empty? |
|
259 if (win_entry->cleared) { |
168
|
260 werase(win_entry->win); |
108
|
261 return; |
|
262 } |
|
263 |
105
|
264 // win_entry->top is the top message of the screen. If it set to NULL, we |
|
265 // are displaying the last messages. |
|
266 |
74
|
267 // We will show the last CHAT_WIN_HEIGHT lines. |
|
268 // Let's find out where it begins. |
105
|
269 if (!win_entry->top || |
|
270 (g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) { |
|
271 // Move up CHAT_WIN_HEIGHT lines |
|
272 win_entry->hbuf = g_list_last(win_entry->hbuf); |
|
273 hbuf_head = win_entry->hbuf; |
|
274 win_entry->top = NULL; // (Just to make sure) |
|
275 n = 0; |
|
276 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) { |
|
277 hbuf_head = g_list_previous(hbuf_head); |
|
278 n++; |
|
279 } |
|
280 } else |
|
281 hbuf_head = win_entry->top; |
74
|
282 |
|
283 // Get the last CHAT_WIN_HEIGHT lines. |
|
284 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); |
|
285 |
|
286 // Display these lines |
|
287 for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
168
|
288 wmove(win_entry->win, n, 0); |
75
|
289 if (*(lines+2*n)) { |
|
290 if (**(lines+2*n)) |
|
291 wprintw(win_entry->win, "%s", *(lines+2*n)); // prefix |
|
292 else { |
|
293 wprintw(win_entry->win, " "); |
|
294 } |
|
295 wprintw(win_entry->win, "%s", *(lines+2*n+1)); // line |
168
|
296 wclrtoeol(win_entry->win); |
|
297 } else { |
|
298 wclrtobot(win_entry->win); |
|
299 break; |
75
|
300 } |
74
|
301 } |
|
302 g_free(lines); |
|
303 } |
|
304 |
143
|
305 // scr_ShowWindow() |
|
306 // Display the chat window with the given identifier. |
50
|
307 void scr_ShowWindow(const char *winId) |
24
|
308 { |
74
|
309 window_entry_t *win_entry = scr_SearchWindow(winId); |
|
310 |
181
|
311 if (!win_entry) |
180
|
312 win_entry = scr_CreateBuddyPanel(winId, FALSE); |
74
|
313 |
180
|
314 top_panel(win_entry->panel); |
|
315 currentWindow = win_entry; |
|
316 chatmode = TRUE; |
|
317 roster_msg_setflag(winId, FALSE); |
|
318 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE); |
|
319 update_roster = TRUE; |
74
|
320 |
180
|
321 // Refresh the window |
|
322 scr_UpdateWindow(win_entry); |
|
323 |
|
324 // Finished :) |
|
325 update_panels(); |
142
|
326 |
|
327 top_panel(inputPanel); |
24
|
328 } |
|
329 |
143
|
330 // scr_ShowBuddyWindow() |
|
331 // Display the chat window buffer for the current buddy. |
24
|
332 void scr_ShowBuddyWindow(void) |
|
333 { |
105
|
334 const gchar *jid; |
140
|
335 |
105
|
336 if (!current_buddy) |
140
|
337 jid = NULL; |
|
338 else |
|
339 jid = CURRENT_JID; |
|
340 |
|
341 if (!jid) { |
|
342 top_panel(chatPanel); |
143
|
343 top_panel(inputPanel); |
140
|
344 currentWindow = NULL; |
105
|
345 return; |
140
|
346 } |
|
347 |
105
|
348 scr_ShowWindow(jid); |
24
|
349 } |
|
350 |
|
351 |
143
|
352 // scr_WriteInWindow() |
|
353 // Write some text in the winId window (this usually is a jid). |
|
354 // Lines are splitted when they are too long to fit in the chat window. |
|
355 // If this window doesn't exist, it is created. |
75
|
356 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp, |
|
357 const char *prefix, int force_show) |
24
|
358 { |
75
|
359 char *fullprefix = NULL; |
74
|
360 window_entry_t *win_entry; |
24
|
361 int dont_show = FALSE; |
|
362 |
75
|
363 // Prepare the prefix |
|
364 if (prefix || TimeStamp) { |
|
365 if (!prefix) prefix = ""; |
|
366 fullprefix = calloc(1, strlen(prefix)+16); |
|
367 if (TimeStamp) { |
|
368 time_t now = time(NULL); |
|
369 strftime(fullprefix, 12, "[%H:%M] ", localtime(&now)); |
|
370 } else { |
|
371 strcpy(fullprefix, " "); |
|
372 } |
|
373 strcat(fullprefix, prefix); |
74
|
374 } |
|
375 |
|
376 // Look for the window entry. |
|
377 win_entry = scr_SearchWindow(winId); |
|
378 |
|
379 // Do we have to really show the window? |
24
|
380 if (!chatmode) |
|
381 dont_show = TRUE; |
74
|
382 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) |
24
|
383 dont_show = TRUE; |
|
384 |
74
|
385 // If the window entry doesn't exist yet, let's create it. |
|
386 if (win_entry == NULL) { |
151
|
387 win_entry = scr_CreateBuddyPanel(winId, dont_show); |
24
|
388 } |
|
389 |
75
|
390 hbuf_add_line(&win_entry->hbuf, text, fullprefix, |
74
|
391 maxX - scr_WindowWidth(rosterWnd) - 14); |
75
|
392 free(fullprefix); |
74
|
393 |
108
|
394 if (win_entry->cleared) { |
|
395 win_entry->cleared = 0; // The message must be displayed |
|
396 win_entry->top = g_list_last(win_entry->hbuf); |
|
397 } |
|
398 |
24
|
399 if (!dont_show) { |
74
|
400 // Show and refresh the window |
|
401 top_panel(win_entry->panel); |
|
402 scr_UpdateWindow(win_entry); |
142
|
403 top_panel(inputPanel); |
24
|
404 update_panels(); |
|
405 doupdate(); |
|
406 } else { |
148
|
407 roster_msg_setflag(winId, TRUE); |
30
|
408 update_roster = TRUE; |
24
|
409 } |
|
410 } |
|
411 |
|
412 void scr_InitCurses(void) |
|
413 { |
|
414 initscr(); |
|
415 noecho(); |
|
416 raw(); |
35
|
417 halfdelay(5); |
24
|
418 start_color(); |
|
419 use_default_colors(); |
|
420 |
|
421 ParseColors(); |
|
422 |
|
423 getmaxyx(stdscr, maxY, maxX); |
167
|
424 if (maxY < LOG_WIN_HEIGHT+2) |
|
425 maxY = LOG_WIN_HEIGHT+2; |
24
|
426 inputLine[0] = 0; |
|
427 ptr_inputline = inputLine; |
|
428 |
35
|
429 setlocale(LC_CTYPE, ""); |
24
|
430 |
|
431 return; |
|
432 } |
|
433 |
81
|
434 void scr_TerminateCurses(void) |
|
435 { |
|
436 clear(); |
|
437 refresh(); |
|
438 endwin(); |
|
439 return; |
|
440 } |
|
441 |
151
|
442 // scr_DrawMainWindow() |
157
|
443 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
151
|
444 // |
|
445 // I think it could be improved a _lot_ but I'm really not an ncurses |
|
446 // expert... :-\ Mikael. |
|
447 // |
|
448 void scr_DrawMainWindow(unsigned int fullinit) |
24
|
449 { |
157
|
450 if (fullinit) { |
|
451 /* Create windows */ |
|
452 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); |
|
453 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); |
|
454 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); |
|
455 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1); |
|
456 inputWnd = newwin(1, maxX, maxY-1, 0); |
168
|
457 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
458 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
459 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL)); |
|
460 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
157
|
461 } else { |
|
462 /* Resize windows */ |
|
463 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH); |
|
464 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH); |
|
465 |
|
466 wresize(logWnd_border, LOG_WIN_HEIGHT, maxX); |
|
467 wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2); |
|
468 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0); |
|
469 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1); |
|
470 |
|
471 wresize(inputWnd, 1, maxX); |
|
472 mvwin(inputWnd, maxY-1, 0); |
168
|
473 |
|
474 werase(chatWnd); |
157
|
475 } |
151
|
476 |
|
477 /* Draw/init windows */ |
|
478 |
74
|
479 mvwprintw(chatWnd, 0, 0, "This is the status window"); |
24
|
480 |
151
|
481 // - Draw/clear the log window |
24
|
482 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
157
|
483 // Auto-scrolling in log window |
74
|
484 scrollok(logWnd, TRUE); |
24
|
485 |
|
486 |
151
|
487 if (fullinit) { |
157
|
488 // Enable keypad (+ special keys) |
|
489 keypad(inputWnd, TRUE); |
|
490 |
151
|
491 // Create panels |
|
492 rosterPanel = new_panel(rosterWnd); |
|
493 chatPanel = new_panel(chatWnd); |
|
494 logPanel_border = new_panel(logWnd_border); |
|
495 logPanel = new_panel(logWnd); |
|
496 inputPanel = new_panel(inputWnd); |
157
|
497 } else { |
|
498 // Update panels |
|
499 replace_panel(rosterPanel, rosterWnd); |
|
500 replace_panel(chatPanel, chatWnd); |
|
501 replace_panel(logPanel, logWnd); |
|
502 replace_panel(logPanel_border, logWnd_border); |
|
503 replace_panel(inputPanel, inputWnd); |
151
|
504 } |
|
505 |
|
506 // We'll need to redraw the roster |
149
|
507 update_roster = TRUE; |
24
|
508 return; |
|
509 } |
|
510 |
151
|
511 // scr_Resize() |
|
512 // Function called when the window is resized. |
157
|
513 // - Resize windows |
151
|
514 // - Rewrap lines in each buddy buffer |
|
515 void scr_Resize() |
|
516 { |
|
517 struct list_head *pos, *n; |
|
518 window_entry_t *search_entry; |
|
519 int x, y, lines, cols; |
|
520 |
|
521 // First, update the global variables |
|
522 getmaxyx(stdscr, maxY, maxX); |
167
|
523 if (maxY < LOG_WIN_HEIGHT+2) |
|
524 maxY = LOG_WIN_HEIGHT+2; |
151
|
525 // Make sure the cursor stays inside the window |
|
526 check_offset(0); |
|
527 |
157
|
528 // Resize windows and update panels |
151
|
529 scr_DrawMainWindow(FALSE); |
|
530 |
|
531 // Resize all buddy windows |
|
532 x = ROSTER_WIDTH; |
|
533 y = 0; |
|
534 lines = CHAT_WIN_HEIGHT; |
|
535 cols = maxX - ROSTER_WIDTH; |
|
536 |
|
537 list_for_each_safe(pos, n, &window_list) { |
|
538 search_entry = window_entry(pos); |
|
539 if (search_entry->win) { |
157
|
540 // Resize buddy window (no need to move it) |
|
541 wresize(search_entry->win, lines, cols); |
168
|
542 werase(search_entry->win); |
151
|
543 // If a panel exists, replace the old window with the new |
|
544 if (search_entry->panel) { |
|
545 replace_panel(search_entry->panel, search_entry->win); |
|
546 } |
|
547 // Redo line wrapping |
|
548 hbuf_rebuild(&search_entry->hbuf, |
|
549 maxX - scr_WindowWidth(rosterWnd) - 14); |
|
550 } |
|
551 } |
|
552 |
|
553 // Refresh current buddy window |
157
|
554 if (chatmode) |
151
|
555 scr_ShowBuddyWindow(); |
|
556 } |
|
557 |
143
|
558 // scr_DrawRoster() |
|
559 // Actually, display the buddylist on the screen. |
81
|
560 void scr_DrawRoster(void) |
24
|
561 { |
81
|
562 static guint offset = 0; |
|
563 char name[ROSTER_WIDTH]; |
|
564 int maxx, maxy; |
|
565 GList *buddy; |
|
566 int i, n; |
|
567 int rOffset; |
164
|
568 enum imstatus currentstatus = jb_getstatus(); |
81
|
569 |
123
|
570 // We can reset update_roster |
|
571 update_roster = FALSE; |
|
572 |
81
|
573 getmaxyx(rosterWnd, maxy, maxx); |
|
574 maxx --; // last char is for vertical border |
|
575 name[ROSTER_WIDTH-7] = 0; |
|
576 |
|
577 // cleanup of roster window |
168
|
578 werase(rosterWnd); |
|
579 // Redraw the vertical line (not very good...) |
81
|
580 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
168
|
581 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) |
|
582 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE); |
81
|
583 |
|
584 // Leave now if buddylist is empty |
|
585 if (!buddylist) { |
|
586 offset = 0; |
123
|
587 update_panels(); |
|
588 doupdate(); |
81
|
589 return; |
|
590 } |
|
591 |
84
|
592 // Update offset if necessary |
|
593 i = g_list_position(buddylist, current_buddy); |
|
594 if (i == -1) { // This is bad |
|
595 scr_LogPrint("Doh! Can't find current selected buddy!!"); |
123
|
596 update_panels(); |
|
597 doupdate(); |
84
|
598 return; |
|
599 } else if (i < offset) { |
|
600 offset = i; |
|
601 } else if (i+1 > offset + maxy) { |
|
602 offset = i + 1 - maxy; |
|
603 } |
81
|
604 |
|
605 buddy = buddylist; |
|
606 rOffset = offset; |
|
607 |
84
|
608 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { |
81
|
609 |
|
610 char status = '?'; |
|
611 char pending = ' '; |
|
612 enum imstatus budstate; |
149
|
613 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG; |
|
614 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP; |
|
615 unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE; |
81
|
616 |
|
617 if (rOffset > 0) { |
|
618 rOffset--; |
|
619 continue; |
|
620 } |
|
621 |
149
|
622 // Display message notice if there is a message flag, but not |
|
623 // for unfolded groups. |
|
624 if (ismsg && (!isgrp || ishid)) { |
81
|
625 pending = '#'; |
|
626 } |
|
627 |
|
628 budstate = buddy_getstatus(BUDDATA(buddy)); |
164
|
629 if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline) |
81
|
630 status = imstatus2char[budstate]; |
|
631 if (buddy == current_buddy) { |
|
632 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL)); |
|
633 // The 3 following lines aim to color the whole line |
|
634 wmove(rosterWnd, i, 0); |
|
635 for (n = 0; n < maxx; n++) |
|
636 waddch(rosterWnd, ' '); |
|
637 } else { |
149
|
638 if (pending == '#') |
139
|
639 wattrset(rosterWnd, COLOR_PAIR(COLOR_NMSG)); |
|
640 else |
|
641 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES)); |
81
|
642 } |
|
643 |
|
644 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7); |
149
|
645 if (isgrp) { |
133
|
646 char *sep; |
149
|
647 if (ishid) |
133
|
648 sep = "+++"; |
|
649 else |
|
650 sep = "---"; |
|
651 mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name); |
|
652 } |
126
|
653 else |
|
654 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name); |
84
|
655 |
|
656 i++; |
81
|
657 } |
|
658 |
142
|
659 top_panel(inputPanel); |
81
|
660 update_panels(); |
|
661 doupdate(); |
24
|
662 } |
|
663 |
50
|
664 void scr_WriteMessage(const char *jid, const char *text, char *prefix) |
24
|
665 { |
75
|
666 scr_WriteInWindow(jid, text, TRUE, prefix, FALSE); |
47
|
667 } |
|
668 |
50
|
669 void scr_WriteIncomingMessage(const char *jidfrom, const char *text) |
47
|
670 { |
75
|
671 // FIXME expand tabs / filter out special chars... |
115
|
672 scr_WriteMessage(jidfrom, text, "<== "); |
24
|
673 update_panels(); |
|
674 doupdate(); |
|
675 } |
|
676 |
50
|
677 void scr_WriteOutgoingMessage(const char *jidto, const char *text) |
47
|
678 { |
65
|
679 scr_WriteMessage(jidto, text, "--> "); |
47
|
680 scr_ShowWindow(jidto); |
|
681 } |
|
682 |
24
|
683 int scr_Getch(void) |
|
684 { |
|
685 int ch; |
|
686 ch = wgetch(inputWnd); |
|
687 return ch; |
|
688 } |
|
689 |
|
690 WINDOW *scr_GetRosterWindow(void) |
|
691 { |
|
692 return rosterWnd; |
|
693 } |
|
694 |
|
695 WINDOW *scr_GetStatusWindow(void) |
|
696 { |
|
697 return chatWnd; |
|
698 } |
|
699 |
|
700 WINDOW *scr_GetInputWindow(void) |
|
701 { |
|
702 return inputWnd; |
|
703 } |
|
704 |
143
|
705 // scr_RosterTop() |
|
706 // Go to the first buddy in the buddylist |
105
|
707 void scr_RosterTop(void) |
104
|
708 { |
143
|
709 enum imstatus prev_st = imstatus_size; // undef |
119
|
710 |
|
711 if (current_buddy) { |
|
712 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
|
713 if (chatmode) |
|
714 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
|
715 } |
104
|
716 current_buddy = buddylist; |
119
|
717 if (chatmode && current_buddy) |
|
718 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
|
719 |
|
720 // We should rebuild the buddylist but not everytime |
143
|
721 // Here we check if we were locking a buddy who is actually offline, |
|
722 // and hide_offline_buddies is TRUE. In which case we need to rebuild. |
120
|
723 if (current_buddy && prev_st == offline && |
|
724 buddylist_get_hide_offline_buddies()) |
119
|
725 buddylist_build(); |
104
|
726 if (chatmode) |
|
727 scr_ShowBuddyWindow(); |
143
|
728 update_roster = TRUE; |
104
|
729 } |
|
730 |
143
|
731 // scr_RosterBottom() |
|
732 // Go to the last buddy in the buddylist |
105
|
733 void scr_RosterBottom(void) |
104
|
734 { |
143
|
735 enum imstatus prev_st = imstatus_size; // undef |
119
|
736 |
|
737 if (current_buddy) { |
|
738 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
|
739 if (chatmode) |
|
740 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
|
741 } |
104
|
742 current_buddy = g_list_last(buddylist); |
143
|
743 // Lock the buddy in the buddylist if we're in chat mode |
119
|
744 if (chatmode && current_buddy) |
|
745 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
|
746 |
|
747 // We should rebuild the buddylist but not everytime |
143
|
748 // Here we check if we were locking a buddy who is actually offline, |
|
749 // and hide_offline_buddies is TRUE. In which case we need to rebuild. |
120
|
750 if (current_buddy && prev_st == offline && |
|
751 buddylist_get_hide_offline_buddies()) |
119
|
752 buddylist_build(); |
143
|
753 |
104
|
754 if (chatmode) |
|
755 scr_ShowBuddyWindow(); |
143
|
756 update_roster = TRUE; |
104
|
757 } |
|
758 |
143
|
759 // scr_RosterUp() |
|
760 // Go to the previous buddy in the buddylist |
105
|
761 void scr_RosterUp(void) |
81
|
762 { |
143
|
763 enum imstatus prev_st = imstatus_size; // undef |
119
|
764 |
81
|
765 if (current_buddy) { |
|
766 if (g_list_previous(current_buddy)) { |
120
|
767 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
119
|
768 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
81
|
769 current_buddy = g_list_previous(current_buddy); |
143
|
770 // Lock the buddy in the buddylist if we're in chat mode |
119
|
771 if (chatmode) |
|
772 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
|
773 // We should rebuild the buddylist but not everytime |
143
|
774 // Here we check if we were locking a buddy who is actually offline, |
|
775 // and hide_offline_buddies is TRUE. In which case we need to rebuild. |
120
|
776 if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
119
|
777 buddylist_build(); |
143
|
778 update_roster = TRUE; |
81
|
779 } |
|
780 } |
104
|
781 |
|
782 if (chatmode) |
|
783 scr_ShowBuddyWindow(); |
81
|
784 } |
|
785 |
143
|
786 // scr_RosterDown() |
|
787 // Go to the next buddy in the buddylist |
105
|
788 void scr_RosterDown(void) |
81
|
789 { |
143
|
790 enum imstatus prev_st = imstatus_size; // undef |
119
|
791 |
81
|
792 if (current_buddy) { |
|
793 if (g_list_next(current_buddy)) { |
120
|
794 prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
119
|
795 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
81
|
796 current_buddy = g_list_next(current_buddy); |
119
|
797 if (chatmode) |
|
798 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
|
799 // We should rebuild the buddylist but not everytime |
143
|
800 // Here we check if we were locking a buddy who is actually offline, |
|
801 // and hide_offline_buddies is TRUE. In which case we need to rebuild. |
120
|
802 if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
119
|
803 buddylist_build(); |
143
|
804 update_roster = TRUE; |
81
|
805 } |
|
806 } |
104
|
807 |
|
808 if (chatmode) |
|
809 scr_ShowBuddyWindow(); |
81
|
810 } |
|
811 |
143
|
812 // scr_ScrollUp() |
|
813 // Scroll up the current buddy window, half a screen. |
105
|
814 void scr_ScrollUp(void) |
|
815 { |
|
816 const gchar *jid; |
|
817 window_entry_t *win_entry; |
|
818 int n, nblines; |
|
819 GList *hbuf_top; |
|
820 |
|
821 // Get win_entry |
|
822 if (!current_buddy) |
|
823 return; |
|
824 jid = CURRENT_JID; |
|
825 if (!jid) |
|
826 return; |
|
827 win_entry = scr_SearchWindow(jid); |
|
828 if (!win_entry) |
|
829 return; |
|
830 |
|
831 // Scroll up half a screen (or less) |
|
832 nblines = CHAT_WIN_HEIGHT/2-1; |
|
833 hbuf_top = win_entry->top; |
|
834 if (!hbuf_top) { |
|
835 hbuf_top = g_list_last(win_entry->hbuf); |
109
|
836 if (!win_entry->cleared) |
|
837 nblines *= 3; |
|
838 else |
|
839 win_entry->cleared = FALSE; |
105
|
840 } |
|
841 |
|
842 n = 0; |
|
843 while (hbuf_top && n < nblines && g_list_previous(hbuf_top)) { |
|
844 hbuf_top = g_list_previous(hbuf_top); |
|
845 n++; |
|
846 } |
|
847 win_entry->top = hbuf_top; |
|
848 |
|
849 // Refresh the window |
|
850 scr_UpdateWindow(win_entry); |
|
851 |
|
852 // Finished :) |
|
853 update_panels(); |
|
854 doupdate(); |
|
855 } |
|
856 |
143
|
857 // scr_ScrollDown() |
|
858 // Scroll down the current buddy window, half a screen. |
105
|
859 void scr_ScrollDown(void) |
|
860 { |
|
861 const gchar *jid; |
|
862 window_entry_t *win_entry; |
|
863 int n, nblines; |
|
864 GList *hbuf_top; |
|
865 |
|
866 // Get win_entry |
|
867 if (!current_buddy) |
|
868 return; |
|
869 jid = CURRENT_JID; |
|
870 if (!jid) |
|
871 return; |
|
872 win_entry = scr_SearchWindow(jid); |
|
873 if (!win_entry) |
|
874 return; |
|
875 |
|
876 // Scroll down half a screen (or less) |
|
877 nblines = CHAT_WIN_HEIGHT/2-1; |
|
878 hbuf_top = win_entry->top; |
|
879 |
|
880 for (n=0 ; hbuf_top && n < nblines ; n++) |
|
881 hbuf_top = g_list_next(hbuf_top); |
|
882 win_entry->top = hbuf_top; |
|
883 // Check if we are at the bottom |
|
884 for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) |
|
885 hbuf_top = g_list_next(hbuf_top); |
|
886 if (!hbuf_top) |
|
887 win_entry->top = NULL; // End reached |
|
888 |
|
889 // Refresh the window |
|
890 scr_UpdateWindow(win_entry); |
|
891 |
|
892 // Finished :) |
|
893 update_panels(); |
|
894 doupdate(); |
|
895 } |
|
896 |
143
|
897 // scr_Clear() |
|
898 // Clear the current buddy window (used for the /clear command) |
108
|
899 void scr_Clear(void) |
|
900 { |
|
901 const gchar *jid; |
|
902 window_entry_t *win_entry; |
|
903 |
|
904 // Get win_entry |
|
905 if (!current_buddy) |
|
906 return; |
|
907 jid = CURRENT_JID; |
|
908 if (!jid) |
|
909 return; |
|
910 win_entry = scr_SearchWindow(jid); |
|
911 if (!win_entry) |
|
912 return; |
|
913 |
|
914 win_entry->cleared = TRUE; |
109
|
915 win_entry->top = NULL; |
108
|
916 |
|
917 // Refresh the window |
|
918 scr_UpdateWindow(win_entry); |
|
919 |
|
920 // Finished :) |
|
921 update_panels(); |
|
922 doupdate(); |
|
923 } |
|
924 |
44
|
925 // scr_LogPrint(...) |
|
926 // Display a message in the log window. |
24
|
927 void scr_LogPrint(const char *fmt, ...) |
|
928 { |
|
929 time_t timestamp; |
|
930 char *buffer; |
|
931 va_list ap; |
|
932 |
153
|
933 do { |
157
|
934 buffer = (char *) calloc(1, 1024); |
153
|
935 } while (!buffer); |
24
|
936 |
|
937 timestamp = time(NULL); |
|
938 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); |
|
939 wprintw(logWnd, "\n%s", buffer); |
|
940 |
|
941 va_start(ap, fmt); |
153
|
942 vsnprintf(buffer, 1024, fmt, ap); |
24
|
943 va_end(ap); |
|
944 |
|
945 wprintw(logWnd, "%s", buffer); |
|
946 free(buffer); |
|
947 |
|
948 update_panels(); |
|
949 doupdate(); |
|
950 } |
|
951 |
143
|
952 // scr_set_chatmode() |
|
953 // Public fonction to (un)set chatmode... |
129
|
954 inline void scr_set_chatmode(int enable) |
|
955 { |
|
956 chatmode = enable; |
|
957 } |
|
958 |
173
|
959 // scr_cmdhisto_addline() |
|
960 // Add a line to the inputLine history |
|
961 inline void scr_cmdhisto_addline(char *line) |
|
962 { |
|
963 if (!line || !*line) return; |
|
964 |
|
965 cmdhisto = g_list_append(cmdhisto, g_strdup(line)); |
|
966 } |
|
967 |
|
968 // scr_cmdhisto_prev() |
|
969 // Look for previous line beginning w/ the given mask in the inputLine history |
175
|
970 // Returns NULL if none found |
173
|
971 const char *scr_cmdhisto_prev(char *mask, guint len) |
|
972 { |
|
973 GList *hl; |
|
974 if (!cmdhisto_cur) { |
|
975 hl = g_list_last(cmdhisto); |
174
|
976 if (hl) { // backup current line |
|
977 strncpy(cmdhisto_backup, mask, INPUTLINE_LENGTH); |
|
978 } |
173
|
979 } else { |
|
980 hl = g_list_previous(cmdhisto_cur); |
|
981 } |
|
982 while (hl) { |
|
983 if (!strncmp((char*)hl->data, mask, len)) { |
|
984 // Found a match |
|
985 cmdhisto_cur = hl; |
|
986 return (const char*)hl->data; |
|
987 } |
|
988 hl = g_list_previous(hl); |
|
989 } |
|
990 return NULL; |
|
991 } |
|
992 |
|
993 // scr_cmdhisto_next() |
|
994 // Look for next line beginning w/ the given mask in the inputLine history |
175
|
995 // Returns NULL if none found |
173
|
996 const char *scr_cmdhisto_next(char *mask, guint len) |
|
997 { |
|
998 GList *hl; |
|
999 if (!cmdhisto_cur) return NULL; |
|
1000 hl = cmdhisto_cur; |
|
1001 while ((hl = g_list_next(hl)) != NULL) |
|
1002 if (!strncmp((char*)hl->data, mask, len)) { |
|
1003 // Found a match |
|
1004 cmdhisto_cur = hl; |
|
1005 return (const char*)hl->data; |
|
1006 } |
175
|
1007 // If the "backuped" line matches, we'll use it |
|
1008 if (strncmp(cmdhisto_backup, mask, len)) return NULL; // No match |
174
|
1009 cmdhisto_cur = NULL; |
|
1010 return cmdhisto_backup; |
173
|
1011 } |
|
1012 |
98
|
1013 // which_row() |
|
1014 // Tells which row our cursor is in, in the command line. |
|
1015 // -1 -> normal text |
|
1016 // 0 -> command |
|
1017 // 1 -> parameter 1 (etc.) |
102
|
1018 // If > 0, then *p_row is set to the beginning of the row |
|
1019 int which_row(char **p_row) |
98
|
1020 { |
|
1021 int row = -1; |
|
1022 char *p; |
|
1023 int quote = FALSE; |
|
1024 |
|
1025 // Not a command? |
|
1026 if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) |
|
1027 return -1; |
|
1028 |
|
1029 // This is a command |
|
1030 row = 0; |
|
1031 for (p = inputLine ; p < ptr_inputline ; p++) { |
|
1032 if (quote) { |
|
1033 if (*p == '"' && *(p-1) != '\\') |
|
1034 quote = FALSE; |
|
1035 continue; |
|
1036 } |
|
1037 if (*p == '"' && *(p-1) != '\\') { |
|
1038 quote = TRUE; |
121
|
1039 } else if (*p == ' ') { |
|
1040 if (*(p-1) != ' ') |
|
1041 row++; |
102
|
1042 *p_row = p+1; |
|
1043 } |
98
|
1044 } |
|
1045 return row; |
|
1046 } |
|
1047 |
143
|
1048 // scr_insert_text() |
|
1049 // Insert the given text at the current cursor position. |
|
1050 // The cursor is moved. We don't check if the cursor still is in the screen |
|
1051 // after, the caller should do that. |
98
|
1052 void scr_insert_text(const char *text) |
|
1053 { |
|
1054 char tmpLine[INPUTLINE_LENGTH+1]; |
|
1055 int len = strlen(text); |
|
1056 // Check the line isn't too long |
|
1057 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { |
|
1058 scr_LogPrint("Cannot insert text, line too long."); |
|
1059 return; |
|
1060 } |
|
1061 |
|
1062 strcpy(tmpLine, ptr_inputline); |
|
1063 strcpy(ptr_inputline, text); ptr_inputline += len; |
|
1064 strcpy(ptr_inputline, tmpLine); |
|
1065 } |
|
1066 |
143
|
1067 // scr_handle_tab() |
|
1068 // Function called when tab is pressed. |
|
1069 // Initiate or continue a completion... |
98
|
1070 void scr_handle_tab(void) |
|
1071 { |
102
|
1072 int nrow; |
|
1073 char *row; |
|
1074 const char *cchar; |
103
|
1075 guint compl_categ; |
98
|
1076 |
102
|
1077 nrow = which_row(&row); |
98
|
1078 |
103
|
1079 // a) No completion if no leading slash ('cause not a command) |
|
1080 // b) We can't have more than 2 parameters (we use 2 flags) |
|
1081 if (nrow < 0 || nrow > 2) return; |
102
|
1082 |
103
|
1083 if (nrow == 0) { // Command completion |
|
1084 row = &inputLine[1]; |
|
1085 compl_categ = COMPL_CMD; |
|
1086 } else { // Other completion, depending on the command |
|
1087 cmd *com = cmd_get(inputLine); |
|
1088 if (!com || !row) { |
|
1089 scr_LogPrint("I cannot complete that..."); |
|
1090 return; |
|
1091 } |
|
1092 compl_categ = com->completion_flags[nrow-1]; |
|
1093 } |
|
1094 |
|
1095 if (!completion_started) { |
|
1096 GSList *list = compl_get_category_list(compl_categ); |
|
1097 if (list) { |
|
1098 char *prefix = g_strndup(row, ptr_inputline-row); |
|
1099 // Init completion |
|
1100 new_completion(prefix, list); |
|
1101 g_free(prefix); |
|
1102 // Now complete |
98
|
1103 cchar = complete(); |
|
1104 if (cchar) |
|
1105 scr_insert_text(cchar); |
103
|
1106 completion_started = TRUE; |
98
|
1107 } |
103
|
1108 } else { // Completion already initialized |
|
1109 char *c; |
|
1110 guint back = cancel_completion(); |
|
1111 // Remove $back chars |
|
1112 ptr_inputline -= back; |
|
1113 c = ptr_inputline; |
|
1114 for ( ; *c ; c++) |
|
1115 *c = *(c+back); |
|
1116 // Now complete again |
|
1117 cchar = complete(); |
|
1118 if (cchar) |
|
1119 scr_insert_text(cchar); |
102
|
1120 } |
98
|
1121 } |
|
1122 |
|
1123 void scr_cancel_current_completion(void) |
|
1124 { |
|
1125 char *c; |
|
1126 guint back = cancel_completion(); |
|
1127 // Remove $back chars |
|
1128 ptr_inputline -= back; |
|
1129 c = ptr_inputline; |
|
1130 for ( ; *c ; c++) |
|
1131 *c = *(c+back); |
|
1132 } |
|
1133 |
|
1134 void scr_end_current_completion(void) |
|
1135 { |
|
1136 done_completion(); |
|
1137 completion_started = FALSE; |
|
1138 } |
|
1139 |
24
|
1140 // check_offset(int direction) |
|
1141 // Check inputline_offset value, and make sure the cursor is inside the |
|
1142 // screen. |
|
1143 inline void check_offset(int direction) |
|
1144 { |
|
1145 // Left side |
|
1146 if (inputline_offset && direction <= 0) { |
|
1147 while (ptr_inputline <= (char*)&inputLine + inputline_offset) { |
|
1148 if (inputline_offset) { |
|
1149 inputline_offset -= 5; |
|
1150 if (inputline_offset < 0) |
|
1151 inputline_offset = 0; |
|
1152 } |
|
1153 } |
|
1154 } |
|
1155 // Right side |
|
1156 if (direction >= 0) { |
|
1157 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) |
|
1158 inputline_offset += 5; |
|
1159 } |
|
1160 } |
|
1161 |
44
|
1162 // process_key(key) |
|
1163 // Handle the pressed key, in the command line (bottom). |
29
|
1164 int process_key(int key) |
24
|
1165 { |
|
1166 if (isprint(key)) { |
|
1167 char tmpLine[INPUTLINE_LENGTH+1]; |
|
1168 |
|
1169 // Check the line isn't too long |
|
1170 if (strlen(inputLine) >= INPUTLINE_LENGTH) |
|
1171 return 0; |
|
1172 |
|
1173 // Insert char |
|
1174 strcpy(tmpLine, ptr_inputline); |
|
1175 *ptr_inputline++ = key; |
|
1176 strcpy(ptr_inputline, tmpLine); |
|
1177 check_offset(1); |
|
1178 } else { |
|
1179 switch(key) { |
|
1180 case KEY_BACKSPACE: |
|
1181 if (ptr_inputline != (char*)&inputLine) { |
42
|
1182 char *c = --ptr_inputline; |
|
1183 for ( ; *c ; c++) |
|
1184 *c = *(c+1); |
24
|
1185 check_offset(-1); |
|
1186 } |
|
1187 break; |
|
1188 case KEY_DC: |
|
1189 if (*ptr_inputline) |
|
1190 strcpy(ptr_inputline, ptr_inputline+1); |
|
1191 break; |
|
1192 case KEY_LEFT: |
|
1193 if (ptr_inputline != (char*)&inputLine) { |
|
1194 ptr_inputline--; |
|
1195 check_offset(-1); |
|
1196 } |
|
1197 break; |
|
1198 case KEY_RIGHT: |
|
1199 if (*ptr_inputline) |
|
1200 ptr_inputline++; |
|
1201 check_offset(1); |
|
1202 break; |
98
|
1203 case 7: // Ctrl-g |
|
1204 scr_cancel_current_completion(); |
|
1205 scr_end_current_completion(); |
|
1206 check_offset(-1); |
|
1207 break; |
24
|
1208 case 9: // Tab |
98
|
1209 scr_handle_tab(); |
|
1210 check_offset(0); |
24
|
1211 break; |
|
1212 case '\n': // Enter |
29
|
1213 if (process_line(inputLine)) |
24
|
1214 return 255; |
173
|
1215 // Add line to history |
|
1216 scr_cmdhisto_addline(inputLine); |
|
1217 cmdhisto_cur = NULL; |
|
1218 // Reset the line |
24
|
1219 ptr_inputline = inputLine; |
|
1220 *ptr_inputline = 0; |
|
1221 inputline_offset = 0; |
|
1222 break; |
|
1223 case KEY_UP: |
175
|
1224 { |
|
1225 const char *l = scr_cmdhisto_prev(inputLine, |
|
1226 ptr_inputline-inputLine); |
|
1227 if (l) { |
|
1228 strcpy(inputLine, l); |
|
1229 } |
|
1230 } |
24
|
1231 break; |
|
1232 case KEY_DOWN: |
175
|
1233 { |
|
1234 const char *l = scr_cmdhisto_next(inputLine, |
|
1235 ptr_inputline-inputLine); |
|
1236 if (l) { |
|
1237 strcpy(inputLine, l); |
|
1238 } |
|
1239 } |
24
|
1240 break; |
|
1241 case KEY_PPAGE: |
175
|
1242 scr_RosterUp(); |
24
|
1243 break; |
|
1244 case KEY_NPAGE: |
175
|
1245 scr_RosterDown(); |
24
|
1246 break; |
|
1247 case KEY_HOME: |
|
1248 case 1: |
|
1249 ptr_inputline = inputLine; |
|
1250 inputline_offset = 0; |
|
1251 break; |
|
1252 case KEY_END: |
|
1253 case 5: |
|
1254 for (; *ptr_inputline; ptr_inputline++) ; |
|
1255 check_offset(1); |
|
1256 break; |
|
1257 case 21: // Ctrl-u |
|
1258 strcpy(inputLine, ptr_inputline); |
|
1259 ptr_inputline = inputLine; |
|
1260 inputline_offset = 0; |
|
1261 break; |
|
1262 case KEY_EOL: |
|
1263 case 11: // Ctrl-k |
|
1264 *ptr_inputline = 0; |
|
1265 break; |
|
1266 case 16: // Ctrl-p |
175
|
1267 scr_ScrollUp(); |
24
|
1268 break; |
|
1269 case 14: // Ctrl-n |
175
|
1270 scr_ScrollDown(); |
24
|
1271 break; |
|
1272 case 27: // ESC |
|
1273 currentWindow = NULL; |
|
1274 chatmode = FALSE; |
119
|
1275 if (current_buddy) |
|
1276 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
24
|
1277 top_panel(chatPanel); |
|
1278 top_panel(inputPanel); |
157
|
1279 update_panels(); |
24
|
1280 break; |
151
|
1281 case 12: // Ctrl-l |
|
1282 case KEY_RESIZE: |
|
1283 scr_Resize(); |
|
1284 break; |
24
|
1285 default: |
|
1286 scr_LogPrint("Unkown key=%d", key); |
|
1287 } |
|
1288 } |
157
|
1289 if (completion_started && key != 9 && key != KEY_RESIZE) |
98
|
1290 scr_end_current_completion(); |
24
|
1291 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
|
1292 wclrtoeol(inputWnd); |
|
1293 if (*ptr_inputline) { |
|
1294 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); |
|
1295 } |
157
|
1296 if (!update_roster) { |
|
1297 //update_panels(); |
|
1298 doupdate(); |
|
1299 } |
24
|
1300 return 0; |
|
1301 } |