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