author | Mikael Berthe <mikael@lilotux.net> |
Sun, 24 Jul 2005 22:56:42 +0100 | |
changeset 370 | dd9e2eb52916 |
parent 369 | 499170ed71c9 |
child 373 | af2f8ddf6a1b |
permissions | -rw-r--r-- |
307 | 1 |
/* |
2 |
* screen.c -- UI stuff |
|
3 |
* |
|
4 |
* Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
|
5 |
* Parts of this file come from the Cabber project <cabber@ajmacias.com> |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or modify |
|
8 |
* it under the terms of the GNU General Public License as published by |
|
9 |
* the Free Software Foundation; either version 2 of the License, or (at |
|
10 |
* your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, but |
|
13 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
* General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
20 |
* USA |
|
21 |
*/ |
|
22 |
||
24 | 23 |
#include <stdio.h> |
24 |
#include <stdlib.h> |
|
25 |
#include <string.h> |
|
26 |
#include <ncurses.h> |
|
27 |
#include <panel.h> |
|
28 |
#include <time.h> |
|
29 |
#include <ctype.h> |
|
30 |
#include <locale.h> |
|
232 | 31 |
#include <langinfo.h> |
24 | 32 |
|
33 |
#include "screen.h" |
|
81 | 34 |
#include "hbuf.h" |
47 | 35 |
#include "commands.h" |
95 | 36 |
#include "compl.h" |
81 | 37 |
#include "roster.h" |
180 | 38 |
#include "histolog.h" |
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
276
diff
changeset
|
39 |
#include "settings.h" |
81 | 40 |
#include "utils.h" |
24 | 41 |
#include "list.h" |
42 |
||
43 |
#define window_entry(n) list_entry(n, window_entry_t, list) |
|
44 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
45 |
static inline void check_offset(int); |
151 | 46 |
|
24 | 47 |
LIST_HEAD(window_list); |
48 |
||
49 |
typedef struct _window_entry_t { |
|
50 |
WINDOW *win; |
|
108 | 51 |
PANEL *panel; |
52 |
char *name; |
|
53 |
GList *hbuf; |
|
181 | 54 |
GList *top; // If top is NULL, we'll display the last lines |
55 |
char cleared; // For ex, user has issued a /clear command... |
|
24 | 56 |
struct list_head list; |
57 |
} window_entry_t; |
|
58 |
||
59 |
||
60 |
static WINDOW *rosterWnd, *chatWnd, *inputWnd; |
|
61 |
static WINDOW *logWnd, *logWnd_border; |
|
62 |
static PANEL *rosterPanel, *chatPanel, *inputPanel; |
|
63 |
static PANEL *logPanel, *logPanel_border; |
|
64 |
static int maxY, maxX; |
|
65 |
static window_entry_t *currentWindow; |
|
66 |
||
67 |
static int chatmode; |
|
238 | 68 |
static int multimode; |
69 |
static char *multiline; |
|
30 | 70 |
int update_roster; |
232 | 71 |
int utf8_mode = 0; |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
72 |
static bool Autoaway; |
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
73 |
static bool Curses; |
24 | 74 |
|
174 | 75 |
static char inputLine[INPUTLINE_LENGTH+1]; |
76 |
static char *ptr_inputline; |
|
77 |
static short int inputline_offset; |
|
78 |
static int completion_started; |
|
173 | 79 |
static GList *cmdhisto; |
80 |
static GList *cmdhisto_cur; |
|
174 | 81 |
static char cmdhisto_backup[INPUTLINE_LENGTH+1]; |
24 | 82 |
|
83 |
||
99 | 84 |
/* Functions */ |
24 | 85 |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
86 |
static int scr_WindowWidth(WINDOW * win) |
24 | 87 |
{ |
88 |
int x, y; |
|
89 |
getmaxyx(win, y, x); |
|
90 |
return x; |
|
91 |
} |
|
92 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
93 |
static void scr_draw_box(WINDOW * win, int y, int x, int height, int width, |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
94 |
int Color, chtype box, chtype border) |
24 | 95 |
{ |
96 |
int i, j; |
|
97 |
||
98 |
wattrset(win, COLOR_PAIR(Color)); |
|
99 |
for (i = 0; i < height; i++) { |
|
100 |
wmove(win, y + i, x); |
|
101 |
for (j = 0; j < width; j++) |
|
102 |
if (!i && !j) |
|
103 |
waddch(win, border | ACS_ULCORNER); |
|
104 |
else if (i == height - 1 && !j) |
|
105 |
waddch(win, border | ACS_LLCORNER); |
|
106 |
else if (!i && j == width - 1) |
|
107 |
waddch(win, box | ACS_URCORNER); |
|
108 |
else if (i == height - 1 && j == width - 1) |
|
109 |
waddch(win, box | ACS_LRCORNER); |
|
110 |
else if (!i) |
|
111 |
waddch(win, border | ACS_HLINE); |
|
112 |
else if (i == height - 1) |
|
113 |
waddch(win, box | ACS_HLINE); |
|
114 |
else if (!j) |
|
115 |
waddch(win, border | ACS_VLINE); |
|
116 |
else if (j == width - 1) |
|
117 |
waddch(win, box | ACS_VLINE); |
|
118 |
else |
|
119 |
waddch(win, box | ' '); |
|
120 |
} |
|
121 |
} |
|
122 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
123 |
static int FindColor(const char *name) |
24 | 124 |
{ |
125 |
if (!strcmp(name, "default")) |
|
126 |
return -1; |
|
127 |
if (!strcmp(name, "black")) |
|
128 |
return COLOR_BLACK; |
|
129 |
if (!strcmp(name, "red")) |
|
130 |
return COLOR_RED; |
|
131 |
if (!strcmp(name, "green")) |
|
132 |
return COLOR_GREEN; |
|
133 |
if (!strcmp(name, "yellow")) |
|
134 |
return COLOR_YELLOW; |
|
135 |
if (!strcmp(name, "blue")) |
|
136 |
return COLOR_BLUE; |
|
137 |
if (!strcmp(name, "magenta")) |
|
138 |
return COLOR_MAGENTA; |
|
139 |
if (!strcmp(name, "cyan")) |
|
140 |
return COLOR_CYAN; |
|
141 |
if (!strcmp(name, "white")) |
|
142 |
return COLOR_WHITE; |
|
143 |
||
144 |
return -1; |
|
145 |
} |
|
146 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
147 |
static void ParseColors(void) |
24 | 148 |
{ |
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
149 |
const char *colors[8] = { |
24 | 150 |
"", "", |
267 | 151 |
"general", |
139 | 152 |
"newmsg", |
267 | 153 |
"rosterselect", |
154 |
"rosternormal", |
|
24 | 155 |
NULL |
156 |
}; |
|
157 |
||
158 |
char *tmp = malloc(1024); |
|
281
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
159 |
const char *color; |
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
160 |
const char *background = settings_opt_get("color_background"); |
f562b9af2de7
Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents:
279
diff
changeset
|
161 |
const char *backselected = settings_opt_get("color_backselected"); |
24 | 162 |
int i = 0; |
163 |
||
267 | 164 |
// Default values |
165 |
if (!background) background = "blue"; |
|
166 |
if (!backselected) backselected = "cyan"; |
|
167 |
||
24 | 168 |
while (colors[i]) { |
169 |
sprintf(tmp, "color_%s", colors[i]); |
|
279
f5dd437c057b
Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
276
diff
changeset
|
170 |
color = settings_opt_get(tmp); |
24 | 171 |
|
172 |
switch (i + 1) { |
|
173 |
case 1: |
|
174 |
init_pair(1, COLOR_BLACK, COLOR_WHITE); |
|
175 |
break; |
|
176 |
case 2: |
|
177 |
init_pair(2, COLOR_WHITE, COLOR_BLACK); |
|
178 |
break; |
|
179 |
case 3: |
|
267 | 180 |
init_pair(3, ((color) ? FindColor(color) : COLOR_WHITE), |
181 |
FindColor(background)); |
|
24 | 182 |
break; |
183 |
case 4: |
|
267 | 184 |
init_pair(4, ((color) ? FindColor(color) : COLOR_RED), |
185 |
FindColor(background)); |
|
24 | 186 |
break; |
187 |
case 5: |
|
267 | 188 |
init_pair(5, ((color) ? FindColor(color) : COLOR_BLACK), |
189 |
FindColor(backselected)); |
|
24 | 190 |
break; |
191 |
case 6: |
|
267 | 192 |
init_pair(6, ((color) ? FindColor(color) : COLOR_MAGENTA), |
193 |
FindColor(background)); |
|
24 | 194 |
break; |
195 |
} |
|
196 |
i++; |
|
197 |
} |
|
198 |
} |
|
199 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
200 |
static window_entry_t *scr_CreateBuddyPanel(const char *title, int dont_show) |
24 | 201 |
{ |
151 | 202 |
int x; |
203 |
int y; |
|
204 |
int lines; |
|
205 |
int cols; |
|
153 | 206 |
window_entry_t *tmp; |
207 |
||
208 |
do { |
|
209 |
tmp = calloc(1, sizeof(window_entry_t)); |
|
210 |
} while (!tmp); |
|
24 | 211 |
|
151 | 212 |
// Dimensions |
213 |
x = ROSTER_WIDTH; |
|
214 |
y = 0; |
|
215 |
lines = CHAT_WIN_HEIGHT; |
|
216 |
cols = maxX - ROSTER_WIDTH; |
|
217 |
||
24 | 218 |
tmp->win = newwin(lines, cols, y, x); |
154 | 219 |
while (!tmp->win) { |
220 |
usleep(250); |
|
221 |
tmp->win = newwin(lines, cols, y, x); |
|
222 |
} |
|
168 | 223 |
wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL)); |
24 | 224 |
tmp->panel = new_panel(tmp->win); |
153 | 225 |
tmp->name = (char *) calloc(1, 96); |
226 |
strncpy(tmp->name, title, 96); |
|
24 | 227 |
|
143 | 228 |
if (!dont_show) { |
24 | 229 |
currentWindow = tmp; |
230 |
} else { |
|
231 |
if (currentWindow) |
|
232 |
top_panel(currentWindow->panel); |
|
233 |
else |
|
234 |
top_panel(chatPanel); |
|
235 |
} |
|
143 | 236 |
update_panels(); |
24 | 237 |
|
181 | 238 |
// Load buddy history from file (if enabled) |
185 | 239 |
hlog_read_history(title, &tmp->hbuf, maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
181 | 240 |
|
24 | 241 |
list_add_tail(&tmp->list, &window_list); |
242 |
||
243 |
return tmp; |
|
244 |
} |
|
245 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
246 |
static window_entry_t *scr_SearchWindow(const char *winId) |
24 | 247 |
{ |
248 |
struct list_head *pos, *n; |
|
249 |
window_entry_t *search_entry = NULL; |
|
250 |
||
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
251 |
if (!winId) return NULL; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
252 |
|
24 | 253 |
list_for_each_safe(pos, n, &window_list) { |
254 |
search_entry = window_entry(pos); |
|
255 |
if (search_entry->name) { |
|
256 |
if (!strcasecmp(search_entry->name, winId)) { |
|
257 |
return search_entry; |
|
258 |
} |
|
259 |
} |
|
260 |
} |
|
261 |
return NULL; |
|
262 |
} |
|
263 |
||
143 | 264 |
// scr_UpdateWindow() |
265 |
// (Re-)Display the given chat window. |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
266 |
static void scr_UpdateWindow(window_entry_t *win_entry) |
74 | 267 |
{ |
268 |
int n; |
|
269 |
int width; |
|
184 | 270 |
hbb_line **lines, *line; |
74 | 271 |
GList *hbuf_head; |
184 | 272 |
char date[32]; |
74 | 273 |
|
108 | 274 |
width = scr_WindowWidth(win_entry->win); |
275 |
||
276 |
// Should the window be empty? |
|
277 |
if (win_entry->cleared) { |
|
168 | 278 |
werase(win_entry->win); |
108 | 279 |
return; |
280 |
} |
|
281 |
||
105 | 282 |
// win_entry->top is the top message of the screen. If it set to NULL, we |
283 |
// are displaying the last messages. |
|
284 |
||
74 | 285 |
// We will show the last CHAT_WIN_HEIGHT lines. |
286 |
// Let's find out where it begins. |
|
105 | 287 |
if (!win_entry->top || |
288 |
(g_list_position(g_list_first(win_entry->hbuf), win_entry->top) == -1)) { |
|
289 |
// Move up CHAT_WIN_HEIGHT lines |
|
290 |
win_entry->hbuf = g_list_last(win_entry->hbuf); |
|
291 |
hbuf_head = win_entry->hbuf; |
|
292 |
win_entry->top = NULL; // (Just to make sure) |
|
293 |
n = 0; |
|
294 |
while (hbuf_head && (n < CHAT_WIN_HEIGHT-1) && g_list_previous(hbuf_head)) { |
|
295 |
hbuf_head = g_list_previous(hbuf_head); |
|
296 |
n++; |
|
297 |
} |
|
298 |
} else |
|
299 |
hbuf_head = win_entry->top; |
|
74 | 300 |
|
301 |
// Get the last CHAT_WIN_HEIGHT lines. |
|
302 |
lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT); |
|
303 |
||
304 |
// Display these lines |
|
305 |
for (n = 0; n < CHAT_WIN_HEIGHT; n++) { |
|
168 | 306 |
wmove(win_entry->win, n, 0); |
184 | 307 |
line = *(lines+n); |
185 | 308 |
// NOTE: update PREFIX_WIDTH if you change the date format!! |
309 |
// You need to set it to the whole prefix length + 1 |
|
184 | 310 |
if (line) { |
311 |
if (line->timestamp) { |
|
185 | 312 |
strftime(date, 35, "%m-%d %H:%M", localtime(&line->timestamp)); |
184 | 313 |
} else |
185 | 314 |
strcpy(date, " "); |
197 | 315 |
if (line->flags & HBB_PREFIX_INFO) { |
316 |
char dir = '*'; |
|
317 |
if (line->flags & HBB_PREFIX_IN) |
|
318 |
dir = '<'; |
|
319 |
else if (line->flags & HBB_PREFIX_OUT) |
|
320 |
dir = '>'; |
|
321 |
wprintw(win_entry->win, "%.11s *%c* ", date, dir); |
|
325
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
322 |
} else if (line->flags & HBB_PREFIX_ERR) { |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
323 |
char dir = '#'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
324 |
if (line->flags & HBB_PREFIX_IN) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
325 |
dir = '<'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
326 |
else if (line->flags & HBB_PREFIX_OUT) |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
327 |
dir = '>'; |
ff6fb51bfd78
Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents:
322
diff
changeset
|
328 |
wprintw(win_entry->win, "%.11s #%c# ", date, dir); |
197 | 329 |
} else if (line->flags & HBB_PREFIX_IN) |
185 | 330 |
wprintw(win_entry->win, "%.11s <== ", date); |
184 | 331 |
else if (line->flags & HBB_PREFIX_OUT) |
185 | 332 |
wprintw(win_entry->win, "%.11s --> ", date); |
75 | 333 |
else { |
185 | 334 |
wprintw(win_entry->win, "%.11s ", date); |
75 | 335 |
} |
184 | 336 |
wprintw(win_entry->win, "%s", line->text); // line |
168 | 337 |
wclrtoeol(win_entry->win); |
184 | 338 |
g_free(line->text); |
168 | 339 |
} else { |
340 |
wclrtobot(win_entry->win); |
|
341 |
break; |
|
75 | 342 |
} |
74 | 343 |
} |
344 |
g_free(lines); |
|
345 |
} |
|
346 |
||
143 | 347 |
// scr_ShowWindow() |
348 |
// Display the chat window with the given identifier. |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
349 |
static void scr_ShowWindow(const char *winId) |
24 | 350 |
{ |
74 | 351 |
window_entry_t *win_entry = scr_SearchWindow(winId); |
352 |
||
181 | 353 |
if (!win_entry) |
180 | 354 |
win_entry = scr_CreateBuddyPanel(winId, FALSE); |
74 | 355 |
|
180 | 356 |
top_panel(win_entry->panel); |
357 |
currentWindow = win_entry; |
|
358 |
chatmode = TRUE; |
|
359 |
roster_msg_setflag(winId, FALSE); |
|
360 |
roster_setflags(winId, ROSTER_FLAG_LOCK, TRUE); |
|
361 |
update_roster = TRUE; |
|
74 | 362 |
|
180 | 363 |
// Refresh the window |
364 |
scr_UpdateWindow(win_entry); |
|
365 |
||
366 |
// Finished :) |
|
367 |
update_panels(); |
|
142 | 368 |
|
369 |
top_panel(inputPanel); |
|
24 | 370 |
} |
371 |
||
143 | 372 |
// scr_ShowBuddyWindow() |
373 |
// Display the chat window buffer for the current buddy. |
|
24 | 374 |
void scr_ShowBuddyWindow(void) |
375 |
{ |
|
105 | 376 |
const gchar *jid; |
140 | 377 |
|
105 | 378 |
if (!current_buddy) |
140 | 379 |
jid = NULL; |
380 |
else |
|
381 |
jid = CURRENT_JID; |
|
382 |
||
383 |
if (!jid) { |
|
384 |
top_panel(chatPanel); |
|
143 | 385 |
top_panel(inputPanel); |
140 | 386 |
currentWindow = NULL; |
105 | 387 |
return; |
140 | 388 |
} |
389 |
||
105 | 390 |
scr_ShowWindow(jid); |
24 | 391 |
} |
392 |
||
393 |
||
143 | 394 |
// scr_WriteInWindow() |
395 |
// Write some text in the winId window (this usually is a jid). |
|
396 |
// Lines are splitted when they are too long to fit in the chat window. |
|
397 |
// If this window doesn't exist, it is created. |
|
184 | 398 |
void scr_WriteInWindow(const char *winId, const char *text, time_t timestamp, |
399 |
unsigned int prefix_flags, int force_show) |
|
24 | 400 |
{ |
74 | 401 |
window_entry_t *win_entry; |
24 | 402 |
int dont_show = FALSE; |
403 |
||
74 | 404 |
// Look for the window entry. |
405 |
win_entry = scr_SearchWindow(winId); |
|
406 |
||
407 |
// Do we have to really show the window? |
|
24 | 408 |
if (!chatmode) |
409 |
dont_show = TRUE; |
|
74 | 410 |
else if ((!force_show) && ((!currentWindow || (currentWindow != win_entry)))) |
24 | 411 |
dont_show = TRUE; |
412 |
||
74 | 413 |
// If the window entry doesn't exist yet, let's create it. |
414 |
if (win_entry == NULL) { |
|
151 | 415 |
win_entry = scr_CreateBuddyPanel(winId, dont_show); |
24 | 416 |
} |
417 |
||
220 | 418 |
// The message must be displayed -> update top pointer |
419 |
if (win_entry->cleared) |
|
420 |
win_entry->top = g_list_last(win_entry->hbuf); |
|
421 |
||
184 | 422 |
hbuf_add_line(&win_entry->hbuf, text, timestamp, prefix_flags, |
185 | 423 |
maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
74 | 424 |
|
108 | 425 |
if (win_entry->cleared) { |
220 | 426 |
win_entry->cleared = FALSE; |
427 |
if (g_list_next(win_entry->top)) |
|
428 |
win_entry->top = g_list_next(win_entry->top); |
|
429 |
} |
|
430 |
||
431 |
// Make sure the last line appears in the window; update top if necessary |
|
432 |
if (win_entry->top) { |
|
433 |
int dist; |
|
434 |
GList *first = g_list_first(win_entry->hbuf); |
|
435 |
dist = g_list_position(first, g_list_last(win_entry->hbuf)) - |
|
436 |
g_list_position(first, win_entry->top); |
|
437 |
if (dist >= CHAT_WIN_HEIGHT) |
|
438 |
win_entry->top = NULL; |
|
108 | 439 |
} |
440 |
||
24 | 441 |
if (!dont_show) { |
74 | 442 |
// Show and refresh the window |
443 |
top_panel(win_entry->panel); |
|
444 |
scr_UpdateWindow(win_entry); |
|
142 | 445 |
top_panel(inputPanel); |
24 | 446 |
update_panels(); |
447 |
doupdate(); |
|
448 |
} else { |
|
148 | 449 |
roster_msg_setflag(winId, TRUE); |
30 | 450 |
update_roster = TRUE; |
24 | 451 |
} |
452 |
} |
|
453 |
||
454 |
void scr_InitCurses(void) |
|
455 |
{ |
|
456 |
initscr(); |
|
457 |
noecho(); |
|
458 |
raw(); |
|
35 | 459 |
halfdelay(5); |
24 | 460 |
start_color(); |
461 |
use_default_colors(); |
|
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
462 |
Curses = TRUE; |
24 | 463 |
|
464 |
ParseColors(); |
|
465 |
||
466 |
getmaxyx(stdscr, maxY, maxX); |
|
167 | 467 |
if (maxY < LOG_WIN_HEIGHT+2) |
468 |
maxY = LOG_WIN_HEIGHT+2; |
|
24 | 469 |
inputLine[0] = 0; |
470 |
ptr_inputline = inputLine; |
|
471 |
||
35 | 472 |
setlocale(LC_CTYPE, ""); |
232 | 473 |
utf8_mode = (strcmp(nl_langinfo(CODESET), "UTF-8") == 0); |
24 | 474 |
|
475 |
return; |
|
476 |
} |
|
477 |
||
81 | 478 |
void scr_TerminateCurses(void) |
479 |
{ |
|
363
913915140ad2
Fix segfault when mcabber receives a KILL signal before entering curses mode
Mikael Berthe <mikael@lilotux.net>
parents:
361
diff
changeset
|
480 |
if (!Curses) return; |
81 | 481 |
clear(); |
482 |
refresh(); |
|
483 |
endwin(); |
|
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
484 |
Curses = FALSE; |
81 | 485 |
return; |
486 |
} |
|
487 |
||
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
488 |
void inline set_autoaway(bool setaway) |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
489 |
{ |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
490 |
static enum imstatus oldstatus; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
491 |
Autoaway = setaway; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
492 |
|
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
493 |
if (setaway) { |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
494 |
const char *msg; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
495 |
oldstatus = jb_getstatus(); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
496 |
msg = settings_opt_get("message_autoaway"); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
497 |
if (!msg) msg = MSG_AUTOAWAY; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
498 |
jb_setstatus(away, msg); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
499 |
} else { |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
500 |
// Back |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
501 |
jb_setstatus(oldstatus, NULL); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
502 |
} |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
503 |
} |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
504 |
|
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
505 |
// Check if we should enter/leave automatic away status |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
506 |
void scr_CheckAutoAway(bool activity) |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
507 |
{ |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
508 |
static time_t LastActivity; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
509 |
enum imstatus cur_st; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
510 |
unsigned int autoaway_timeout = settings_opt_get_int("autoaway"); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
511 |
|
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
512 |
if (Autoaway && activity) set_autoaway(FALSE); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
513 |
if (!autoaway_timeout) return; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
514 |
if (!LastActivity || activity) time(&LastActivity); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
515 |
|
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
516 |
cur_st = jb_getstatus(); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
517 |
// Auto-away is disabled for the following states |
339 | 518 |
if ((cur_st != available) && (cur_st != freeforchat)) |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
519 |
return; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
520 |
|
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
521 |
if (!activity) { |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
522 |
time_t now; |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
523 |
time(&now); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
524 |
if (!Autoaway && (now > LastActivity + autoaway_timeout)) |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
525 |
set_autoaway(TRUE); |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
526 |
} |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
527 |
} |
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
528 |
|
151 | 529 |
// scr_DrawMainWindow() |
157 | 530 |
// Set fullinit to TRUE to also create panels. Set it to FALSE for a resize. |
151 | 531 |
// |
532 |
// I think it could be improved a _lot_ but I'm really not an ncurses |
|
533 |
// expert... :-\ Mikael. |
|
534 |
// |
|
535 |
void scr_DrawMainWindow(unsigned int fullinit) |
|
24 | 536 |
{ |
157 | 537 |
if (fullinit) { |
538 |
/* Create windows */ |
|
539 |
rosterWnd = newwin(CHAT_WIN_HEIGHT, ROSTER_WIDTH, 0, 0); |
|
540 |
chatWnd = newwin(CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH, 0, ROSTER_WIDTH); |
|
541 |
logWnd_border = newwin(LOG_WIN_HEIGHT, maxX, CHAT_WIN_HEIGHT, 0); |
|
542 |
logWnd = newwin(LOG_WIN_HEIGHT-2, maxX-2, CHAT_WIN_HEIGHT+1, 1); |
|
543 |
inputWnd = newwin(1, maxX, maxY-1, 0); |
|
358
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
544 |
if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
545 |
scr_TerminateCurses(); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
546 |
fprintf(stderr, "Cannot create windows!\n"); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
547 |
exit(EXIT_FAILURE); |
6e4e667c5571
Fix a segfault when starting mcabber in a really small terminal
Mikael Berthe <mikael@lilotux.net>
parents:
339
diff
changeset
|
548 |
} |
168 | 549 |
wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
550 |
wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
551 |
wbkgd(logWnd_border, COLOR_PAIR(COLOR_GENERAL)); |
|
552 |
wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); |
|
157 | 553 |
} else { |
554 |
/* Resize windows */ |
|
555 |
wresize(rosterWnd, CHAT_WIN_HEIGHT, ROSTER_WIDTH); |
|
556 |
wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - ROSTER_WIDTH); |
|
557 |
||
558 |
wresize(logWnd_border, LOG_WIN_HEIGHT, maxX); |
|
559 |
wresize(logWnd, LOG_WIN_HEIGHT-2, maxX-2); |
|
560 |
mvwin(logWnd_border, CHAT_WIN_HEIGHT, 0); |
|
561 |
mvwin(logWnd, CHAT_WIN_HEIGHT+1, 1); |
|
562 |
||
563 |
wresize(inputWnd, 1, maxX); |
|
564 |
mvwin(inputWnd, maxY-1, 0); |
|
168 | 565 |
|
566 |
werase(chatWnd); |
|
157 | 567 |
} |
151 | 568 |
|
569 |
/* Draw/init windows */ |
|
570 |
||
74 | 571 |
mvwprintw(chatWnd, 0, 0, "This is the status window"); |
24 | 572 |
|
151 | 573 |
// - Draw/clear the log window |
24 | 574 |
scr_draw_box(logWnd_border, 0, 0, LOG_WIN_HEIGHT, maxX, COLOR_GENERAL, 0, 0); |
157 | 575 |
// Auto-scrolling in log window |
74 | 576 |
scrollok(logWnd, TRUE); |
24 | 577 |
|
578 |
||
151 | 579 |
if (fullinit) { |
157 | 580 |
// Enable keypad (+ special keys) |
581 |
keypad(inputWnd, TRUE); |
|
582 |
||
151 | 583 |
// Create panels |
584 |
rosterPanel = new_panel(rosterWnd); |
|
585 |
chatPanel = new_panel(chatWnd); |
|
586 |
logPanel_border = new_panel(logWnd_border); |
|
587 |
logPanel = new_panel(logWnd); |
|
588 |
inputPanel = new_panel(inputWnd); |
|
232 | 589 |
|
590 |
if (utf8_mode) |
|
591 |
scr_LogPrint("WARNING: UTF-8 not yet supported!"); |
|
157 | 592 |
} else { |
593 |
// Update panels |
|
594 |
replace_panel(rosterPanel, rosterWnd); |
|
595 |
replace_panel(chatPanel, chatWnd); |
|
596 |
replace_panel(logPanel, logWnd); |
|
597 |
replace_panel(logPanel_border, logWnd_border); |
|
598 |
replace_panel(inputPanel, inputWnd); |
|
151 | 599 |
} |
600 |
||
601 |
// We'll need to redraw the roster |
|
149 | 602 |
update_roster = TRUE; |
24 | 603 |
return; |
604 |
} |
|
605 |
||
151 | 606 |
// scr_Resize() |
607 |
// Function called when the window is resized. |
|
157 | 608 |
// - Resize windows |
151 | 609 |
// - Rewrap lines in each buddy buffer |
610 |
void scr_Resize() |
|
611 |
{ |
|
612 |
struct list_head *pos, *n; |
|
613 |
window_entry_t *search_entry; |
|
614 |
int x, y, lines, cols; |
|
615 |
||
616 |
// First, update the global variables |
|
617 |
getmaxyx(stdscr, maxY, maxX); |
|
167 | 618 |
if (maxY < LOG_WIN_HEIGHT+2) |
619 |
maxY = LOG_WIN_HEIGHT+2; |
|
151 | 620 |
// Make sure the cursor stays inside the window |
621 |
check_offset(0); |
|
622 |
||
157 | 623 |
// Resize windows and update panels |
151 | 624 |
scr_DrawMainWindow(FALSE); |
625 |
||
626 |
// Resize all buddy windows |
|
627 |
x = ROSTER_WIDTH; |
|
628 |
y = 0; |
|
629 |
lines = CHAT_WIN_HEIGHT; |
|
630 |
cols = maxX - ROSTER_WIDTH; |
|
631 |
||
632 |
list_for_each_safe(pos, n, &window_list) { |
|
633 |
search_entry = window_entry(pos); |
|
634 |
if (search_entry->win) { |
|
189 | 635 |
GList *rescue_top; |
157 | 636 |
// Resize buddy window (no need to move it) |
637 |
wresize(search_entry->win, lines, cols); |
|
168 | 638 |
werase(search_entry->win); |
151 | 639 |
// If a panel exists, replace the old window with the new |
640 |
if (search_entry->panel) { |
|
641 |
replace_panel(search_entry->panel, search_entry->win); |
|
642 |
} |
|
643 |
// Redo line wrapping |
|
189 | 644 |
rescue_top = hbuf_previous_persistent(search_entry->top); |
151 | 645 |
hbuf_rebuild(&search_entry->hbuf, |
185 | 646 |
maxX - ROSTER_WIDTH - PREFIX_WIDTH); |
189 | 647 |
if (g_list_position(g_list_first(search_entry->hbuf), search_entry->top) == -1) |
648 |
search_entry->top = rescue_top; |
|
151 | 649 |
} |
650 |
} |
|
651 |
||
652 |
// Refresh current buddy window |
|
157 | 653 |
if (chatmode) |
151 | 654 |
scr_ShowBuddyWindow(); |
655 |
} |
|
656 |
||
143 | 657 |
// scr_DrawRoster() |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
658 |
// Display the buddylist (not really the roster) on the screen |
81 | 659 |
void scr_DrawRoster(void) |
24 | 660 |
{ |
81 | 661 |
static guint offset = 0; |
662 |
char name[ROSTER_WIDTH]; |
|
663 |
int maxx, maxy; |
|
664 |
GList *buddy; |
|
665 |
int i, n; |
|
666 |
int rOffset; |
|
164 | 667 |
enum imstatus currentstatus = jb_getstatus(); |
81 | 668 |
|
123 | 669 |
// We can reset update_roster |
670 |
update_roster = FALSE; |
|
671 |
||
81 | 672 |
getmaxyx(rosterWnd, maxy, maxx); |
673 |
maxx --; // last char is for vertical border |
|
674 |
name[ROSTER_WIDTH-7] = 0; |
|
675 |
||
676 |
// cleanup of roster window |
|
168 | 677 |
werase(rosterWnd); |
678 |
// Redraw the vertical line (not very good...) |
|
81 | 679 |
wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); |
168 | 680 |
for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) |
681 |
mvwaddch(rosterWnd, i, ROSTER_WIDTH-1, ACS_VLINE); |
|
81 | 682 |
|
683 |
// Leave now if buddylist is empty |
|
684 |
if (!buddylist) { |
|
685 |
offset = 0; |
|
123 | 686 |
update_panels(); |
687 |
doupdate(); |
|
81 | 688 |
return; |
689 |
} |
|
690 |
||
84 | 691 |
// Update offset if necessary |
692 |
i = g_list_position(buddylist, current_buddy); |
|
693 |
if (i == -1) { // This is bad |
|
694 |
scr_LogPrint("Doh! Can't find current selected buddy!!"); |
|
695 |
return; |
|
696 |
} else if (i < offset) { |
|
697 |
offset = i; |
|
698 |
} else if (i+1 > offset + maxy) { |
|
699 |
offset = i + 1 - maxy; |
|
700 |
} |
|
81 | 701 |
|
702 |
buddy = buddylist; |
|
703 |
rOffset = offset; |
|
704 |
||
84 | 705 |
for (i=0; i<maxy && buddy; buddy = g_list_next(buddy)) { |
81 | 706 |
|
707 |
char status = '?'; |
|
708 |
char pending = ' '; |
|
709 |
enum imstatus budstate; |
|
149 | 710 |
unsigned short ismsg = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_MSG; |
711 |
unsigned short isgrp = buddy_gettype(BUDDATA(buddy)) & ROSTER_TYPE_GROUP; |
|
712 |
unsigned short ishid = buddy_getflags(BUDDATA(buddy)) & ROSTER_FLAG_HIDE; |
|
81 | 713 |
|
714 |
if (rOffset > 0) { |
|
715 |
rOffset--; |
|
716 |
continue; |
|
717 |
} |
|
718 |
||
149 | 719 |
// Display message notice if there is a message flag, but not |
720 |
// for unfolded groups. |
|
721 |
if (ismsg && (!isgrp || ishid)) { |
|
81 | 722 |
pending = '#'; |
723 |
} |
|
724 |
||
725 |
budstate = buddy_getstatus(BUDDATA(buddy)); |
|
164 | 726 |
if (budstate >= 0 && budstate < imstatus_size && currentstatus != offline) |
81 | 727 |
status = imstatus2char[budstate]; |
728 |
if (buddy == current_buddy) { |
|
729 |
wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DESSEL)); |
|
730 |
// The 3 following lines aim to color the whole line |
|
731 |
wmove(rosterWnd, i, 0); |
|
732 |
for (n = 0; n < maxx; n++) |
|
733 |
waddch(rosterWnd, ' '); |
|
734 |
} else { |
|
149 | 735 |
if (pending == '#') |
139 | 736 |
wattrset(rosterWnd, COLOR_PAIR(COLOR_NMSG)); |
737 |
else |
|
738 |
wattrset(rosterWnd, COLOR_PAIR(COLOR_BD_DES)); |
|
81 | 739 |
} |
740 |
||
741 |
strncpy(name, buddy_getname(BUDDATA(buddy)), ROSTER_WIDTH-7); |
|
149 | 742 |
if (isgrp) { |
133 | 743 |
char *sep; |
149 | 744 |
if (ishid) |
133 | 745 |
sep = "+++"; |
746 |
else |
|
747 |
sep = "---"; |
|
748 |
mvwprintw(rosterWnd, i, 0, " %c%s %s", pending, sep, name); |
|
749 |
} |
|
126 | 750 |
else |
751 |
mvwprintw(rosterWnd, i, 0, " %c[%c] %s", pending, status, name); |
|
84 | 752 |
|
753 |
i++; |
|
81 | 754 |
} |
755 |
||
142 | 756 |
top_panel(inputPanel); |
81 | 757 |
update_panels(); |
758 |
doupdate(); |
|
24 | 759 |
} |
760 |
||
184 | 761 |
void scr_WriteMessage(const char *jid, const char *text, time_t timestamp, |
762 |
guint prefix_flags) |
|
24 | 763 |
{ |
184 | 764 |
if (!timestamp) timestamp = time(NULL); |
765 |
||
766 |
scr_WriteInWindow(jid, text, timestamp, prefix_flags, FALSE); |
|
47 | 767 |
} |
768 |
||
190 | 769 |
// If prefix is NULL, HBB_PREFIX_IN is supposed. |
184 | 770 |
void scr_WriteIncomingMessage(const char *jidfrom, const char *text, |
190 | 771 |
time_t timestamp, guint prefix) |
47 | 772 |
{ |
190 | 773 |
if (!prefix) prefix = HBB_PREFIX_IN; |
75 | 774 |
// FIXME expand tabs / filter out special chars... |
190 | 775 |
scr_WriteMessage(jidfrom, text, timestamp, prefix); |
24 | 776 |
update_panels(); |
777 |
doupdate(); |
|
778 |
} |
|
779 |
||
50 | 780 |
void scr_WriteOutgoingMessage(const char *jidto, const char *text) |
47 | 781 |
{ |
184 | 782 |
scr_WriteMessage(jidto, text, 0, HBB_PREFIX_OUT); |
47 | 783 |
scr_ShowWindow(jidto); |
784 |
} |
|
785 |
||
24 | 786 |
int scr_Getch(void) |
787 |
{ |
|
788 |
int ch; |
|
789 |
ch = wgetch(inputWnd); |
|
790 |
return ch; |
|
791 |
} |
|
792 |
||
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
793 |
// set_current_buddy(newbuddy) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
794 |
// Set the current_buddy to newbuddy (if not NULL) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
795 |
// Lock the newbuddy, and unlock the previous current_buddy |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
796 |
static void set_current_buddy(GList *newbuddy) |
24 | 797 |
{ |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
798 |
enum imstatus prev_st = imstatus_size; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
799 |
/* prev_st initialized to imstatus_size, which is used as "undef" value. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
800 |
* We are sure prev_st will get a different status value after the |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
801 |
* buddy_getstatus() call. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
802 |
*/ |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
803 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
804 |
if (!current_buddy || !newbuddy) return; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
805 |
if (newbuddy == current_buddy) return; |
24 | 806 |
|
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
807 |
prev_st = buddy_getstatus(BUDDATA(current_buddy)); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
808 |
buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
330 | 809 |
if (chatmode) |
810 |
alternate_buddy = current_buddy; |
|
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
811 |
current_buddy = newbuddy; |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
812 |
// Lock the buddy in the buddylist if we're in chat mode |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
813 |
if (chatmode) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
814 |
buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
815 |
// We should rebuild the buddylist but not everytime |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
816 |
// Here we check if we were locking a buddy who is actually offline, |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
817 |
// and hide_offline_buddies is TRUE. In which case we need to rebuild. |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
818 |
if (prev_st == offline && buddylist_get_hide_offline_buddies()) |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
819 |
buddylist_build(); |
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
820 |
update_roster = TRUE; |
24 | 821 |
} |
822 |
||
143 | 823 |
// scr_RosterTop() |
824 |
// Go to the first buddy in the buddylist |
|
105 | 825 |
void scr_RosterTop(void) |
104 | 826 |
{ |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
827 |
set_current_buddy(buddylist); |
104 | 828 |
if (chatmode) |
829 |
scr_ShowBuddyWindow(); |
|
830 |
} |
|
831 |
||
143 | 832 |
// scr_RosterBottom() |
833 |
// Go to the last buddy in the buddylist |
|
105 | 834 |
void scr_RosterBottom(void) |
104 | 835 |
{ |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
836 |
set_current_buddy(g_list_last(buddylist)); |
104 | 837 |
if (chatmode) |
838 |
scr_ShowBuddyWindow(); |
|
839 |
} |
|
840 |
||
143 | 841 |
// scr_RosterUp() |
842 |
// Go to the previous buddy in the buddylist |
|
105 | 843 |
void scr_RosterUp(void) |
81 | 844 |
{ |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
845 |
set_current_buddy(g_list_previous(current_buddy)); |
104 | 846 |
if (chatmode) |
847 |
scr_ShowBuddyWindow(); |
|
81 | 848 |
} |
849 |
||
143 | 850 |
// scr_RosterDown() |
851 |
// Go to the next buddy in the buddylist |
|
105 | 852 |
void scr_RosterDown(void) |
81 | 853 |
{ |
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
854 |
set_current_buddy(g_list_next(current_buddy)); |
104 | 855 |
if (chatmode) |
856 |
scr_ShowBuddyWindow(); |
|
81 | 857 |
} |
858 |
||
265 | 859 |
// scr_RosterSearch(str) |
860 |
// Look forward for a buddy with jid/name containing str. |
|
861 |
void scr_RosterSearch(char *str) |
|
862 |
{ |
|
328
83d129adde03
Add set_current_buddy() function, to reduce code duplication
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
863 |
set_current_buddy(buddy_search(str)); |
265 | 864 |
if (chatmode) |
865 |
scr_ShowBuddyWindow(); |
|
866 |
} |
|
867 |
||
236 | 868 |
// scr_RosterUnreadMessage(next) |
869 |
// Go to a new message. If next is not null, try to go to the next new |
|
870 |
// message. If it is not possible or if next is NULL, go to the first new |
|
871 |
// message from unread_list. |
|
872 |
void scr_RosterUnreadMessage(int next) |
|
873 |
{ |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
874 |
gpointer unread_ptr; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
875 |
gpointer refbuddata; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
876 |
gpointer ngroup; |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
877 |
GList *nbuddy; |
236 | 878 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
879 |
if (!current_buddy) return; |
236 | 880 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
881 |
if (next) refbuddata = BUDDATA(current_buddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
882 |
else refbuddata = NULL; |
236 | 883 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
884 |
unread_ptr = unread_msg(refbuddata); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
885 |
if (!unread_ptr) return; |
236 | 886 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
887 |
// If buddy is in a folded group, we need to expand it |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
888 |
ngroup = buddy_getgroup(unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
889 |
if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
890 |
buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
891 |
buddylist_build(); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
892 |
} |
236 | 893 |
|
329
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
894 |
nbuddy = g_list_find(buddylist, unread_ptr); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
895 |
if (nbuddy) { |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
896 |
set_current_buddy(nbuddy); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
897 |
if (chatmode) scr_ShowBuddyWindow(); |
7c53bf62a2a2
scr_RosterUnreadMessage() uses set_current_buddy()
Mikael Berthe <mikael@lilotux.net>
parents:
328
diff
changeset
|
898 |
} else scr_LogPrint("Error: nbuddy == NULL"); |
236 | 899 |
} |
900 |
||
330 | 901 |
// scr_RosterJumpAlternate() |
902 |
// Try to jump to alternate (== previous) buddy |
|
903 |
void scr_RosterJumpAlternate(void) |
|
105 | 904 |
{ |
330 | 905 |
if (!alternate_buddy || g_list_position(buddylist, alternate_buddy) == -1) |
906 |
return; |
|
907 |
set_current_buddy(alternate_buddy); |
|
908 |
if (chatmode) |
|
909 |
scr_ShowBuddyWindow(); |
|
910 |
} |
|
911 |
||
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
912 |
// scr_BufferScrollUpDown() |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
913 |
// Scroll up/down the current buddy window, half a screen. |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
914 |
// (up if updown == -1, down if updown == 1) |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
915 |
void scr_BufferScrollUpDown(int updown) |
105 | 916 |
{ |
917 |
window_entry_t *win_entry; |
|
918 |
int n, nblines; |
|
919 |
GList *hbuf_top; |
|
920 |
||
921 |
// Get win_entry |
|
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
922 |
if (!current_buddy) return; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
923 |
win_entry = scr_SearchWindow(CURRENT_JID); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
924 |
if (!win_entry) return; |
105 | 925 |
|
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
926 |
// Scroll half a screen (or less) |
105 | 927 |
nblines = CHAT_WIN_HEIGHT/2-1; |
928 |
hbuf_top = win_entry->top; |
|
929 |
||
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
930 |
if (updown == -1) { // UP |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
931 |
if (!hbuf_top) { |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
932 |
hbuf_top = g_list_last(win_entry->hbuf); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
933 |
if (!win_entry->cleared) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
934 |
nblines *= 3; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
935 |
else |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
936 |
win_entry->cleared = FALSE; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
937 |
} |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
938 |
for (n=0 ; hbuf_top && n < nblines && g_list_previous(hbuf_top) ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
939 |
hbuf_top = g_list_previous(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
940 |
win_entry->top = hbuf_top; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
941 |
} else { // DOWN |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
942 |
for (n=0 ; hbuf_top && n < nblines ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
943 |
hbuf_top = g_list_next(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
944 |
win_entry->top = hbuf_top; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
945 |
// Check if we are at the bottom |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
946 |
for (n=0 ; hbuf_top && n < CHAT_WIN_HEIGHT-1 ; n++) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
947 |
hbuf_top = g_list_next(hbuf_top); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
948 |
if (!hbuf_top) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
949 |
win_entry->top = NULL; // End reached |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
950 |
} |
105 | 951 |
|
952 |
// Refresh the window |
|
953 |
scr_UpdateWindow(win_entry); |
|
954 |
||
955 |
// Finished :) |
|
956 |
update_panels(); |
|
957 |
doupdate(); |
|
958 |
} |
|
959 |
||
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
960 |
// scr_BufferClear() |
143 | 961 |
// Clear the current buddy window (used for the /clear command) |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
962 |
void scr_BufferClear(void) |
108 | 963 |
{ |
964 |
window_entry_t *win_entry; |
|
965 |
||
966 |
// Get win_entry |
|
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
967 |
if (!current_buddy) return; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
968 |
win_entry = scr_SearchWindow(CURRENT_JID); |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
969 |
if (!win_entry) return; |
108 | 970 |
|
971 |
win_entry->cleared = TRUE; |
|
109 | 972 |
win_entry->top = NULL; |
108 | 973 |
|
974 |
// Refresh the window |
|
975 |
scr_UpdateWindow(win_entry); |
|
976 |
||
977 |
// Finished :) |
|
978 |
update_panels(); |
|
979 |
doupdate(); |
|
980 |
} |
|
981 |
||
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
982 |
// scr_BufferTopBottom() |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
983 |
// Jump to the head/tail of the current buddy window |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
984 |
// (top if topbottom == -1, bottom topbottom == 1) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
985 |
void scr_BufferTopBottom(int topbottom) |
187 | 986 |
{ |
987 |
window_entry_t *win_entry; |
|
988 |
||
989 |
// Get win_entry |
|
990 |
if (!current_buddy) return; |
|
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
991 |
win_entry = scr_SearchWindow(CURRENT_JID); |
187 | 992 |
if (!win_entry) return; |
993 |
||
994 |
win_entry->cleared = FALSE; |
|
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
995 |
if (topbottom == 1) |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
996 |
win_entry->top = NULL; |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
997 |
else |
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
358
diff
changeset
|
998 |
win_entry->top = g_list_first(win_entry->hbuf); |
187 | 999 |
|
1000 |
// Refresh the window |
|
1001 |
scr_UpdateWindow(win_entry); |
|
1002 |
||
1003 |
// Finished :) |
|
1004 |
update_panels(); |
|
1005 |
doupdate(); |
|
1006 |
} |
|
1007 |
||
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1008 |
// scr_BufferSearch(direction, text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1009 |
// Jump to the next line containing text |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1010 |
// (backward search if direction == -1, forward if topbottom == 1) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1011 |
void scr_BufferSearch(int direction, const char *text) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1012 |
{ |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1013 |
window_entry_t *win_entry; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1014 |
GList *current_line, *search_res; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1015 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1016 |
// Get win_entry |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1017 |
if (!current_buddy) return; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1018 |
win_entry = scr_SearchWindow(CURRENT_JID); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1019 |
if (!win_entry) return; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1020 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1021 |
if (win_entry->top) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1022 |
current_line = win_entry->top; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1023 |
else |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1024 |
current_line = g_list_last(win_entry->hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1025 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1026 |
search_res = hbuf_search(current_line, direction, text); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1027 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1028 |
if (search_res) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1029 |
win_entry->cleared = FALSE; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1030 |
win_entry->top = search_res; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1031 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1032 |
// Refresh the window |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1033 |
scr_UpdateWindow(win_entry); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1034 |
|
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1035 |
// Finished :) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1036 |
update_panels(); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1037 |
doupdate(); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1038 |
} else |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1039 |
scr_LogPrint("Search string not found"); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1040 |
} |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
1041 |
|
44 | 1042 |
// scr_LogPrint(...) |
1043 |
// Display a message in the log window. |
|
24 | 1044 |
void scr_LogPrint(const char *fmt, ...) |
1045 |
{ |
|
1046 |
time_t timestamp; |
|
1047 |
char *buffer; |
|
1048 |
va_list ap; |
|
1049 |
||
153 | 1050 |
do { |
157 | 1051 |
buffer = (char *) calloc(1, 1024); |
153 | 1052 |
} while (!buffer); |
24 | 1053 |
|
1054 |
timestamp = time(NULL); |
|
1055 |
strftime(buffer, 64, "[%H:%M:%S] ", localtime(×tamp)); |
|
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1056 |
if (Curses) |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1057 |
wprintw(logWnd, "\n%s", buffer); |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1058 |
else |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1059 |
printf("%s", buffer); |
24 | 1060 |
|
1061 |
va_start(ap, fmt); |
|
153 | 1062 |
vsnprintf(buffer, 1024, fmt, ap); |
24 | 1063 |
va_end(ap); |
1064 |
||
332
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1065 |
if (Curses) { |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1066 |
wprintw(logWnd, "%s", buffer); |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1067 |
update_panels(); |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1068 |
doupdate(); |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1069 |
} else { |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1070 |
printf("%s\n", buffer); |
a1901741890e
scr_LogPrint() can be called before ncurses initialization
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1071 |
} |
24 | 1072 |
free(buffer); |
1073 |
} |
|
1074 |
||
143 | 1075 |
// scr_set_chatmode() |
261 | 1076 |
// Public function to (un)set chatmode... |
129 | 1077 |
inline void scr_set_chatmode(int enable) |
1078 |
{ |
|
1079 |
chatmode = enable; |
|
1080 |
} |
|
1081 |
||
238 | 1082 |
// scr_get_multimode() |
261 | 1083 |
// Public function to get multimode status... |
238 | 1084 |
inline int scr_get_multimode() |
1085 |
{ |
|
1086 |
return multimode; |
|
1087 |
} |
|
1088 |
||
1089 |
// scr_set_multimode() |
|
261 | 1090 |
// Public function to (un)set multimode... |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1091 |
// Convention: |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1092 |
// 0 = disabled / 1 = multimode / 2 = multimode verbatim (commands disabled) |
238 | 1093 |
inline void scr_set_multimode(int enable) |
1094 |
{ |
|
1095 |
if (multiline) { |
|
1096 |
g_free(multiline); |
|
1097 |
multiline = NULL; |
|
1098 |
} |
|
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
252
diff
changeset
|
1099 |
multimode = enable; |
238 | 1100 |
} |
1101 |
||
1102 |
// scr_get_multiline() |
|
261 | 1103 |
// Public function to get the current multi-line. |
238 | 1104 |
inline const char *scr_get_multiline() |
1105 |
{ |
|
1106 |
if (multimode && multiline) |
|
1107 |
return multiline; |
|
1108 |
else |
|
1109 |
return ""; |
|
1110 |
} |
|
1111 |
||
1112 |
// scr_append_multiline(line) |
|
1113 |
// Public function to append a line to the current multi-line message. |
|
1114 |
// Skip empty leading lines. |
|
1115 |
void scr_append_multiline(const char *line) |
|
1116 |
{ |
|
1117 |
static int num; |
|
1118 |
||
1119 |
if (!multimode) { |
|
1120 |
scr_LogPrint("Error: Not in multi-line message mode!"); |
|
1121 |
return; |
|
1122 |
} |
|
1123 |
if (multiline) { |
|
1124 |
int len = strlen(multiline)+strlen(line)+2; |
|
252 | 1125 |
if (len >= HBB_BLOCKSIZE - 1) { |
238 | 1126 |
// We don't handle single messages with size > HBB_BLOCKSIZE |
1127 |
// (see hbuf) |
|
1128 |
scr_LogPrint("Your multi-line message is too big, this line has " |
|
1129 |
"not been added."); |
|
1130 |
scr_LogPrint("Please send this part now..."); |
|
1131 |
return; |
|
1132 |
} |
|
276
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1133 |
if (num >= MULTILINE_MAX_LINE_NUMBER) { |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1134 |
// We don't allow too many lines; however the maximum is arbitrary |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1135 |
// (It should be < 1000 yet) |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1136 |
scr_LogPrint("Your message has too many lines, this one has " |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1137 |
"not been added."); |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1138 |
scr_LogPrint("Please send this part now..."); |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1139 |
return; |
627925d885de
Limit the number of lines in multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
271
diff
changeset
|
1140 |
} |
238 | 1141 |
multiline = g_renew(char, multiline, len); |
1142 |
strcat(multiline, "\n"); |
|
1143 |
strcat(multiline, line); |
|
1144 |
num++; |
|
1145 |
} else { |
|
1146 |
// First message line (we skip leading empty lines) |
|
1147 |
num = 0; |
|
1148 |
if (line[0]) { |
|
1149 |
multiline = g_new(char, strlen(line)+1); |
|
1150 |
strcpy(multiline, line); |
|
1151 |
num++; |
|
1152 |
} else |
|
1153 |
return; |
|
1154 |
} |
|
1155 |
scr_LogPrint("Multi-line mode: line #%d added [%.25s...", num, line); |
|
1156 |
} |
|
1157 |
||
173 | 1158 |
// scr_cmdhisto_addline() |
1159 |
// Add a line to the inputLine history |
|
1160 |
inline void scr_cmdhisto_addline(char *line) |
|
1161 |
{ |
|
1162 |
if (!line || !*line) return; |
|
1163 |
||
1164 |
cmdhisto = g_list_append(cmdhisto, g_strdup(line)); |
|
1165 |
} |
|
1166 |
||
1167 |
// scr_cmdhisto_prev() |
|
1168 |
// Look for previous line beginning w/ the given mask in the inputLine history |
|
175 | 1169 |
// Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1170 |
static const char *scr_cmdhisto_prev(char *mask, guint len) |
173 | 1171 |
{ |
1172 |
GList *hl; |
|
1173 |
if (!cmdhisto_cur) { |
|
1174 |
hl = g_list_last(cmdhisto); |
|
174 | 1175 |
if (hl) { // backup current line |
1176 |
strncpy(cmdhisto_backup, mask, INPUTLINE_LENGTH); |
|
1177 |
} |
|
173 | 1178 |
} else { |
1179 |
hl = g_list_previous(cmdhisto_cur); |
|
1180 |
} |
|
1181 |
while (hl) { |
|
1182 |
if (!strncmp((char*)hl->data, mask, len)) { |
|
1183 |
// Found a match |
|
1184 |
cmdhisto_cur = hl; |
|
1185 |
return (const char*)hl->data; |
|
1186 |
} |
|
1187 |
hl = g_list_previous(hl); |
|
1188 |
} |
|
1189 |
return NULL; |
|
1190 |
} |
|
1191 |
||
1192 |
// scr_cmdhisto_next() |
|
1193 |
// Look for next line beginning w/ the given mask in the inputLine history |
|
175 | 1194 |
// Returns NULL if none found |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1195 |
static const char *scr_cmdhisto_next(char *mask, guint len) |
173 | 1196 |
{ |
1197 |
GList *hl; |
|
1198 |
if (!cmdhisto_cur) return NULL; |
|
1199 |
hl = cmdhisto_cur; |
|
1200 |
while ((hl = g_list_next(hl)) != NULL) |
|
1201 |
if (!strncmp((char*)hl->data, mask, len)) { |
|
1202 |
// Found a match |
|
1203 |
cmdhisto_cur = hl; |
|
1204 |
return (const char*)hl->data; |
|
1205 |
} |
|
175 | 1206 |
// If the "backuped" line matches, we'll use it |
1207 |
if (strncmp(cmdhisto_backup, mask, len)) return NULL; // No match |
|
174 | 1208 |
cmdhisto_cur = NULL; |
1209 |
return cmdhisto_backup; |
|
173 | 1210 |
} |
1211 |
||
195 | 1212 |
// readline_transpose_chars() |
1213 |
// Drag the character before point forward over the character at |
|
1214 |
// point, moving point forward as well. If point is at the end of |
|
1215 |
// the line, then this transposes the two characters before point. |
|
1216 |
void readline_transpose_chars() |
|
1217 |
{ |
|
1218 |
char swp; |
|
1219 |
||
1220 |
if (ptr_inputline == inputLine) return; |
|
1221 |
||
1222 |
if (!*ptr_inputline) { // We're at EOL |
|
1223 |
// If line is only 1 char long, nothing to do... |
|
1224 |
if (ptr_inputline == inputLine+1) return; |
|
1225 |
// Transpose the two previous characters |
|
1226 |
swp = *(ptr_inputline-2); |
|
1227 |
*(ptr_inputline-2) = *(ptr_inputline-1); |
|
1228 |
*(ptr_inputline-1) = swp; |
|
1229 |
} else { |
|
196 | 1230 |
// Swap the two characters before the cursor and move right. |
195 | 1231 |
swp = *(ptr_inputline-1); |
1232 |
*(ptr_inputline-1) = *ptr_inputline; |
|
1233 |
*ptr_inputline++ = swp; |
|
1234 |
check_offset(1); |
|
1235 |
} |
|
1236 |
} |
|
1237 |
||
1238 |
// readline_backward_kill_word() |
|
194 | 1239 |
// Kill the word before the cursor, in input line |
195 | 1240 |
void readline_backward_kill_word() |
194 | 1241 |
{ |
1242 |
char *c, *old = ptr_inputline; |
|
1243 |
int spaceallowed = 1; |
|
1244 |
||
1245 |
if (ptr_inputline == inputLine) return; |
|
1246 |
||
1247 |
for (c = ptr_inputline-1 ; c > inputLine ; c--) |
|
1248 |
if (!isalnum(*c)) { |
|
1249 |
if (*c == ' ') |
|
1250 |
if (!spaceallowed) break; |
|
1251 |
} else spaceallowed = 0; |
|
1252 |
||
1253 |
if (c != inputLine || *c != ' ') |
|
1254 |
if ((c < ptr_inputline-1) && (!isalnum(*c))) |
|
1255 |
c++; |
|
1256 |
||
1257 |
// Modify the line |
|
1258 |
ptr_inputline = c; |
|
1259 |
for (;;) { |
|
1260 |
*c = *old++; |
|
1261 |
if (!*c++) break; |
|
1262 |
} |
|
195 | 1263 |
check_offset(-1); |
194 | 1264 |
} |
1265 |
||
98 | 1266 |
// which_row() |
1267 |
// Tells which row our cursor is in, in the command line. |
|
1268 |
// -1 -> normal text |
|
1269 |
// 0 -> command |
|
1270 |
// 1 -> parameter 1 (etc.) |
|
102 | 1271 |
// If > 0, then *p_row is set to the beginning of the row |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1272 |
static int which_row(char **p_row) |
98 | 1273 |
{ |
1274 |
int row = -1; |
|
1275 |
char *p; |
|
1276 |
int quote = FALSE; |
|
1277 |
||
1278 |
// Not a command? |
|
1279 |
if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) |
|
1280 |
return -1; |
|
1281 |
||
1282 |
// This is a command |
|
1283 |
row = 0; |
|
1284 |
for (p = inputLine ; p < ptr_inputline ; p++) { |
|
1285 |
if (quote) { |
|
1286 |
if (*p == '"' && *(p-1) != '\\') |
|
1287 |
quote = FALSE; |
|
1288 |
continue; |
|
1289 |
} |
|
1290 |
if (*p == '"' && *(p-1) != '\\') { |
|
1291 |
quote = TRUE; |
|
121 | 1292 |
} else if (*p == ' ') { |
1293 |
if (*(p-1) != ' ') |
|
1294 |
row++; |
|
102 | 1295 |
*p_row = p+1; |
1296 |
} |
|
98 | 1297 |
} |
1298 |
return row; |
|
1299 |
} |
|
1300 |
||
143 | 1301 |
// scr_insert_text() |
1302 |
// Insert the given text at the current cursor position. |
|
1303 |
// The cursor is moved. We don't check if the cursor still is in the screen |
|
1304 |
// after, the caller should do that. |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1305 |
static void scr_insert_text(const char *text) |
98 | 1306 |
{ |
1307 |
char tmpLine[INPUTLINE_LENGTH+1]; |
|
1308 |
int len = strlen(text); |
|
1309 |
// Check the line isn't too long |
|
1310 |
if (strlen(inputLine) + len >= INPUTLINE_LENGTH) { |
|
1311 |
scr_LogPrint("Cannot insert text, line too long."); |
|
1312 |
return; |
|
1313 |
} |
|
1314 |
||
1315 |
strcpy(tmpLine, ptr_inputline); |
|
1316 |
strcpy(ptr_inputline, text); ptr_inputline += len; |
|
1317 |
strcpy(ptr_inputline, tmpLine); |
|
1318 |
} |
|
1319 |
||
143 | 1320 |
// scr_handle_tab() |
1321 |
// Function called when tab is pressed. |
|
1322 |
// Initiate or continue a completion... |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1323 |
static void scr_handle_tab(void) |
98 | 1324 |
{ |
102 | 1325 |
int nrow; |
1326 |
char *row; |
|
1327 |
const char *cchar; |
|
103 | 1328 |
guint compl_categ; |
98 | 1329 |
|
102 | 1330 |
nrow = which_row(&row); |
98 | 1331 |
|
103 | 1332 |
// a) No completion if no leading slash ('cause not a command) |
1333 |
// b) We can't have more than 2 parameters (we use 2 flags) |
|
1334 |
if (nrow < 0 || nrow > 2) return; |
|
102 | 1335 |
|
103 | 1336 |
if (nrow == 0) { // Command completion |
1337 |
row = &inputLine[1]; |
|
1338 |
compl_categ = COMPL_CMD; |
|
1339 |
} else { // Other completion, depending on the command |
|
285 | 1340 |
int alias = FALSE; |
1341 |
cmd *com; |
|
1342 |
char *xpline = expandalias(inputLine); |
|
1343 |
com = cmd_get(xpline); |
|
1344 |
if (xpline != inputLine) { |
|
1345 |
// This is an alias, so we can't complete rows > 0 |
|
1346 |
alias = TRUE; |
|
1347 |
g_free(xpline); |
|
1348 |
} |
|
1349 |
if ((!com && (!alias || !completion_started)) || !row) { |
|
103 | 1350 |
scr_LogPrint("I cannot complete that..."); |
1351 |
return; |
|
1352 |
} |
|
285 | 1353 |
if (!alias) |
1354 |
compl_categ = com->completion_flags[nrow-1]; |
|
1355 |
else |
|
1356 |
compl_categ = 0; |
|
103 | 1357 |
} |
1358 |
||
1359 |
if (!completion_started) { |
|
1360 |
GSList *list = compl_get_category_list(compl_categ); |
|
1361 |
if (list) { |
|
1362 |
char *prefix = g_strndup(row, ptr_inputline-row); |
|
1363 |
// Init completion |
|
1364 |
new_completion(prefix, list); |
|
1365 |
g_free(prefix); |
|
1366 |
// Now complete |
|
98 | 1367 |
cchar = complete(); |
1368 |
if (cchar) |
|
1369 |
scr_insert_text(cchar); |
|
103 | 1370 |
completion_started = TRUE; |
98 | 1371 |
} |
103 | 1372 |
} else { // Completion already initialized |
1373 |
char *c; |
|
1374 |
guint back = cancel_completion(); |
|
1375 |
// Remove $back chars |
|
1376 |
ptr_inputline -= back; |
|
1377 |
c = ptr_inputline; |
|
1378 |
for ( ; *c ; c++) |
|
1379 |
*c = *(c+back); |
|
1380 |
// Now complete again |
|
1381 |
cchar = complete(); |
|
1382 |
if (cchar) |
|
1383 |
scr_insert_text(cchar); |
|
102 | 1384 |
} |
98 | 1385 |
} |
1386 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1387 |
static void scr_cancel_current_completion(void) |
98 | 1388 |
{ |
1389 |
char *c; |
|
1390 |
guint back = cancel_completion(); |
|
1391 |
// Remove $back chars |
|
1392 |
ptr_inputline -= back; |
|
1393 |
c = ptr_inputline; |
|
1394 |
for ( ; *c ; c++) |
|
1395 |
*c = *(c+back); |
|
1396 |
} |
|
1397 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1398 |
static void scr_end_current_completion(void) |
98 | 1399 |
{ |
1400 |
done_completion(); |
|
1401 |
completion_started = FALSE; |
|
1402 |
} |
|
1403 |
||
24 | 1404 |
// check_offset(int direction) |
1405 |
// Check inputline_offset value, and make sure the cursor is inside the |
|
1406 |
// screen. |
|
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1407 |
static inline void check_offset(int direction) |
24 | 1408 |
{ |
1409 |
// Left side |
|
1410 |
if (inputline_offset && direction <= 0) { |
|
1411 |
while (ptr_inputline <= (char*)&inputLine + inputline_offset) { |
|
1412 |
if (inputline_offset) { |
|
1413 |
inputline_offset -= 5; |
|
1414 |
if (inputline_offset < 0) |
|
1415 |
inputline_offset = 0; |
|
1416 |
} |
|
1417 |
} |
|
1418 |
} |
|
1419 |
// Right side |
|
1420 |
if (direction >= 0) { |
|
1421 |
while (ptr_inputline >= inputline_offset + (char*)&inputLine + maxX) |
|
1422 |
inputline_offset += 5; |
|
1423 |
} |
|
1424 |
} |
|
1425 |
||
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
332
diff
changeset
|
1426 |
static inline void refresh_inputline(void) |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1427 |
{ |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1428 |
mvwprintw(inputWnd, 0,0, "%s", inputLine + inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1429 |
wclrtoeol(inputWnd); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1430 |
if (*ptr_inputline) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1431 |
wmove(inputWnd, 0, ptr_inputline - (char*)&inputLine - inputline_offset); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1432 |
} |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1433 |
|
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1434 |
void scr_handle_sigint(void) |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1435 |
{ |
365
ddb6593bedc9
Fix segfault when mcabber receives an INT signal (Ctrl-C) early
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1436 |
if (!Curses) return; |
315
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1437 |
// Leave multi-line mode |
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1438 |
process_command("/msay abort"); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1439 |
// Same as Ctrl-g, now |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1440 |
scr_cancel_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1441 |
scr_end_current_completion(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1442 |
check_offset(-1); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1443 |
refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1444 |
} |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1445 |
|
44 | 1446 |
// process_key(key) |
1447 |
// Handle the pressed key, in the command line (bottom). |
|
29 | 1448 |
int process_key(int key) |
24 | 1449 |
{ |
1450 |
if (isprint(key)) { |
|
1451 |
char tmpLine[INPUTLINE_LENGTH+1]; |
|
1452 |
||
1453 |
// Check the line isn't too long |
|
1454 |
if (strlen(inputLine) >= INPUTLINE_LENGTH) |
|
1455 |
return 0; |
|
1456 |
||
1457 |
// Insert char |
|
1458 |
strcpy(tmpLine, ptr_inputline); |
|
1459 |
*ptr_inputline++ = key; |
|
1460 |
strcpy(ptr_inputline, tmpLine); |
|
1461 |
check_offset(1); |
|
1462 |
} else { |
|
1463 |
switch(key) { |
|
232 | 1464 |
case 8: // Ctrl-h |
1465 |
case 127: // Backspace too |
|
24 | 1466 |
case KEY_BACKSPACE: |
1467 |
if (ptr_inputline != (char*)&inputLine) { |
|
42 | 1468 |
char *c = --ptr_inputline; |
1469 |
for ( ; *c ; c++) |
|
1470 |
*c = *(c+1); |
|
24 | 1471 |
check_offset(-1); |
1472 |
} |
|
1473 |
break; |
|
238 | 1474 |
case KEY_DC:// Del |
24 | 1475 |
if (*ptr_inputline) |
1476 |
strcpy(ptr_inputline, ptr_inputline+1); |
|
1477 |
break; |
|
1478 |
case KEY_LEFT: |
|
1479 |
if (ptr_inputline != (char*)&inputLine) { |
|
1480 |
ptr_inputline--; |
|
1481 |
check_offset(-1); |
|
1482 |
} |
|
1483 |
break; |
|
1484 |
case KEY_RIGHT: |
|
1485 |
if (*ptr_inputline) |
|
1486 |
ptr_inputline++; |
|
1487 |
check_offset(1); |
|
1488 |
break; |
|
98 | 1489 |
case 7: // Ctrl-g |
1490 |
scr_cancel_current_completion(); |
|
1491 |
scr_end_current_completion(); |
|
1492 |
check_offset(-1); |
|
1493 |
break; |
|
24 | 1494 |
case 9: // Tab |
98 | 1495 |
scr_handle_tab(); |
1496 |
check_offset(0); |
|
24 | 1497 |
break; |
1498 |
case '\n': // Enter |
|
263 | 1499 |
case 15: // Ctrl-o ("accept-line-and-down-history") |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1500 |
scr_CheckAutoAway(TRUE); |
29 | 1501 |
if (process_line(inputLine)) |
24 | 1502 |
return 255; |
173 | 1503 |
// Add line to history |
1504 |
scr_cmdhisto_addline(inputLine); |
|
1505 |
// Reset the line |
|
24 | 1506 |
ptr_inputline = inputLine; |
1507 |
*ptr_inputline = 0; |
|
1508 |
inputline_offset = 0; |
|
263 | 1509 |
|
1510 |
if (key == '\n') // Enter |
|
1511 |
{ |
|
1512 |
// Reset history line pointer |
|
1513 |
cmdhisto_cur = NULL; |
|
1514 |
} else { // down-history |
|
1515 |
// Use next history line instead of a blank line |
|
1516 |
const char *l = scr_cmdhisto_next("", 0); |
|
1517 |
if (l) |
|
1518 |
strcpy(inputLine, l); |
|
1519 |
// Reset backup history line |
|
1520 |
cmdhisto_backup[0] = 0; |
|
1521 |
} |
|
24 | 1522 |
break; |
1523 |
case KEY_UP: |
|
175 | 1524 |
{ |
1525 |
const char *l = scr_cmdhisto_prev(inputLine, |
|
1526 |
ptr_inputline-inputLine); |
|
1527 |
if (l) { |
|
1528 |
strcpy(inputLine, l); |
|
1529 |
} |
|
1530 |
} |
|
24 | 1531 |
break; |
1532 |
case KEY_DOWN: |
|
175 | 1533 |
{ |
1534 |
const char *l = scr_cmdhisto_next(inputLine, |
|
1535 |
ptr_inputline-inputLine); |
|
1536 |
if (l) { |
|
1537 |
strcpy(inputLine, l); |
|
1538 |
} |
|
1539 |
} |
|
24 | 1540 |
break; |
1541 |
case KEY_PPAGE: |
|
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1542 |
scr_CheckAutoAway(TRUE); |
175 | 1543 |
scr_RosterUp(); |
24 | 1544 |
break; |
1545 |
case KEY_NPAGE: |
|
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1546 |
scr_CheckAutoAway(TRUE); |
175 | 1547 |
scr_RosterDown(); |
24 | 1548 |
break; |
1549 |
case KEY_HOME: |
|
1550 |
case 1: |
|
1551 |
ptr_inputline = inputLine; |
|
1552 |
inputline_offset = 0; |
|
1553 |
break; |
|
1554 |
case KEY_END: |
|
1555 |
case 5: |
|
1556 |
for (; *ptr_inputline; ptr_inputline++) ; |
|
1557 |
check_offset(1); |
|
1558 |
break; |
|
1559 |
case 21: // Ctrl-u |
|
1560 |
strcpy(inputLine, ptr_inputline); |
|
1561 |
ptr_inputline = inputLine; |
|
1562 |
inputline_offset = 0; |
|
1563 |
break; |
|
1564 |
case KEY_EOL: |
|
1565 |
case 11: // Ctrl-k |
|
1566 |
*ptr_inputline = 0; |
|
1567 |
break; |
|
1568 |
case 16: // Ctrl-p |
|
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1569 |
scr_BufferScrollUpDown(-1); |
24 | 1570 |
break; |
1571 |
case 14: // Ctrl-n |
|
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
365
diff
changeset
|
1572 |
scr_BufferScrollUpDown(1); |
24 | 1573 |
break; |
196 | 1574 |
case 17: // Ctrl-q |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1575 |
scr_CheckAutoAway(TRUE); |
236 | 1576 |
scr_RosterUnreadMessage(1); // next unread message |
196 | 1577 |
break; |
195 | 1578 |
case 20: // Ctrl-t |
1579 |
readline_transpose_chars(); |
|
1580 |
break; |
|
194 | 1581 |
case 23: // Ctrl-w |
195 | 1582 |
readline_backward_kill_word(); |
194 | 1583 |
break; |
24 | 1584 |
case 27: // ESC |
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1585 |
scr_CheckAutoAway(TRUE); |
24 | 1586 |
currentWindow = NULL; |
1587 |
chatmode = FALSE; |
|
119 | 1588 |
if (current_buddy) |
1589 |
buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, FALSE); |
|
24 | 1590 |
top_panel(chatPanel); |
1591 |
top_panel(inputPanel); |
|
157 | 1592 |
update_panels(); |
24 | 1593 |
break; |
151 | 1594 |
case 12: // Ctrl-l |
1595 |
case KEY_RESIZE: |
|
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1596 |
scr_CheckAutoAway(TRUE); |
151 | 1597 |
scr_Resize(); |
1598 |
break; |
|
24 | 1599 |
default: |
288 | 1600 |
{ |
1601 |
const gchar *boundcmd = isbound(key); |
|
1602 |
if (boundcmd) { |
|
1603 |
gchar *cmd = g_strdup_printf("/%s", boundcmd); |
|
322
da138cdebf04
Implement auto-away mode
Mikael Berthe <mikael@lilotux.net>
parents:
314
diff
changeset
|
1604 |
scr_CheckAutoAway(TRUE); |
288 | 1605 |
if (process_command(cmd)) |
1606 |
return 255; |
|
1607 |
g_free(cmd); |
|
1608 |
} else { |
|
1609 |
scr_LogPrint("Unknown key=%d", key); |
|
1610 |
if (utf8_mode) |
|
1611 |
scr_LogPrint("WARNING: UTF-8 not yet supported!"); |
|
1612 |
} |
|
1613 |
} |
|
24 | 1614 |
} |
1615 |
} |
|
157 | 1616 |
if (completion_started && key != 9 && key != KEY_RESIZE) |
98 | 1617 |
scr_end_current_completion(); |
312
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1618 |
refresh_inputline(); |
f0b7ff2df7e8
Ctrl-C does not terminate mcabber
Mikael Berthe <mikael@lilotux.net>
parents:
307
diff
changeset
|
1619 |
if (!update_roster) |
157 | 1620 |
doupdate(); |
24 | 1621 |
return 0; |
1622 |
} |