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