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