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