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