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