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)
|
185
|
224 hlog_read_history(title, &tmp->hbuf, maxX - ROSTER_WIDTH - PREFIX_WIDTH);
|
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);
|
185
|
291 // NOTE: update PREFIX_WIDTH if you change the date format!!
|
|
292 // You need to set it to the whole prefix length + 1
|
184
|
293 if (line) {
|
|
294 if (line->timestamp) {
|
185
|
295 strftime(date, 35, "%m-%d %H:%M", localtime(&line->timestamp));
|
184
|
296 } else
|
185
|
297 strcpy(date, " ");
|
184
|
298 if (line->flags & HBB_PREFIX_IN)
|
185
|
299 wprintw(win_entry->win, "%.11s <== ", date);
|
184
|
300 else if (line->flags & HBB_PREFIX_OUT)
|
185
|
301 wprintw(win_entry->win, "%.11s --> ", date);
|
75
|
302 else {
|
185
|
303 wprintw(win_entry->win, "%.11s ", date);
|
75
|
304 }
|
184
|
305 wprintw(win_entry->win, "%s", line->text); // line
|
168
|
306 wclrtoeol(win_entry->win);
|
184
|
307 g_free(line->text);
|
168
|
308 } else {
|
|
309 wclrtobot(win_entry->win);
|
|
310 break;
|
75
|
311 }
|
74
|
312 }
|
|
313 g_free(lines);
|
|
314 }
|
|
315
|
143
|
316 // scr_ShowWindow()
|
|
317 // Display the chat window with the given identifier.
|
50
|
318 void scr_ShowWindow(const char *winId)
|
24
|
319 {
|
74
|
320 window_entry_t *win_entry = scr_SearchWindow(winId);
|
|
321
|
181
|
322 if (!win_entry)
|
180
|
323 win_entry = scr_CreateBuddyPanel(winId, FALSE);
|
74
|
324
|
180
|
325 top_panel(win_entry->panel);
|
|
326 currentWindow = win_entry;
|
|
327 chatmode = TRUE;
|
|
328 roster_msg_setflag(winId, FALSE);
|
|
329 roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE);
|
|
330 update_roster = TRUE;
|
74
|
331
|
180
|
332 // Refresh the window
|
|
333 scr_UpdateWindow(win_entry);
|
|
334
|
|
335 // Finished :)
|
|
336 update_panels();
|
142
|
337
|
|
338 top_panel(inputPanel);
|
24
|
339 }
|
|
340
|
143
|
341 // scr_ShowBuddyWindow()
|
|
342 // Display the chat window buffer for the current buddy.
|
24
|
343 void scr_ShowBuddyWindow(void)
|
|
344 {
|
105
|
345 const gchar *jid;
|
140
|
346
|
105
|
347 if (!current_buddy)
|
140
|
348 jid = NULL;
|
|
349 else
|
|
350 jid = CURRENT_JID;
|
|
351
|
|
352 if (!jid) {
|
|
353 top_panel(chatPanel);
|
143
|
354 top_panel(inputPanel);
|
140
|
355 currentWindow = NULL;
|
105
|
356 return;
|
140
|
357 }
|
|
358
|
105
|
359 scr_ShowWindow(jid);
|
24
|
360 }
|
|
361
|
|
362
|
143
|
363 // scr_WriteInWindow()
|
|
364 // Write some text in the winId window (this usually is a jid).
|
|
365 // Lines are splitted when they are too long to fit in the chat window.
|
|
366 // If this window doesn't exist, it is created.
|
184
|
367 void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp,
|
|
368 unsigned int prefix_flags, int force_show)
|
24
|
369 {
|
74
|
370 window_entry_t *win_entry;
|
24
|
371 int dont_show = FALSE;
|
|
372
|
74
|
373 // Look for the window entry.
|
|
374 win_entry = scr_SearchWindow(winId);
|
|
375
|
|
376 // Do we have to really show the window?
|
24
|
377 if (!chatmode)
|
|
378 dont_show = TRUE;
|
74
|
379 else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry))))
|
24
|
380 dont_show = TRUE;
|
|
381
|
74
|
382 // If the window entry doesn't exist yet, let's create it.
|
|
383 if (win_entry == NULL) {
|
151
|
384 win_entry = scr_CreateBuddyPanel(winId, dont_show);
|
24
|
385 }
|
|
386
|
184
|
387 hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags,
|
185
|
388 maxX - ROSTER_WIDTH - PREFIX_WIDTH);
|
74
|
389
|
108
|
390 if (win_entry->cleared) {
|
|
391 win_entry->cleared = 0; // The message must be displayed
|
|
392 win_entry->top = g_list_last(win_entry->hbuf);
|
|
393 }
|
|
394
|
24
|
395 if (!dont_show) {
|
74
|
396 // Show and refresh the window
|
|
397 top_panel(win_entry->panel);
|
|
398 scr_UpdateWindow(win_entry);
|
142
|
399 top_panel(inputPanel);
|
24
|
400 update_panels();
|
|
401 doupdate();
|
|
402 } else {
|
148
|
403 roster_msg_setflag(winId, TRUE);
|
30
|
404 update_roster = TRUE;
|
24
|
405 }
|
|
406 }
|
|
407
|
|
408 void scr_InitCurses(void)
|
|
409 {
|
|
410 initscr();
|
|
411 noecho();
|
|
412 raw();
|
35
|
413 halfdelay(5);
|
24
|
414 start_color();
|
|
415 use_default_colors();
|
|
416
|
|
417 ParseColors();
|
|
418
|
|
419 getmaxyx(stdscr, maxY, maxX);
|
167
|
420 if (maxY < LOG_WIN_HEIGHT+2)
|
|
421 maxY = LOG_WIN_HEIGHT+2;
|
24
|
422 inputLine[0] = 0;
|
|
423 ptr_inputline = inputLine;
|
|
424
|
35
|
425 setlocale(LC_CTYPE, "");
|
24
|
426
|
|
427 return;
|
|
428 }
|
|
429
|
81
|
430 void scr_TerminateCurses(void)
|
|
431 {
|
|
432 clear();
|
|
433 refresh();
|
|
434 endwin();
|
|
435 return;
|
|
436 }
|
|
437
|
151
|
438 // scr_DrawMainWindow()
|
157
|
439 // Set fullinit to TRUE to also create panels. Set it to FALSE for a resize.
|
151
|
440 //
|
|
441 // I think it could be improved a _lot_ but I'm really not an ncurses
|
|
442 // expert... :-\ Mikael.
|
|
443 //
|
|
444 void scr_DrawMainWindow(unsigned int fullinit)
|
24
|
445 {
|
157
|
446 if (fullinit) {
|
|
447 /* Create windows */
|
|
448 rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0);
|
|
449 chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH);
|
|
450 logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0);
|
|
451 logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1);
|
|
452 inputWnd = newwin(1, maxX, maxY-1, 0);
|
168
|
453 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
454 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL));
|
|
455 wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL));
|
|
456 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL));
|
157
|
457 } else {
|
|
458 /* Resize windows */
|
|
459 wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH);
|
|
460 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH);
|
|
461
|
|
462 wresize(logWnd_border, LOG_WIN_HEIGHT, maxX);
|
|
463 wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2);
|
|
464 mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0);
|
|
465 mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1);
|
|
466
|
|
467 wresize(inputWnd, 1, maxX);
|
|
468 mvwin(inputWnd, maxY-1, 0);
|
168
|
469
|
|
470 werase(chatWnd);
|
157
|
471 }
|
151
|
472
|
|
473 /* Draw/init windows */
|
|
474
|
74
|
475 mvwprintw(chatWnd, 0, 0, "This is the status window");
|
24
|
476
|
151
|
477 // - Draw/clear the log window
|
24
|
478 scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0);
|
157
|
479 // Auto-scrolling in log window
|
74
|
480 scrollok(logWnd, TRUE);
|
24
|
481
|
|
482
|
151
|
483 if (fullinit) {
|
157
|
484 // Enable keypad (+ special keys)
|
|
485 keypad(inputWnd, TRUE);
|
|
486
|
151
|
487 // Create panels
|
|
488 rosterPanel = new_panel(rosterWnd);
|
|
489 chatPanel = new_panel(chatWnd);
|
|
490 logPanel_border = new_panel(logWnd_border);
|
|
491 logPanel = new_panel(logWnd);
|
|
492 inputPanel = new_panel(inputWnd);
|
157
|
493 } else {
|
|
494 // Update panels
|
|
495 replace_panel(rosterPanel, rosterWnd);
|
|
496 replace_panel(chatPanel, chatWnd);
|
|
497 replace_panel(logPanel, logWnd);
|
|
498 replace_panel(logPanel_border, logWnd_border);
|
|
499 replace_panel(inputPanel, inputWnd);
|
151
|
500 }
|
|
501
|
|
502 // We'll need to redraw the roster
|
149
|
503 update_roster = TRUE;
|
24
|
504 return;
|
|
505 }
|
|
506
|
151
|
507 // scr_Resize()
|
|
508 // Function called when the window is resized.
|
157
|
509 // - Resize windows
|
151
|
510 // - Rewrap lines in each buddy buffer
|
|
511 void scr_Resize()
|
|
512 {
|
|
513 struct list_head *pos, *n;
|
|
514 window_entry_t *search_entry;
|
|
515 int x, y, lines, cols;
|
|
516
|
|
517 // First, update the global variables
|
|
518 getmaxyx(stdscr, maxY, maxX);
|
167
|
519 if (maxY < LOG_WIN_HEIGHT+2)
|
|
520 maxY = LOG_WIN_HEIGHT+2;
|
151
|
521 // Make sure the cursor stays inside the window
|
|
522 check_offset(0);
|
|
523
|
157
|
524 // Resize windows and update panels
|
151
|
525 scr_DrawMainWindow(FALSE);
|
|
526
|
|
527 // Resize all buddy windows
|
|
528 x = ROSTER_WIDTH;
|
|
529 y = 0;
|
|
530 lines = CHAT_WIN_HEIGHT;
|
|
531 cols = maxX - ROSTER_WIDTH;
|
|
532
|
|
533 list_for_each_safe(pos, n, &window_list) {
|
|
534 search_entry = window_entry(pos);
|
|
535 if (search_entry->win) {
|
157
|
536 // Resize buddy window (no need to move it)
|
|
537 wresize(search_entry->win, lines, cols);
|
168
|
538 werase(search_entry->win);
|
151
|
539 // If a panel exists, replace the old window with the new
|
|
540 if (search_entry->panel) {
|
|
541 replace_panel(search_entry->panel, search_entry->win);
|
|
542 }
|
|
543 // Redo line wrapping
|
|
544 hbuf_rebuild(&search_entry->hbuf,
|
185
|
545 maxX - ROSTER_WIDTH - PREFIX_WIDTH);
|
151
|
546 }
|
|
547 }
|
|
548
|
|
549 // Refresh current buddy window
|
157
|
550 if (chatmode)
|
151
|
551 scr_ShowBuddyWindow();
|
|
552 }
|
|
553
|
143
|
554 // scr_DrawRoster()
|
|
555 // Actually, display the buddylist on the screen.
|
81
|
556 void scr_DrawRoster(void)
|
24
|
557 {
|
81
|
558 static guint offset = 0;
|
|
559 char name[ROSTER_WIDTH];
|
|
560 int maxx, maxy;
|
|
561 GList *buddy;
|
|
562 int i, n;
|
|
563 int rOffset;
|
164
|
564 enum imstatus currentstatus = jb_getstatus();
|
81
|
565
|
123
|
566 // We can reset update_roster
|
|
567 update_roster = FALSE;
|
|
568
|
81
|
569 getmaxyx(rosterWnd, maxy, maxx);
|
|
570 maxx --; // last char is for vertical border
|
|
571 name[ROSTER_WIDTH-7] = 0;
|
|
572
|
|
573 // cleanup of roster window
|
168
|
574 werase(rosterWnd);
|
|
575 // Redraw the vertical line (not very good...)
|
81
|
576 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL));
|
168
|
577 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++)
|
|
578 mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE);
|
81
|
579
|
|
580 // Leave now if buddylist is empty
|
|
581 if (!buddylist) {
|
|
582 offset = 0;
|
123
|
583 update_panels();
|
|
584 doupdate();
|
81
|
585 return;
|
|
586 }
|
|
587
|
84
|
588 // Update offset if necessary
|
|
589 i = g_list_position(buddylist, current_buddy);
|
|
590 if (i == -1) { // This is bad
|
|
591 scr_LogPrint("Doh! Can't find current selected buddy!!");
|
123
|
592 update_panels();
|
|
593 doupdate();
|
84
|
594 return;
|
|
595 } else if (i < offset) {
|
|
596 offset = i;
|
|
597 } else if (i+1 > offset + maxy) {
|
|
598 offset = i + 1 - maxy;
|
|
599 }
|
81
|
600
|
|
601 buddy = buddylist;
|
|
602 rOffset = offset;
|
|
603
|
84
|
604 for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) {
|
81
|
605
|
|
606 char status = '?';
|
|
607 char pending = ' ';
|
|
608 enum imstatus budstate;
|
149
|
609 unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG;
|
|
610 unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP;
|
|
611 unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE;
|
81
|
612
|
|
613 if (rOffset > 0) {
|
|
614 rOffset--;
|
|
615 continue;
|
|
616 }
|
|
617
|
149
|
618 // Display message notice if there is a message flag, but not
|
|
619 // for unfolded groups.
|
|
620 if (ismsg && (!isgrp || ishid)) {
|
81
|
621 pending = '#';
|
|
622 }
|
|
623
|
|
624 budstate = buddy_getstatus(BUDDATA(buddy));
|
164
|
625 if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline)
|
81
|
626 status = imstatus2char[budstate];
|
|
627 if (buddy == current_buddy) {
|
|
628 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL));
|
|
629 // The 3 following lines aim to color the whole line
|
|
630 wmove(rosterWnd, i, 0);
|
|
631 for (n = 0; n < maxx; n++)
|
|
632 waddch(rosterWnd, ' ');
|
|
633 } else {
|
149
|
634 if (pending == '#')
|
139
|
635 wattrset(rosterWnd, COLOR_PAIR(COLOR_NMSG));
|
|
636 else
|
|
637 wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES));
|
81
|
638 }
|
|
639
|
|
640 strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7);
|
149
|
641 if (isgrp) {
|
133
|
642 char *sep;
|
149
|
643 if (ishid)
|
133
|
644 sep = "+++";
|
|
645 else
|
|
646 sep = "---";
|
|
647 mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name);
|
|
648 }
|
126
|
649 else
|
|
650 mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name);
|
84
|
651
|
|
652 i++;
|
81
|
653 }
|
|
654
|
142
|
655 top_panel(inputPanel);
|
81
|
656 update_panels();
|
|
657 doupdate();
|
24
|
658 }
|
|
659
|
184
|
660 void scr_WriteMessage(const char *jid, const char *text, time_t timestamp,
|
|
661 guint prefix_flags)
|
24
|
662 {
|
184
|
663 if (!timestamp) timestamp = time(NULL);
|
|
664
|
|
665 scr_WriteInWindow(jid, text, timestamp, prefix_flags, FALSE);
|
47
|
666 }
|
|
667
|
184
|
668 void scr_WriteIncomingMessage(const char *jidfrom, const char *text,
|
|
669 time_t timestamp)
|
47
|
670 {
|
75
|
671 // FIXME expand tabs / filter out special chars...
|
184
|
672 scr_WriteMessage(jidfrom, text, timestamp, HBB_PREFIX_IN);
|
24
|
673 update_panels();
|
|
674 doupdate();
|
|
675 }
|
|
676
|
50
|
677 void scr_WriteOutgoingMessage(const char *jidto, const char *text)
|
47
|
678 {
|
184
|
679 scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT);
|
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 }
|