[576] in BarnOwl Developers
[D-O-H] r693 - trunk/owl
daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:07:35 2009
Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Wed, 28 Mar 2007 22:54:33 -0400 (EDT)
Author: asedeno
Date: 2007-03-28 22:54:33 -0400 (Wed, 28 Mar 2007)
New Revision: 693
Modified:
trunk/owl/filter.c
trunk/owl/fmtext.c
trunk/owl/functions.c
trunk/owl/mainwin.c
trunk/owl/owl.c
trunk/owl/owl.h
trunk/owl/perlglue.xs
trunk/owl/util.c
Log:
Adding 256-color support. This requires a version of ncurses that
supports ABI-6. Colors beyond the first eight are refered to by
number.
Perl now has the number of colors exposed to it by way of
BarnOwl::getnumcolors()
and also has a mechanism for undefining filters using
BarnOwl::_remove_filter([filter-name])
You can't remove the 'all' filter or the current filter.
Modified: trunk/owl/filter.c
===================================================================
--- trunk/owl/filter.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/filter.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -216,12 +216,26 @@
if (f->fgcolor!=OWL_COLOR_DEFAULT) {
strcat(out, "-c ");
- strcat(out, owl_util_color_to_string(f->fgcolor));
+ if (f->fgcolor < 8) {
+ strcat(out, owl_util_color_to_string(f->fgcolor));
+ }
+ else {
+ char* c = owl_sprintf("%i",f->fgcolor);
+ strcat(out, c);
+ owl_free(c);
+ }
strcat(out, " ");
}
if (f->bgcolor!=OWL_COLOR_DEFAULT) {
strcat(out, "-b ");
- strcat(out, owl_util_color_to_string(f->bgcolor));
+ if (f->bgcolor < 8) {
+ strcat(out, owl_util_color_to_string(f->bgcolor));
+ }
+ else {
+ char* c = owl_sprintf("%i",f->bgcolor);
+ strcat(out, c);
+ owl_free(c);
+ }
strcat(out, " ");
}
if(!f->root) return;
Modified: trunk/owl/fmtext.c
===================================================================
--- trunk/owl/fmtext.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/fmtext.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -11,8 +11,8 @@
f->bufflen=5;
f->textbuff=owl_malloc(5);
f->fmbuff=owl_malloc(5);
- f->fgcolorbuff=owl_malloc(5);
- f->bgcolorbuff=owl_malloc(5);
+ f->fgcolorbuff=owl_malloc(5 * sizeof(short));
+ f->bgcolorbuff=owl_malloc(5 * sizeof(short));
f->textbuff[0]=0;
f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
f->fgcolorbuff[0]=OWL_COLOR_DEFAULT;
@@ -59,7 +59,7 @@
{
int i;
for (i=first; i<=last; i++) {
- f->fgcolorbuff[i]=(unsigned char) color;
+ f->fgcolorbuff[i]=(short)color;
}
}
@@ -67,7 +67,7 @@
{
int i;
for (i=first; i<=last; i++) {
- f->bgcolorbuff[i]=(unsigned char) color;
+ f->bgcolorbuff[i]=(short)color;
}
}
@@ -76,8 +76,8 @@
if(newlen + 1 > f->bufflen) {
f->textbuff=owl_realloc(f->textbuff, newlen+1);
f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
- f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
- f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
+ f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short));
+ f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short));
f->bufflen = newlen+1;
}
}
@@ -150,7 +150,7 @@
j=f->textlen;
for(i=0; i<j; i++) {
- if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;
+ if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color;
}
}
@@ -161,7 +161,7 @@
j=f->textlen;
for(i=0; i<j; i++) {
- if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;
+ if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color;
}
}
@@ -229,8 +229,8 @@
while (position<=len) {
/* find the last char with the current format and color */
trans1=owl_util_find_trans(f->fmbuff+position, len-position);
- trans2=owl_util_find_trans(f->fgcolorbuff+position, len-position);
- trans3=owl_util_find_trans(f->bgcolorbuff+position, len-position);
+ trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position);
+ trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position);
lastsame = (trans1 < trans2) ? trans1 : trans2;
lastsame = (lastsame < trans3) ? lastsame : trans3;
@@ -251,14 +251,13 @@
/* set the color */
/* warning, this is sort of a hack */
if (owl_global_get_hascolors(&g)) {
- int fg, bg;
- short pair;
+ short fg, bg, pair;
fg = f->fgcolorbuff[position];
bg = f->bgcolorbuff[position];
pair = owl_fmtext_get_colorpair(fg, bg);
if (pair != -1) {
- wattron(w, COLOR_PAIR(pair));
+ wcolor_set(w,pair,NULL);
}
}
@@ -401,12 +400,12 @@
dst->textlen=src->textlen;
dst->textbuff=owl_malloc(mallocsize);
dst->fmbuff=owl_malloc(mallocsize);
- dst->fgcolorbuff=owl_malloc(mallocsize);
- dst->bgcolorbuff=owl_malloc(mallocsize);
+ dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));
+ dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));
memcpy(dst->textbuff, src->textbuff, src->textlen+1);
memcpy(dst->fmbuff, src->fmbuff, src->textlen);
- memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen);
- memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen);
+ memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short));
+ memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short));
}
/* highlight all instances of "string". Return the number of
@@ -677,34 +676,42 @@
void owl_fmtext_init_colorpair_mgr(owl_colorpair_mgr *cpmgr)
{
// This could be a bitarray if we wanted to save memory.
- int i, j, colors;
- cpmgr->next = COLORS;
-
- colors = COLORS + 1; // 1 to account for "default".
- cpmgr->pairs = owl_malloc(colors * sizeof(int*));
- for(i = 0; i < colors; i++) {
- // Because we're going to have a pair set for any fg and the
- // default bg, we don't need to account for default here.
- cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int));
- for(j = 0; j < COLORS; j++) {
+ short i, j;
+ cpmgr->next = 8;
+
+ // The test is <= because we allocate COLORS+1 entries.
+ cpmgr->pairs = owl_malloc((COLORS+1) * sizeof(short*));
+ for(i = 0; i <= COLORS; i++) {
+ cpmgr->pairs[i] = owl_malloc((COLORS+1) * sizeof(short));
+ for(j = 0; j <= COLORS; j++) {
cpmgr->pairs[i][j] = -1;
}
}
+ for(i = 0; i < 8; i++) {
+ short fg, bg;
+ pair_content(i, &fg, &bg);
+ cpmgr->pairs[fg+1][bg+1] = i;
+ }
}
/* Reset used list */
void owl_fmtext_reset_colorpairs()
{
- int i, j, colors;
+ short i, j;
owl_colorpair_mgr *cpmgr = owl_global_get_colorpair_mgr(&g);
- cpmgr->next = COLORS;
+ cpmgr->next = 8;
- colors = COLORS + 1; // 1 to account for "default".
- for(i = 0; i < colors; i++) {
- for(j = 0; j < COLORS; j++) {
+ // The test is <= because we allocated COLORS+1 entries.
+ for(i = 0; i <= COLORS; i++) {
+ for(j = 0; j <= COLORS; j++) {
cpmgr->pairs[i][j] = -1;
}
}
+ for(i = 0; i < 8; i++) {
+ short fg, bg;
+ pair_content(i, &fg, &bg);
+ cpmgr->pairs[fg+1][bg+1] = i;
+ }
}
/* Assign pairs by request */
@@ -722,28 +729,29 @@
default_bg = COLOR_BLACK;
#endif
- if (bg == default_bg) {
- // default bg -> use color pairs initialized by owl.c
- pair = fg;
- } else {
- // looking for a pair we already set up for this draw.
- cpmgr = owl_global_get_colorpair_mgr(&g);
- pair = cpmgr->pairs[fg+1][bg];
- if (!(pair != -1 && pair < cpmgr->next)) {
- // If we didn't find a pair, search for a free one to assign.
- // Skip the first COLORS, since they're static.
- // If we ever get 256 color curses, this will need more thought.
- pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
- if (pair != -1) {
- // We found a free pair, initialize it.
- init_pair(pair, fg, bg);
- cpmgr->pairs[fg+1][bg] = pair;
- cpmgr->next++;
- } else {
- // We still don't have a pair, drop the background color. Too bad.
- pair = fg;
- }
+ // looking for a pair we already set up for this draw.
+ cpmgr = owl_global_get_colorpair_mgr(&g);
+ pair = cpmgr->pairs[fg+1][bg+1];
+ if (!(pair != -1 && pair < cpmgr->next)) {
+/* owl_global_set_needrefresh(&g);*/
+ // If we didn't find a pair, search for a free one to assign.
+ pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
+ if (pair != -1) {
+ // We found a free pair, initialize it.
+ init_pair(pair, fg, bg);
+ cpmgr->pairs[fg+1][bg+1] = pair;
+ cpmgr->next++;
}
+ else if (bg != OWL_COLOR_DEFAULT) {
+ // We still don't have a pair, drop the background color. Too bad.
+ owl_function_debugmsg("colorpairs: color shortage - dropping background color.");
+ pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT);
+ }
+ else {
+ // We still don't have a pair, defaults all around.
+ owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color.");
+ pair = 0;
+ }
}
return pair;
}
Modified: trunk/owl/functions.c
===================================================================
--- trunk/owl/functions.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/functions.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -1439,6 +1439,10 @@
wnoutrefresh(owl_global_get_curs_sepwin(&g));
wnoutrefresh(owl_global_get_curs_typwin(&g));
wnoutrefresh(owl_global_get_curs_msgwin(&g));
+
+ if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
+ owl_popwin_refresh(owl_global_get_popwin(&g));
+ }
sepbar("");
owl_function_makemsg("");
@@ -3017,7 +3021,8 @@
void owl_function_show_colors()
{
owl_fmtext fm;
-
+ int i;
+
owl_fmtext_init_null(&fm);
owl_fmtext_append_normal(&fm, "default: ");
owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT);
@@ -3043,6 +3048,15 @@
owl_fmtext_append_normal(&fm,"white: ");
owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT);
+ for(i = 8; i < COLORS; ++i) {
+ char* str1 = owl_sprintf("%4i: ",i);
+ char* str2 = owl_sprintf("%i\n",i);
+ owl_fmtext_append_normal(&fm,str1);
+ owl_fmtext_append_normal_color(&fm, str2, i, OWL_COLOR_DEFAULT);
+ owl_free(str1);
+ owl_free(str2);
+ }
+
owl_function_popless_fmtext(&fm);
owl_fmtext_free(&fm);
}
@@ -3718,3 +3732,8 @@
owl_function_popless_fmtext(&fm);
owl_fmtext_free(&fm);
}
+
+int owl_function_get_color_count()
+{
+ return COLORS;
+}
Modified: trunk/owl/mainwin.c
===================================================================
--- trunk/owl/mainwin.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/mainwin.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -78,9 +78,12 @@
q=owl_list_get_size(filtlist);
for (p=0; p<q; p++) {
f=owl_list_get_element(filtlist, p);
- if (owl_filter_message_match(f, m)) {
- if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
- if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
+ if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
+ (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
+ if (owl_filter_message_match(f, m)) {
+ if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
+ if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
+ }
}
}
Modified: trunk/owl/owl.c
===================================================================
--- trunk/owl/owl.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/owl.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -330,11 +330,11 @@
/* welcome message */
owl_function_debugmsg("startup: creating splash message");
strcpy(startupmsg, "-----------------------------------------------------------------------\n");
- sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING);
+ sprintf(buff, "Welcome to barnowl version %s. Press 'h' for on-line help. \n", OWL_VERSION_STRING);
strcat(startupmsg, buff);
strcat(startupmsg, " \n");
- strcat(startupmsg, "This is a development build of barnowl. If you are using this \n");
- strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu \n");
+ strcat(startupmsg, "This is a development build of barnowl. If you are using this \n");
+ strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu \n");
strcat(startupmsg, " ^ ^ \n");
strcat(startupmsg, " OvO \n");
strcat(startupmsg, "Please report any bugs to dirty-owl-hackers@mit.edu ( ) \n");
Modified: trunk/owl/owl.h
===================================================================
--- trunk/owl/owl.h 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/owl.h 2007-03-29 02:54:33 UTC (rev 693)
@@ -103,7 +103,7 @@
#define OWL_COLOR_MAGENTA 5
#define OWL_COLOR_CYAN 6
#define OWL_COLOR_WHITE 7
-#define OWL_COLOR_DEFAULT 8
+#define OWL_COLOR_DEFAULT -1
#define OWL_EDITWIN_STYLE_MULTILINE 0
#define OWL_EDITWIN_STYLE_ONELINE 1
@@ -251,8 +251,8 @@
int bufflen;
char *textbuff;
char *fmbuff;
- char *fgcolorbuff;
- char *bgcolorbuff;
+ short *fgcolorbuff;
+ short *bgcolorbuff;
} owl_fmtext;
typedef struct _owl_list {
@@ -525,7 +525,7 @@
typedef struct _owl_colorpair_mgr {
int next;
- int **pairs;
+ short **pairs;
} owl_colorpair_mgr;
typedef struct _owl_obarray {
Modified: trunk/owl/perlglue.xs
===================================================================
--- trunk/owl/perlglue.xs 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/perlglue.xs 2007-03-29 02:54:33 UTC (rev 693)
@@ -295,3 +295,22 @@
owl_style_create_perl(s, name, function, description);
owl_global_add_style(&g, s);
}
+
+int
+getnumcolors()
+ CODE:
+ RETVAL = owl_function_get_color_count();
+ OUTPUT:
+ RETVAL
+
+void
+_remove_filter(filterName)
+ char *filterName
+ CODE:
+ {
+ /* Don't delete the current view, or the 'all' filter */
+ if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g)))
+ && strcmp(filterName, "all")) {
+ owl_global_remove_filter(&g,filterName);
+ }
+ }
Modified: trunk/owl/util.c
===================================================================
--- trunk/owl/util.c 2007-03-29 02:36:40 UTC (rev 692)
+++ trunk/owl/util.c 2007-03-29 02:54:33 UTC (rev 693)
@@ -389,6 +389,15 @@
return(i);
}
+int owl_util_find_trans_short(short *in, int len)
+{
+ int i;
+ for (i=1; i<len; i++) {
+ if (in[i] != in[0]) return(i-1);
+ }
+ return(i);
+}
+
/* downcase the string 'foo' */
void downstr(char *foo)
{
@@ -487,6 +496,7 @@
*/
int owl_util_string_to_color(char *color)
{
+ int c;
if (!strcasecmp(color, "black")) {
return(OWL_COLOR_BLACK);
} else if (!strcasecmp(color, "red")) {
@@ -506,6 +516,10 @@
} else if (!strcasecmp(color, "default")) {
return(OWL_COLOR_DEFAULT);
}
+ c = atoi(color);
+ if (c >= -1 && c < COLORS) {
+ return(c);
+ }
return(-1);
}