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