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