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