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