Mercurial > hg
comparison mcabber/src/screen.c @ 739:0d5fb1d9077c
Allow "bright" text colors
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 10 Mar 2006 17:18:50 +0100 |
parents | 2f027806cd48 |
children | 1877838d3c27 |
comparison
equal
deleted
inserted
replaced
738:03db650f6015 | 739:0d5fb1d9077c |
---|---|
39 #include "settings.h" | 39 #include "settings.h" |
40 #include "utils.h" | 40 #include "utils.h" |
41 #include "list.h" | 41 #include "list.h" |
42 | 42 |
43 #define window_entry(n) list_entry(n, window_entry_t, list) | 43 #define window_entry(n) list_entry(n, window_entry_t, list) |
44 #define get_color(col) (COLOR_PAIR(col)|COLOR_ATTRIB[col]) | |
44 | 45 |
45 #define DEFAULT_LOG_WIN_HEIGHT (5+2) | 46 #define DEFAULT_LOG_WIN_HEIGHT (5+2) |
46 #define DEFAULT_ROSTER_WIDTH 24 | 47 #define DEFAULT_ROSTER_WIDTH 24 |
47 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) | 48 #define CHAT_WIN_HEIGHT (maxY-1-Log_Win_Height) |
48 | 49 |
120 if (!strcmp(name, "cyan")) | 121 if (!strcmp(name, "cyan")) |
121 return COLOR_CYAN; | 122 return COLOR_CYAN; |
122 if (!strcmp(name, "white")) | 123 if (!strcmp(name, "white")) |
123 return COLOR_WHITE; | 124 return COLOR_WHITE; |
124 | 125 |
126 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Wrong color: %s", name); | |
125 return -1; | 127 return -1; |
126 } | 128 } |
127 | 129 |
128 static void ParseColors(void) | 130 static void ParseColors(void) |
129 { | 131 { |
130 const char *colors[10] = { | 132 const char *colors[] = { |
131 "", "", | 133 "", "", |
132 "general", | 134 "general", |
133 "highlight", | 135 "highlight", |
134 "status", | 136 "status", |
135 "roster", | 137 "roster", |
137 "rosterselmsg", | 139 "rosterselmsg", |
138 "rosternewmsg", | 140 "rosternewmsg", |
139 NULL | 141 NULL |
140 }; | 142 }; |
141 | 143 |
142 char *tmp = g_new(char, 512); | |
143 const char *color; | 144 const char *color; |
144 const char *background = settings_opt_get("color_background"); | 145 const char *background = settings_opt_get("color_background"); |
145 const char *backselected = settings_opt_get("color_bgrostersel"); | 146 const char *backselected = settings_opt_get("color_bgrostersel"); |
146 const char *backstatus = settings_opt_get("color_bgstatus"); | 147 const char *backstatus = settings_opt_get("color_bgstatus"); |
147 int i = 0; | 148 char *tmp; |
149 int i; | |
150 | |
151 // Initialize color attributes | |
152 memset(COLOR_ATTRIB, 0, sizeof(COLOR_ATTRIB)); | |
148 | 153 |
149 // Default values | 154 // Default values |
150 if (!background) background = "black"; | 155 if (!background) background = "black"; |
151 if (!backselected) backselected = "cyan"; | 156 if (!backselected) backselected = "cyan"; |
152 if (!backstatus) backstatus = "blue"; | 157 if (!backstatus) backstatus = "blue"; |
153 | 158 |
154 while (colors[i]) { | 159 for (i=0; colors[i]; i++) { |
155 snprintf(tmp, 512, "color_%s", colors[i]); | 160 tmp = g_strdup_printf("color_%s", colors[i]); |
156 color = settings_opt_get(tmp); | 161 color = settings_opt_get(tmp); |
162 g_free(tmp); | |
163 | |
164 if (color) { | |
165 if (!strncmp(color, "bright", 6)) { | |
166 COLOR_ATTRIB[i+1] = A_BOLD; | |
167 color += 6; | |
168 } | |
169 } | |
157 | 170 |
158 switch (i + 1) { | 171 switch (i + 1) { |
159 case 1: | 172 case 1: |
160 init_pair(1, COLOR_BLACK, COLOR_WHITE); | 173 init_pair(1, COLOR_BLACK, COLOR_WHITE); |
161 break; | 174 break; |
162 case 2: | 175 case 2: |
163 init_pair(2, COLOR_WHITE, COLOR_BLACK); | 176 init_pair(2, COLOR_WHITE, COLOR_BLACK); |
164 break; | 177 break; |
165 case COLOR_GENERAL: | 178 case COLOR_GENERAL: |
166 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), | 179 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), |
167 FindColor(background)); | 180 FindColor(background)); |
168 break; | 181 break; |
169 case COLOR_HIGHLIGHT: | 182 case COLOR_HIGHLIGHT: |
170 init_pair(i+1, ((color) ? FindColor(color) : COLOR_CYAN), | 183 init_pair(i+1, ((color) ? FindColor(color) : COLOR_CYAN), |
171 FindColor(background)); | 184 FindColor(background)); |
172 break; | 185 break; |
173 case COLOR_STATUS: | 186 case COLOR_STATUS: |
174 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), | 187 init_pair(i+1, ((color) ? FindColor(color) : COLOR_WHITE), |
175 FindColor(backstatus)); | 188 FindColor(backstatus)); |
176 break; | 189 break; |
177 case COLOR_ROSTER: | 190 case COLOR_ROSTER: |
178 init_pair(i+1, ((color) ? FindColor(color) : COLOR_GREEN), | 191 init_pair(i+1, ((color) ? FindColor(color) : COLOR_GREEN), |
179 FindColor(background)); | 192 FindColor(background)); |
180 break; | 193 break; |
181 case COLOR_ROSTERSEL: | 194 case COLOR_ROSTERSEL: |
182 init_pair(i+1, ((color) ? FindColor(color) : COLOR_BLUE), | 195 init_pair(i+1, ((color) ? FindColor(color) : COLOR_BLUE), |
183 FindColor(backselected)); | 196 FindColor(backselected)); |
184 break; | 197 break; |
185 case COLOR_ROSTERSELNMSG: | 198 case COLOR_ROSTERSELNMSG: |
186 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), | 199 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), |
187 FindColor(backselected)); | 200 FindColor(backselected)); |
188 break; | 201 break; |
189 case COLOR_ROSTERNMSG: | 202 case COLOR_ROSTERNMSG: |
190 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), | 203 init_pair(i+1, ((color) ? FindColor(color) : COLOR_RED), |
191 FindColor(background)); | 204 FindColor(background)); |
192 break; | 205 break; |
193 } | 206 } |
194 i++; | |
195 } | 207 } |
196 } | 208 } |
197 | 209 |
198 void scr_InitCurses(void) | 210 void scr_InitCurses(void) |
199 { | 211 { |
299 tmp->win = newwin(lines, cols, y, x); | 311 tmp->win = newwin(lines, cols, y, x); |
300 while (!tmp->win) { | 312 while (!tmp->win) { |
301 safe_usleep(250); | 313 safe_usleep(250); |
302 tmp->win = newwin(lines, cols, y, x); | 314 tmp->win = newwin(lines, cols, y, x); |
303 } | 315 } |
304 wbkgd(tmp->win, COLOR_PAIR(COLOR_GENERAL)); | 316 wbkgd(tmp->win, get_color(COLOR_GENERAL)); |
305 tmp->panel = new_panel(tmp->win); | 317 tmp->panel = new_panel(tmp->win); |
306 tmp->name = g_strdup(title); | 318 tmp->name = g_strdup(title); |
307 | 319 |
308 if (!dont_show) { | 320 if (!dont_show) { |
309 currentWindow = tmp; | 321 currentWindow = tmp; |
392 line = *(lines+n); | 404 line = *(lines+n); |
393 // NOTE: update PREFIX_WIDTH if you change the date format!! | 405 // NOTE: update PREFIX_WIDTH if you change the date format!! |
394 // You need to set it to the whole prefix length + 1 | 406 // You need to set it to the whole prefix length + 1 |
395 if (line) { | 407 if (line) { |
396 if (line->flags & HBB_PREFIX_HLIGHT) | 408 if (line->flags & HBB_PREFIX_HLIGHT) |
397 wattrset(win_entry->win, COLOR_PAIR(COLOR_HIGHLIGHT)); | 409 wattrset(win_entry->win, get_color(COLOR_HIGHLIGHT)); |
398 | 410 |
399 if (line->timestamp) { | 411 if (line->timestamp) { |
400 strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); | 412 strftime(date, 30, "%m-%d %H:%M", localtime(&line->timestamp)); |
401 } else | 413 } else |
402 strcpy(date, " "); | 414 strcpy(date, " "); |
423 } | 435 } |
424 | 436 |
425 wprintw(win_entry->win, "%s", line->text); // Display text line | 437 wprintw(win_entry->win, "%s", line->text); // Display text line |
426 | 438 |
427 if (line->flags & HBB_PREFIX_HLIGHT) | 439 if (line->flags & HBB_PREFIX_HLIGHT) |
428 wattrset(win_entry->win, COLOR_PAIR(COLOR_GENERAL)); | 440 wattrset(win_entry->win, get_color(COLOR_GENERAL)); |
429 wclrtoeol(win_entry->win); | 441 wclrtoeol(win_entry->win); |
430 g_free(line->text); | 442 g_free(line->text); |
431 } else { | 443 } else { |
432 wclrtobot(win_entry->win); | 444 wclrtobot(win_entry->win); |
433 break; | 445 break; |
612 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { | 624 if (!rosterWnd || !chatWnd || !logWnd || !inputWnd) { |
613 scr_TerminateCurses(); | 625 scr_TerminateCurses(); |
614 fprintf(stderr, "Cannot create windows!\n"); | 626 fprintf(stderr, "Cannot create windows!\n"); |
615 exit(EXIT_FAILURE); | 627 exit(EXIT_FAILURE); |
616 } | 628 } |
617 wbkgd(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); | 629 wbkgd(rosterWnd, get_color(COLOR_GENERAL)); |
618 wbkgd(chatWnd, COLOR_PAIR(COLOR_GENERAL)); | 630 wbkgd(chatWnd, get_color(COLOR_GENERAL)); |
619 wbkgd(logWnd, COLOR_PAIR(COLOR_GENERAL)); | 631 wbkgd(logWnd, get_color(COLOR_GENERAL)); |
620 wbkgd(chatstatusWnd, COLOR_PAIR(COLOR_STATUS)); | 632 wbkgd(chatstatusWnd, get_color(COLOR_STATUS)); |
621 wbkgd(mainstatusWnd, COLOR_PAIR(COLOR_STATUS)); | 633 wbkgd(mainstatusWnd, get_color(COLOR_STATUS)); |
622 } else { | 634 } else { |
623 /* Resize/move windows */ | 635 /* Resize/move windows */ |
624 wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width); | 636 wresize(rosterWnd, CHAT_WIN_HEIGHT, Roster_Width); |
625 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width); | 637 wresize(chatWnd, CHAT_WIN_HEIGHT, maxX - Roster_Width); |
626 mvwin(chatWnd, 0, Roster_Width); | 638 mvwin(chatWnd, 0, Roster_Width); |
837 // Cleanup of roster window | 849 // Cleanup of roster window |
838 werase(rosterWnd); | 850 werase(rosterWnd); |
839 | 851 |
840 if (Roster_Width) { | 852 if (Roster_Width) { |
841 // Redraw the vertical line (not very good...) | 853 // Redraw the vertical line (not very good...) |
842 wattrset(rosterWnd, COLOR_PAIR(COLOR_GENERAL)); | 854 wattrset(rosterWnd, get_color(COLOR_GENERAL)); |
843 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) | 855 for (i=0 ; i < CHAT_WIN_HEIGHT ; i++) |
844 mvwaddch(rosterWnd, i, Roster_Width-1, ACS_VLINE); | 856 mvwaddch(rosterWnd, i, Roster_Width-1, ACS_VLINE); |
845 } | 857 } |
846 | 858 |
847 // Leave now if buddylist is empty or the roster is hidden | 859 // Leave now if buddylist is empty or the roster is hidden |
915 if (budstate >= 0 && budstate < imstatus_size) | 927 if (budstate >= 0 && budstate < imstatus_size) |
916 status = imstatus2char[budstate]; | 928 status = imstatus2char[budstate]; |
917 } | 929 } |
918 if (buddy == current_buddy) { | 930 if (buddy == current_buddy) { |
919 if (pending == '#') | 931 if (pending == '#') |
920 wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERSELNMSG)); | 932 wattrset(rosterWnd, get_color(COLOR_ROSTERSELNMSG)); |
921 else | 933 else |
922 wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERSEL)); | 934 wattrset(rosterWnd, get_color(COLOR_ROSTERSEL)); |
923 // The 3 following lines aim at coloring the whole line | 935 // The 3 following lines aim at coloring the whole line |
924 wmove(rosterWnd, i, 0); | 936 wmove(rosterWnd, i, 0); |
925 for (n = 0; n < maxx; n++) | 937 for (n = 0; n < maxx; n++) |
926 waddch(rosterWnd, ' '); | 938 waddch(rosterWnd, ' '); |
927 } else { | 939 } else { |
928 if (pending == '#') | 940 if (pending == '#') |
929 wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTERNMSG)); | 941 wattrset(rosterWnd, get_color(COLOR_ROSTERNMSG)); |
930 else | 942 else |
931 wattrset(rosterWnd, COLOR_PAIR(COLOR_ROSTER)); | 943 wattrset(rosterWnd, get_color(COLOR_ROSTER)); |
932 } | 944 } |
933 | 945 |
934 if (Roster_Width > 7) | 946 if (Roster_Width > 7) |
935 strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7); | 947 strncpy(name, buddy_getname(BUDDATA(buddy)), Roster_Width-7); |
936 else | 948 else |