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;
|
173
|
50 static GList *cmdhisto;
|
|
51 static GList *cmdhisto_cur;
|
24
|
52
|
|
53
|
99
|
54 /* Functions */
|
24
|
55
|
74
|
56 int scr_WindowWidth(WINDOW * win)
|
24
|
57 {
|
|
58 int x, y;
|
|
59 getmaxyx(win, y, x);
|
|
60 return x;
|
|
61 }
|
|
62
|
74
|
63 void scr_clear_box(WINDOW *win, int y, int x, int height, int width, int Color)
|
|
64 {
|
|
65 int i, j;
|
|
66
|
|
67 wattrset(win, COLOR_PAIR(Color));
|
|
68 for (i = 0; i < height; i++) {
|
|
69 wmove(win, y + i, x);
|
|
70 for (j = 0; j < width; j++)
|
|
71 wprintw(win, " ");
|
|
72 }
|
|
73 }
|
|
74
|
24
|
75 void scr_draw_box(WINDOW * win, int y, int x, int height, int width,
|
|
76 int Color, chtype box, chtype border)
|
|
77 {
|
|
78 int i, j;
|
|
79
|
|
80 wattrset(win, COLOR_PAIR(Color));
|
|
81 for (i = 0; i < height; i++) {
|
|
82 wmove(win, y + i, x);
|
|
83 for (j = 0; j < width; j++)
|
|
84 if (!i && !j)
|
|
85 waddch(win, border | ACS_ULCORNER);
|
|
86 else if (i == height - 1 && !j)
|
|
87 waddch(win, border | ACS_LLCORNER);
|
|
88 else if (!i && j == width - 1)
|
|
89 waddch(win, box | ACS_URCORNER);
|
|
90 else if (i == height - 1 && j == width - 1)
|
|
91 waddch(win, box | ACS_LRCORNER);
|
|
92 else if (!i)
|
|
93 waddch(win, border | ACS_HLINE);
|
|
94 else if (i == height - 1)
|
|
95 waddch(win, box | ACS_HLINE);
|
|
96 else if (!j)
|
|
97 waddch(win, border | ACS_VLINE);
|
|
98 else if (j == width - 1)
|
|
99 waddch(win, box | ACS_VLINE);
|
|
100 else
|
|
101 waddch(win, box | ' ');
|
|
102 }
|
|
103 }
|
|
104
|
|
105 int FindColor(char *name)
|
|
106 {
|
|
107 if (!strcmp(name, "default"))
|
|
108 return -1;
|
|
109 if (!strcmp(name, "black"))
|
|
110 return COLOR_BLACK;
|
|
111 if (!strcmp(name, "red"))
|
|
112 return COLOR_RED;
|
|
113 if (!strcmp(name, "green"))
|
|
114 return COLOR_GREEN;
|
|
115 if (!strcmp(name, "yellow"))
|
|
116 return COLOR_YELLOW;
|
|
117 if (!strcmp(name, "blue"))
|
|
118 return COLOR_BLUE;
|
|
119 if (!strcmp(name, "magenta"))
|
|
120 return COLOR_MAGENTA;
|
|
121 if (!strcmp(name, "cyan"))
|
|
122 return COLOR_CYAN;
|
|
123 if (!strcmp(name, "white"))
|
|
124 return COLOR_WHITE;
|
|
125
|
|
126 return -1;
|
|
127 }
|
|
128
|
|
129 void ParseColors(void)
|
|
130 {
|
|
131 char *colors[11] = {
|
|
132 "", "",
|
|
133 "borderlines",
|
|
134 "jidonline",
|
139
|
135 "newmsg",
|
24
|
136 "jidofflineselected",
|
|
137 "jidoffline",
|
|
138 "text",
|
|
139 NULL
|
|
140 };
|
|
141
|
|
142 char *tmp = malloc(1024);
|
|
143 char *color1;
|
|
144 char *background = cfg_read("color_background");
|
|
145 char *backselected = cfg_read("color_backselected");
|
|
146 int i = 0;
|
|
147
|
|
148 while (colors[i]) {
|
|
149 sprintf(tmp, "color_%s", colors[i]);
|
|
150 color1 = cfg_read(tmp);
|
|
151
|
|
152 switch (i + 1) {
|
|
153 case 1:
|
|
154 init_pair(1, COLOR_BLACK, COLOR_WHITE);
|
|
155 break;
|
|
156 case 2:
|
|
157 init_pair(2, COLOR_WHITE, COLOR_BLACK);
|
|
158 break;
|
|
159 case 3:
|
|
160 init_pair(3, FindColor(color1), FindColor(background));
|
|
161 break;
|
|
162 case 4:
|
|
163 init_pair(4, FindColor(color1), FindColor(backselected));
|
|
164 break;
|
|
165 case 5:
|
|
166 init_pair(5, FindColor(color1), FindColor(background));
|
|
167 break;
|
|
168 case 6:
|
|
169 init_pair(6, FindColor(color1), FindColor(backselected));
|
|
170 break;
|
|
171 case 7:
|
|
172 init_pair(7, FindColor(color1), FindColor(background));
|
|
173 break;
|
|
174 case 8:
|
|
175 init_pair(8, FindColor(color1), FindColor(background));
|
|
176 break;
|
|
177 }
|
|
178 i++;
|
|
179 }
|
|
180 }
|
|
181
|
|
182
|
151
|
183 window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show)
|
24
|
184 {
|
151
|
185 int x;
|
|
186 int y;
|
|
187 int lines;
|
|
188 int cols;
|
153
|
189 window_entry_t *tmp;
|
|
190
|
|
191 do {
|
|
192 tmp = calloc(1, sizeof(window_entry_t));
|
|
193 } while (!tmp);
|
24
|
194
|
151
|
195 // Dimensions
|
|
196 x = ROSTER_WIDTH;
|
|
197 y = 0;
|
|
198 lines = CHAT_WIN_HEIGHT;
|
|
199 cols = maxX - ROSTER_WIDTH;
|
|
200
|
24
|
201 tmp->win = newwin(lines, cols, y, x);
|
154
|
202 while (!tmp->win) {
|
|
203 usleep(250);
|
|
204 tmp->win = newwin(lines, cols, y, x);
|
|
205 }
|
168
|
206 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL));
|
24
|
207 tmp->panel = new_panel(tmp->win);
|
153
|
208 tmp->name = (char *) calloc(1, 96);
|
|
209 strncpy(tmp->name, title, 96);
|
24
|
210
|
143
|
211 if (!dont_show) {
|
24
|
212 currentWindow = tmp;
|
|
213 } else {
|
|
214 if (currentWindow)
|
|
215 top_panel(currentWindow->panel);
|
|
216 else
|
|
217 top_panel(chatPanel);
|
|
218 }
|
143
|
219 update_panels();
|
24
|
220
|
|
221 list_add_tail(&tmp->list, &window_list);
|
|
222
|
|
223 return tmp;
|
|
224 }
|
|
225
|
50
|
226 window_entry_t *scr_SearchWindow(const char *winId)
|
24
|
227 {
|
|
228 struct list_head *pos, *n;
|
|
229 window_entry_t *search_entry = NULL;
|
|
230
|
|
231 list_for_each_safe(pos, n, &window_list) {
|
|
232 search_entry = window_entry(pos);
|
|
233 if (search_entry->name) {
|
|
234 if (!strcasecmp(search_entry->name, winId)) {
|
|
235 return search_entry;
|
|
236 }
|
|
237 }
|
|
238 }
|
|
239 return NULL;
|
|
240 }
|
|
241
|
143
|
242 // scr_UpdateWindow()
|
|
243 // (Re-)Display the given chat window.
|
74
|
244 void scr_UpdateWindow(window_entry_t *win_entry)
|
|
245 {
|
|
246 int n;
|
|
247 int width;
|
|
248 char **lines;
|
|
249 GList *hbuf_head;
|
|
250
|
108
|
251 width = scr_WindowWidth(win_entry->win);
|
|
252
|
|
253 // Should the window be empty?
|
|
254 if (win_entry->cleared) {
|
168
|
255 werase(win_entry->win);
|
108
|
256 return;
|
|
257 }
|
|
258
|
105
|
259 // win_entry->top is the top message of the screen. If it set to NULL, we
|
|
260 // are displaying the last messages.
|
|
261
|
74
|
262 // We will show the last CHAT_WIN_HEIGHT lines.
|
|
263 // Let's find out where it begins.
|
105
|
264 if (!win_entry->top ||
|
|
265 (g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) {
|
|
266 // Move up CHAT_WIN_HEIGHT lines
|
|
267 win_entry->hbuf = g_list_last(win_entry->hbuf);
|
|
268 hbuf_head = win_entry->hbuf;
|
|
269 win_entry->top = NULL; // (Just to make sure)
|
|
270 n = 0;
|
|
271 while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) {
|
|
272 hbuf_head = g_list_previous(hbuf_head);
|
|
273 n++;
|
|
274 }
|
|
275 } else
|
|
276 hbuf_head = win_entry->top;
|
74
|
277
|
|
278 // Get the last CHAT_WIN_HEIGHT lines.
|
|
279 lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
|
|
280
|
|
281 // Display these lines
|
|
282 for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
|
168
|
283 wmove(win_entry->win, n, 0);
|
75
|
284 if (*(lines+2*n)) {
|
|
285 if (**(lines+2*n))
|
|
286 wprintw(win_entry->win, "%s", *(lines+2*n)); // prefix
|
|
287 else {
|
|
288 wprintw(win_entry->win, " ");
|
|
289 }
|
|
290 wprintw(win_entry->win, "%s", *(lines+2*n+1)); // line
|
168
|
291 wclrtoeol(win_entry->win);
|
|
292 } else {
|
|
293 wclrtobot(win_entry->win);
|
|
294 break;
|
75
|
295 }
|
74
|
296 }
|
|
297 g_free(lines);
|
|
298 }
|
|
299
|
143
|
300 // scr_ShowWindow()
|
|
301 // Display the chat window with the given identifier.
|
50
|
302 void scr_ShowWindow(const char *winId)
|
24
|
303 {
|
74
|
304 window_entry_t *win_entry = scr_SearchWindow(winId);
|
|
305
|
|
306 if (win_entry != NULL) {
|
|
307 top_panel(win_entry->panel);
|
|
308 currentWindow = win_entry;
|
24
|
309 chatmode = TRUE;
|
148
|
310 roster_msg_setflag(winId, FALSE);
|
119
|
311 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE);
|
30
|
312 update_roster = TRUE;
|
74
|
313
|
105
|
314 // Refresh the window
|
74
|
315 scr_UpdateWindow(win_entry);
|
|
316
|
|
317 // Finished :)
|
24
|
318 update_panels();
|
157
|
319 // doupdate(); (update_roster should be enough?)
|
24
|
320 } else {
|
|
321 top_panel(chatPanel);
|
74
|
322 currentWindow = win_entry; // == NULL (current window empty)
|
24
|
323 }
|
142
|
324
|
|
325 top_panel(inputPanel);
|
24
|
326 }
|
|
327
|
143
|
328 // scr_ShowBuddyWindow()
|
|
329 // Display the chat window buffer for the current buddy.
|
24
|
330 void scr_ShowBuddyWindow(void)
|
|
331 {
|
105
|
332 const gchar *jid;
|
140
|
333
|
105
|
334 if (!current_buddy)
|
140
|
335 jid = NULL;
|
|
336 else
|
|
337 jid = CURRENT_JID;
|
|
338
|
|
339 if (!jid) {
|
|
340 top_panel(chatPanel);
|
143
|
341 top_panel(inputPanel);
|
140
|
342 currentWindow = NULL;
|
105
|
343 return;
|
140
|
344 }
|
|
345
|
105
|
346 scr_ShowWindow(jid);
|
24
|
347 }
|
|
348
|
|
349
|
143
|
350 // scr_WriteInWindow()
|
|
351 // Write some text in the winId window (this usually is a jid).
|
|
352 // Lines are splitted when they are too long to fit in the chat window.
|
|
353 // If this window doesn't exist, it is created.
|
75
|
354 void scr_WriteInWindow(const char *winId, const char *text, int TimeStamp,
|
|
355 const char *prefix, int force_show)
|
24
|
356 {
|
75
|
357 char *fullprefix = NULL;
|
74
|
358 window_entry_t *win_entry;
|
24
|
359 int dont_show = FALSE;
|
|
360
|
75
|
361 // Prepare the prefix
|
|
362 if (prefix || TimeStamp) {
|
|
363 if (!prefix) prefix = "";
|
|
364 fullprefix = calloc(1, strlen(prefix)+16);
|
|
365 if (TimeStamp) {
|
|
366 time_t now = time(NULL);
|
|
367 strftime(fullprefix, 12, "[%H:%M] ", localtime(&now));
|
|
368 } else {
|
|
369 strcpy(fullprefix, " ");
|
|
370 }
|
|
371 strcat(fullprefix, prefix);
|
74
|
372 }
|
|
373
|
|
374 // Look for the window entry.
|
|
375 win_entry = scr_SearchWindow(winId);
|
|
376
|
|
377 // Do we have to really show the window?
|
24
|
378 if (!chatmode)
|
|
379 dont_show = TRUE;
|
74
|
380 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry))))
|
24
|
381 dont_show = TRUE;
|
|
382
|
74
|
383 // If the window entry doesn't exist yet, let's create it.
|
|
384 if (win_entry == NULL) {
|
151
|
385 win_entry = scr_CreateBuddyPanel(winId, dont_show);
|
24
|
386 }
|
|
387
|
75
|
388 hbuf_add_line(&win_entry->hbuf, text, fullprefix,
|
74
|
389 maxX - scr_WindowWidth(rosterWnd) - 14);
|
75
|
390 free(fullprefix);
|
74
|
391
|
108
|
392 if (win_entry->cleared) {
|
|
393 win_entry->cleared = 0; // The message must be displayed
|
|
394 win_entry->top = g_list_last(win_entry->hbuf);
|
|
395 }
|
|
396
|
24
|
397 if (!dont_show) {
|
74
|
398 // Show and refresh the window
|
|
399 top_panel(win_entry->panel);
|
|
400 scr_UpdateWindow(win_entry);
|
142
|
401 top_panel(inputPanel);
|
24
|
402 update_panels();
|
|
403 doupdate();
|
|
404 } else {
|
148
|
405 roster_msg_setflag(winId, TRUE);
|
30
|
406 update_roster = TRUE;
|
24
|
407 }
|
|
408 }
|
|
409
|
|
410 void scr_InitCurses(void)
|
|
411 {
|
|
412 initscr();
|
|
413 noecho();
|
|
414 raw();
|
35
|
415 halfdelay(5);
|
24
|
416 start_color();
|
|
417 use_default_colors();
|
|
418
|
|
419 ParseColors();
|
|
420
|
|
421 getmaxyx(stdscr, maxY, maxX);
|
167
|
422 if (maxY < LOG_WIN_HEIGHT+2)
|
|
423 maxY = LOG_WIN_HEIGHT+2;
|
24
|
424 inputLine[0] = 0;
|
|
425 ptr_inputline = inputLine;
|
|
426
|
35
|
427 setlocale(LC_CTYPE, "");
|
24
|
428
|
|
429 return;
|
|
430 }
|
|
431
|
81
|
432 void scr_TerminateCurses(void)
|
|
433 {
|
|
434 clear();
|
|
435 refresh();
|
|
436 endwin();
|
|
437 return;
|
|
438 }
|
|
439
|
151
|
440 // scr_DrawMainWindow()
|
157
|
441 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize.
|
151
|
442 //
|
|
443 // I think it could be improved a _lot_ but I'm really not an ncurses
|
|
444 // expert... :-\ Mikael.
|
|
445 //
|
|
446 void scr_DrawMainWindow(unsigned int fullinit)
|
24
|
447 {
|
157
|
448 if (fullinit) {
|
|
449 /* Create windows */
|
|
450 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
|
|
451 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
|
|
452 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
|
|
453 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
|
|
454 inputWnd = newwin(1, maxX, maxY-1, 0);
|
168
|
455 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
456 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
457 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL));
|
|
458 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
|
157
|
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);
|
168
|
471
|
|
472 werase(chatWnd);
|
157
|
473 }
|
151
|
474
|
|
475 /* Draw/init windows */
|
|
476
|
74
|
477 mvwprintw(chatWnd, 0, 0, "This is the status window");
|
24
|
478
|
151
|
479 // - Draw/clear the log window
|
24
|
480 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
|
157
|
481 // Auto-scrolling in log window
|
74
|
482 scrollok(logWnd, TRUE);
|
24
|
483
|
|
484
|
151
|
485 if (fullinit) {
|
157
|
486 // Enable keypad (+ special keys)
|
|
487 keypad(inputWnd, TRUE);
|
|
488
|
151
|
489 // Create panels
|
|
490 rosterPanel = new_panel(rosterWnd);
|
|
491 chatPanel = new_panel(chatWnd);
|
|
492 logPanel_border = new_panel(logWnd_border);
|
|
493 logPanel = new_panel(logWnd);
|
|
494 inputPanel = new_panel(inputWnd);
|
157
|
495 } else {
|
|
496 // Update panels
|
|
497 replace_panel(rosterPanel, rosterWnd);
|
|
498 replace_panel(chatPanel, chatWnd);
|
|
499 replace_panel(logPanel, logWnd);
|
|
500 replace_panel(logPanel_border, logWnd_border);
|
|
501 replace_panel(inputPanel, inputWnd);
|
151
|
502 }
|
|
503
|
|
504 // We'll need to redraw the roster
|
149
|
505 update_roster = TRUE;
|
24
|
506 return;
|
|
507 }
|
|
508
|
151
|
509 // scr_Resize()
|
|
510 // Function called when the window is resized.
|
157
|
511 // - Resize windows
|
151
|
512 // - Rewrap lines in each buddy buffer
|
|
513 void scr_Resize()
|
|
514 {
|
|
515 struct list_head *pos, *n;
|
|
516 window_entry_t *search_entry;
|
|
517 int x, y, lines, cols;
|
|
518
|
|
519 // First, update the global variables
|
|
520 getmaxyx(stdscr, maxY, maxX);
|
167
|
521 if (maxY < LOG_WIN_HEIGHT+2)
|
|
522 maxY = LOG_WIN_HEIGHT+2;
|
151
|
523 // Make sure the cursor stays inside the window
|
|
524 check_offset(0);
|
|
525
|
157
|
526 // Resize windows and update panels
|
151
|
527 scr_DrawMainWindow(FALSE);
|
|
528
|
|
529 // Resize all buddy windows
|
|
530 x = ROSTER_WIDTH;
|
|
531 y = 0;
|
|
532 lines = CHAT_WIN_HEIGHT;
|
|
533 cols = maxX - ROSTER_WIDTH;
|
|
534
|
|
535 list_for_each_safe(pos, n, &window_list) {
|
|
536 search_entry = window_entry(pos);
|
|
537 if (search_entry->win) {
|
157
|
538 // Resize buddy window (no need to move it)
|
|
539 wresize(search_entry->win, lines, cols);
|
168
|
540 werase(search_entry->win);
|
151
|
541 // If a panel exists, replace the old window with the new
|
|
542 if (search_entry->panel) {
|
|
543 replace_panel(search_entry->panel, search_entry->win);
|
|
544 }
|
|
545 // Redo line wrapping
|
|
546 hbuf_rebuild(&search_entry->hbuf,
|
|
547 maxX - scr_WindowWidth(rosterWnd) - 14);
|
|
548 }
|
|
549 }
|
|
550
|
|
551 // Refresh current buddy window
|
157
|
552 if (chatmode)
|
151
|
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;
|
164
|
566 enum imstatus currentstatus = jb_getstatus();
|
81
|
567
|
123
|
568 // We can reset update_roster
|
|
569 update_roster = FALSE;
|
|
570
|
81
|
571 getmaxyx(rosterWnd, maxy, maxx);
|
|
572 maxx --; // last char is for vertical border
|
|
573 name[ROSTER_WIDTH-7] = 0;
|
|
574
|
|
575 // cleanup of roster window
|
168
|
576 werase(rosterWnd);
|
|
577 // Redraw the vertical line (not very good...)
|
81
|
578 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
|
168
|
579 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++)
|
|
580 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE);
|
81
|
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));
|
164
|
627 if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline)
|
81
|
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
|
153
|
931 do {
|
157
|
932 buffer = (char *) calloc(1, 1024);
|
153
|
933 } while (!buffer);
|
24
|
934
|
|
935 timestamp = time(NULL);
|
|
936 strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp));
|
|
937 wprintw(logWnd, "\n%s", buffer);
|
|
938
|
|
939 va_start(ap, fmt);
|
153
|
940 vsnprintf(buffer, 1024, fmt, ap);
|
24
|
941 va_end(ap);
|
|
942
|
|
943 wprintw(logWnd, "%s", buffer);
|
|
944 free(buffer);
|
|
945
|
|
946 update_panels();
|
|
947 doupdate();
|
|
948 }
|
|
949
|
143
|
950 // scr_set_chatmode()
|
|
951 // Public fonction to (un)set chatmode...
|
129
|
952 inline void scr_set_chatmode(int enable)
|
|
953 {
|
|
954 chatmode = enable;
|
|
955 }
|
|
956
|
173
|
957 // scr_cmdhisto_addline()
|
|
958 // Add a line to the inputLine history
|
|
959 inline void scr_cmdhisto_addline(char *line)
|
|
960 {
|
|
961 if (!line || !*line) return;
|
|
962
|
|
963 cmdhisto = g_list_append(cmdhisto, g_strdup(line));
|
|
964 }
|
|
965
|
|
966 // scr_cmdhisto_prev()
|
|
967 // Look for previous line beginning w/ the given mask in the inputLine history
|
|
968 const char *scr_cmdhisto_prev(char *mask, guint len)
|
|
969 {
|
|
970 GList *hl;
|
|
971 if (!cmdhisto_cur) {
|
|
972 hl = g_list_last(cmdhisto);
|
|
973 } else {
|
|
974 hl = g_list_previous(cmdhisto_cur);
|
|
975 }
|
|
976 while (hl) {
|
|
977 if (!strncmp((char*)hl->data, mask, len)) {
|
|
978 // Found a match
|
|
979 cmdhisto_cur = hl;
|
|
980 return (const char*)hl->data;
|
|
981 }
|
|
982 hl = g_list_previous(hl);
|
|
983 }
|
|
984 return NULL;
|
|
985 }
|
|
986
|
|
987 // scr_cmdhisto_next()
|
|
988 // Look for next line beginning w/ the given mask in the inputLine history
|
|
989 const char *scr_cmdhisto_next(char *mask, guint len)
|
|
990 {
|
|
991 GList *hl;
|
|
992 if (!cmdhisto_cur) return NULL;
|
|
993 hl = cmdhisto_cur;
|
|
994 while ((hl = g_list_next(hl)) != NULL)
|
|
995 if (!strncmp((char*)hl->data, mask, len)) {
|
|
996 // Found a match
|
|
997 cmdhisto_cur = hl;
|
|
998 return (const char*)hl->data;
|
|
999 }
|
|
1000 return NULL;
|
|
1001 }
|
|
1002
|
98
|
1003 // which_row()
|
|
1004 // Tells which row our cursor is in, in the command line.
|
|
1005 // -1 -> normal text
|
|
1006 // 0 -> command
|
|
1007 // 1 -> parameter 1 (etc.)
|
102
|
1008 // If > 0, then *p_row is set to the beginning of the row
|
|
1009 int which_row(char **p_row)
|
98
|
1010 {
|
|
1011 int row = -1;
|
|
1012 char *p;
|
|
1013 int quote = FALSE;
|
|
1014
|
|
1015 // Not a command?
|
|
1016 if ((ptr_inputline == inputLine) || (inputLine[0] != '/'))
|
|
1017 return -1;
|
|
1018
|
|
1019 // This is a command
|
|
1020 row = 0;
|
|
1021 for (p = inputLine ; p < ptr_inputline ; p++) {
|
|
1022 if (quote) {
|
|
1023 if (*p == '"' && *(p-1) != '\\')
|
|
1024 quote = FALSE;
|
|
1025 continue;
|
|
1026 }
|
|
1027 if (*p == '"' && *(p-1) != '\\') {
|
|
1028 quote = TRUE;
|
121
|
1029 } else if (*p == ' ') {
|
|
1030 if (*(p-1) != ' ')
|
|
1031 row++;
|
102
|
1032 *p_row = p+1;
|
|
1033 }
|
98
|
1034 }
|
|
1035 return row;
|
|
1036 }
|
|
1037
|
143
|
1038 // scr_insert_text()
|
|
1039 // Insert the given text at the current cursor position.
|
|
1040 // The cursor is moved. We don't check if the cursor still is in the screen
|
|
1041 // after, the caller should do that.
|
98
|
1042 void scr_insert_text(const char *text)
|
|
1043 {
|
|
1044 char tmpLine[INPUTLINE_LENGTH+1];
|
|
1045 int len = strlen(text);
|
|
1046 // Check the line isn't too long
|
|
1047 if (strlen(inputLine) + len >= INPUTLINE_LENGTH) {
|
|
1048 scr_LogPrint("Cannot insert text, line too long.");
|
|
1049 return;
|
|
1050 }
|
|
1051
|
|
1052 strcpy(tmpLine, ptr_inputline);
|
|
1053 strcpy(ptr_inputline, text); ptr_inputline += len;
|
|
1054 strcpy(ptr_inputline, tmpLine);
|
|
1055 }
|
|
1056
|
143
|
1057 // scr_handle_tab()
|
|
1058 // Function called when tab is pressed.
|
|
1059 // Initiate or continue a completion...
|
98
|
1060 void scr_handle_tab(void)
|
|
1061 {
|
102
|
1062 int nrow;
|
|
1063 char *row;
|
|
1064 const char *cchar;
|
103
|
1065 guint compl_categ;
|
98
|
1066
|
102
|
1067 nrow = which_row(&row);
|
98
|
1068
|
103
|
1069 // a) No completion if no leading slash ('cause not a command)
|
|
1070 // b) We can't have more than 2 parameters (we use 2 flags)
|
|
1071 if (nrow < 0 || nrow > 2) return;
|
102
|
1072
|
103
|
1073 if (nrow == 0) { // Command completion
|
|
1074 row = &inputLine[1];
|
|
1075 compl_categ = COMPL_CMD;
|
|
1076 } else { // Other completion, depending on the command
|
|
1077 cmd *com = cmd_get(inputLine);
|
|
1078 if (!com || !row) {
|
|
1079 scr_LogPrint("I cannot complete that...");
|
|
1080 return;
|
|
1081 }
|
|
1082 compl_categ = com->completion_flags[nrow-1];
|
|
1083 }
|
|
1084
|
|
1085 if (!completion_started) {
|
|
1086 GSList *list = compl_get_category_list(compl_categ);
|
|
1087 if (list) {
|
|
1088 char *prefix = g_strndup(row, ptr_inputline-row);
|
|
1089 // Init completion
|
|
1090 new_completion(prefix, list);
|
|
1091 g_free(prefix);
|
|
1092 // Now complete
|
98
|
1093 cchar = complete();
|
|
1094 if (cchar)
|
|
1095 scr_insert_text(cchar);
|
103
|
1096 completion_started = TRUE;
|
98
|
1097 }
|
103
|
1098 } else { // Completion already initialized
|
|
1099 char *c;
|
|
1100 guint back = cancel_completion();
|
|
1101 // Remove $back chars
|
|
1102 ptr_inputline -= back;
|
|
1103 c = ptr_inputline;
|
|
1104 for ( ; *c ; c++)
|
|
1105 *c = *(c+back);
|
|
1106 // Now complete again
|
|
1107 cchar = complete();
|
|
1108 if (cchar)
|
|
1109 scr_insert_text(cchar);
|
102
|
1110 }
|
98
|
1111 }
|
|
1112
|
|
1113 void scr_cancel_current_completion(void)
|
|
1114 {
|
|
1115 char *c;
|
|
1116 guint back = cancel_completion();
|
|
1117 // Remove $back chars
|
|
1118 ptr_inputline -= back;
|
|
1119 c = ptr_inputline;
|
|
1120 for ( ; *c ; c++)
|
|
1121 *c = *(c+back);
|
|
1122 }
|
|
1123
|
|
1124 void scr_end_current_completion(void)
|
|
1125 {
|
|
1126 done_completion();
|
|
1127 completion_started = FALSE;
|
|
1128 }
|
|
1129
|
24
|
1130 // check_offset(int direction)
|
|
1131 // Check inputline_offset value, and make sure the cursor is inside the
|
|
1132 // screen.
|
|
1133 inline void check_offset(int direction)
|
|
1134 {
|
|
1135 // Left side
|
|
1136 if (inputline_offset && direction <= 0) {
|
|
1137 while (ptr_inputline <= (char*)&inputLine + inputline_offset) {
|
|
1138 if (inputline_offset) {
|
|
1139 inputline_offset -= 5;
|
|
1140 if (inputline_offset < 0)
|
|
1141 inputline_offset = 0;
|
|
1142 }
|
|
1143 }
|
|
1144 }
|
|
1145 // Right side
|
|
1146 if (direction >= 0) {
|
|
1147 while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX)
|
|
1148 inputline_offset += 5;
|
|
1149 }
|
|
1150 }
|
|
1151
|
44
|
1152 // process_key(key)
|
|
1153 // Handle the pressed key, in the command line (bottom).
|
29
|
1154 int process_key(int key)
|
24
|
1155 {
|
|
1156 if (isprint(key)) {
|
|
1157 char tmpLine[INPUTLINE_LENGTH+1];
|
|
1158
|
|
1159 // Check the line isn't too long
|
|
1160 if (strlen(inputLine) >= INPUTLINE_LENGTH)
|
|
1161 return 0;
|
|
1162
|
|
1163 // Insert char
|
|
1164 strcpy(tmpLine, ptr_inputline);
|
|
1165 *ptr_inputline++ = key;
|
|
1166 strcpy(ptr_inputline, tmpLine);
|
|
1167 check_offset(1);
|
|
1168 } else {
|
|
1169 switch(key) {
|
|
1170 case KEY_BACKSPACE:
|
|
1171 if (ptr_inputline != (char*)&inputLine) {
|
42
|
1172 char *c = --ptr_inputline;
|
|
1173 for ( ; *c ; c++)
|
|
1174 *c = *(c+1);
|
24
|
1175 check_offset(-1);
|
|
1176 }
|
|
1177 break;
|
|
1178 case KEY_DC:
|
|
1179 if (*ptr_inputline)
|
|
1180 strcpy(ptr_inputline, ptr_inputline+1);
|
|
1181 break;
|
|
1182 case KEY_LEFT:
|
|
1183 if (ptr_inputline != (char*)&inputLine) {
|
|
1184 ptr_inputline--;
|
|
1185 check_offset(-1);
|
|
1186 }
|
|
1187 break;
|
|
1188 case KEY_RIGHT:
|
|
1189 if (*ptr_inputline)
|
|
1190 ptr_inputline++;
|
|
1191 check_offset(1);
|
|
1192 break;
|
98
|
1193 case 7: // Ctrl-g
|
|
1194 scr_cancel_current_completion();
|
|
1195 scr_end_current_completion();
|
|
1196 check_offset(-1);
|
|
1197 break;
|
24
|
1198 case 9: // Tab
|
98
|
1199 scr_handle_tab();
|
|
1200 check_offset(0);
|
24
|
1201 break;
|
|
1202 case '\n': // Enter
|
29
|
1203 if (process_line(inputLine))
|
24
|
1204 return 255;
|
173
|
1205 // Add line to history
|
|
1206 scr_cmdhisto_addline(inputLine);
|
|
1207 cmdhisto_cur = NULL;
|
|
1208 // Reset the line
|
24
|
1209 ptr_inputline = inputLine;
|
|
1210 *ptr_inputline = 0;
|
|
1211 inputline_offset = 0;
|
|
1212 break;
|
|
1213 case KEY_UP:
|
81
|
1214 scr_RosterUp();
|
24
|
1215 break;
|
|
1216 case KEY_DOWN:
|
81
|
1217 scr_RosterDown();
|
24
|
1218 break;
|
|
1219 case KEY_PPAGE:
|
105
|
1220 scr_ScrollUp();
|
24
|
1221 break;
|
|
1222 case KEY_NPAGE:
|
105
|
1223 scr_ScrollDown();
|
24
|
1224 break;
|
|
1225 case KEY_HOME:
|
|
1226 case 1:
|
|
1227 ptr_inputline = inputLine;
|
|
1228 inputline_offset = 0;
|
|
1229 break;
|
|
1230 case KEY_END:
|
|
1231 case 5:
|
|
1232 for (; *ptr_inputline; ptr_inputline++) ;
|
|
1233 check_offset(1);
|
|
1234 break;
|
|
1235 case 21: // Ctrl-u
|
|
1236 strcpy(inputLine, ptr_inputline);
|
|
1237 ptr_inputline = inputLine;
|
|
1238 inputline_offset = 0;
|
|
1239 break;
|
|
1240 case KEY_EOL:
|
|
1241 case 11: // Ctrl-k
|
|
1242 *ptr_inputline = 0;
|
|
1243 break;
|
|
1244 case 16: // Ctrl-p
|
173
|
1245 {
|
|
1246 const char *l = scr_cmdhisto_prev(inputLine,
|
|
1247 ptr_inputline-inputLine);
|
|
1248 if (l) {
|
|
1249 strcpy(inputLine, l);
|
|
1250 }
|
|
1251 }
|
24
|
1252 break;
|
|
1253 case 14: // Ctrl-n
|
173
|
1254 {
|
|
1255 const char *l = scr_cmdhisto_next(inputLine,
|
|
1256 ptr_inputline-inputLine);
|
|
1257 if (l) {
|
|
1258 strcpy(inputLine, l);
|
|
1259 }
|
|
1260 }
|
24
|
1261 break;
|
|
1262 case 27: // ESC
|
|
1263 currentWindow = NULL;
|
|
1264 chatmode = FALSE;
|
119
|
1265 if (current_buddy)
|
|
1266 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE);
|
24
|
1267 top_panel(chatPanel);
|
|
1268 top_panel(inputPanel);
|
157
|
1269 update_panels();
|
24
|
1270 break;
|
151
|
1271 case 12: // Ctrl-l
|
|
1272 case KEY_RESIZE:
|
|
1273 scr_Resize();
|
|
1274 break;
|
24
|
1275 default:
|
|
1276 scr_LogPrint("Unkown key=%d", key);
|
|
1277 }
|
|
1278 }
|
157
|
1279 if (completion_started && key != 9 && key != KEY_RESIZE)
|
98
|
1280 scr_end_current_completion();
|
24
|
1281 mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset);
|
|
1282 wclrtoeol(inputWnd);
|
|
1283 if (*ptr_inputline) {
|
|
1284 wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset);
|
|
1285 }
|
157
|
1286 if (!update_roster) {
|
|
1287 //update_panels();
|
|
1288 doupdate();
|
|
1289 }
|
24
|
1290 return 0;
|
|
1291 }
|