Changeset c2c5c77


Ignore:
Timestamp:
Mar 28, 2007, 10:54:33 PM (14 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7f33c18
Parents:
af9b92e
Message:
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.
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • filter.c

    r1716fed rc2c5c77  
    217217  if (f->fgcolor!=OWL_COLOR_DEFAULT) {
    218218    strcat(out, "-c ");
    219     strcat(out, owl_util_color_to_string(f->fgcolor));
     219    if (f->fgcolor < 8) {
     220      strcat(out, owl_util_color_to_string(f->fgcolor));
     221    }
     222    else {
     223      char* c = owl_sprintf("%i",f->fgcolor);
     224      strcat(out, c);
     225      owl_free(c);
     226    }
    220227    strcat(out, " ");
    221228  }
    222229  if (f->bgcolor!=OWL_COLOR_DEFAULT) {
    223230    strcat(out, "-b ");
    224     strcat(out, owl_util_color_to_string(f->bgcolor));
     231    if (f->bgcolor < 8) {
     232      strcat(out, owl_util_color_to_string(f->bgcolor));
     233    }
     234    else {
     235      char* c = owl_sprintf("%i",f->bgcolor);
     236      strcat(out, c);
     237      owl_free(c);
     238    }
    225239    strcat(out, " ");
    226240  }
  • fmtext.c

    ra387d12e rc2c5c77  
    1212  f->textbuff=owl_malloc(5);
    1313  f->fmbuff=owl_malloc(5);
    14   f->fgcolorbuff=owl_malloc(5);
    15   f->bgcolorbuff=owl_malloc(5);
     14  f->fgcolorbuff=owl_malloc(5 * sizeof(short));
     15  f->bgcolorbuff=owl_malloc(5 * sizeof(short));
    1616  f->textbuff[0]=0;
    1717  f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE;
     
    6060  int i;
    6161  for (i=first; i<=last; i++) {
    62     f->fgcolorbuff[i]=(unsigned char) color;
     62    f->fgcolorbuff[i]=(short)color;
    6363  }
    6464}
     
    6868  int i;
    6969  for (i=first; i<=last; i++) {
    70     f->bgcolorbuff[i]=(unsigned char) color;
     70    f->bgcolorbuff[i]=(short)color;
    7171  }
    7272}
     
    7777      f->textbuff=owl_realloc(f->textbuff, newlen+1);
    7878      f->fmbuff=owl_realloc(f->fmbuff, newlen+1);
    79       f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);
    80       f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);
     79      f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short));
     80      f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short));
    8181      f->bufflen = newlen+1;
    8282  }
     
    151151  j=f->textlen;
    152152  for(i=0; i<j; i++) {
    153     if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;
     153    if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color;
    154154  }
    155155}
     
    162162  j=f->textlen;
    163163  for(i=0; i<j; i++) {
    164     if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;
     164    if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color;
    165165  }
    166166}
     
    230230    /* find the last char with the current format and color */
    231231    trans1=owl_util_find_trans(f->fmbuff+position, len-position);
    232     trans2=owl_util_find_trans(f->fgcolorbuff+position, len-position);
    233     trans3=owl_util_find_trans(f->bgcolorbuff+position, len-position);
     232    trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position);
     233    trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position);
    234234
    235235    lastsame = (trans1 < trans2) ? trans1 : trans2;
     
    252252    /* warning, this is sort of a hack */
    253253    if (owl_global_get_hascolors(&g)) {
    254       int fg, bg;
    255       short pair;
     254      short fg, bg, pair;
    256255      fg = f->fgcolorbuff[position];
    257256      bg = f->bgcolorbuff[position];
     
    259258      pair = owl_fmtext_get_colorpair(fg, bg);
    260259      if (pair != -1) {
    261         wattron(w, COLOR_PAIR(pair));
     260        wcolor_set(w,pair,NULL);
    262261      }
    263262    }
     
    402401  dst->textbuff=owl_malloc(mallocsize);
    403402  dst->fmbuff=owl_malloc(mallocsize);
    404   dst->fgcolorbuff=owl_malloc(mallocsize);
    405   dst->bgcolorbuff=owl_malloc(mallocsize);
     403  dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short));
     404  dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short));
    406405  memcpy(dst->textbuff, src->textbuff, src->textlen+1);
    407406  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
    408   memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen);
    409   memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen);
     407  memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short));
     408  memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short));
    410409}
    411410
     
    678677{
    679678  // This could be a bitarray if we wanted to save memory.
    680   int i, j, colors;
    681   cpmgr->next = COLORS;
    682 
    683   colors = COLORS + 1; // 1 to account for "default".
    684   cpmgr->pairs = owl_malloc(colors * sizeof(int*));
    685   for(i = 0; i < colors; i++) {
    686     // Because we're going to have a pair set for any fg and the
    687     // default bg, we don't need to account for default here.
    688     cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int));
    689     for(j = 0; j < COLORS; j++) {
     679  short i, j;
     680  cpmgr->next = 8;
     681 
     682  // The test is <= because we allocate COLORS+1 entries.
     683  cpmgr->pairs = owl_malloc((COLORS+1) * sizeof(short*));
     684  for(i = 0; i <= COLORS; i++) {
     685    cpmgr->pairs[i] = owl_malloc((COLORS+1) * sizeof(short));
     686    for(j = 0; j <= COLORS; j++) {
    690687      cpmgr->pairs[i][j] = -1;
    691688    }
     689  }
     690  for(i = 0; i < 8; i++) {
     691    short fg, bg;
     692    pair_content(i, &fg, &bg);
     693    cpmgr->pairs[fg+1][bg+1] = i;
    692694  }
    693695}
     
    696698void owl_fmtext_reset_colorpairs()
    697699{
    698   int i, j, colors;
     700  short i, j;
    699701  owl_colorpair_mgr *cpmgr = owl_global_get_colorpair_mgr(&g);
    700   cpmgr->next = COLORS;
    701 
    702   colors = COLORS + 1; // 1 to account for "default".
    703   for(i = 0; i < colors; i++) {
    704     for(j = 0; j < COLORS; j++) {
     702  cpmgr->next = 8;
     703
     704  // The test is <= because we allocated COLORS+1 entries.
     705  for(i = 0; i <= COLORS; i++) {
     706    for(j = 0; j <= COLORS; j++) {
    705707      cpmgr->pairs[i][j] = -1;
    706708    }
     709  }
     710  for(i = 0; i < 8; i++) {
     711    short fg, bg;
     712    pair_content(i, &fg, &bg);
     713    cpmgr->pairs[fg+1][bg+1] = i;
    707714  }
    708715}
     
    723730#endif
    724731
    725   if (bg == default_bg) {
    726     // default bg -> use color pairs initialized by owl.c
    727     pair = fg;
    728   } else {
    729     // looking for a pair we already set up for this draw.
    730     cpmgr = owl_global_get_colorpair_mgr(&g);
    731     pair = cpmgr->pairs[fg+1][bg];
    732     if (!(pair != -1 && pair < cpmgr->next)) {
    733       // If we didn't find a pair, search for a free one to assign.
    734       // Skip the first COLORS, since they're static.
    735       // If we ever get 256 color curses, this will need more thought.
    736       pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
    737       if (pair != -1) {
    738         // We found a free pair, initialize it.
    739         init_pair(pair, fg, bg);
    740         cpmgr->pairs[fg+1][bg] = pair;
    741         cpmgr->next++;
    742       } else {
    743         // We still don't have a pair, drop the background color. Too bad.
    744         pair = fg;
    745       }
     732  // looking for a pair we already set up for this draw.
     733  cpmgr = owl_global_get_colorpair_mgr(&g);
     734  pair = cpmgr->pairs[fg+1][bg+1];
     735  if (!(pair != -1 && pair < cpmgr->next)) {
     736/*    owl_global_set_needrefresh(&g);*/
     737    // If we didn't find a pair, search for a free one to assign.
     738    pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1;
     739    if (pair != -1) {
     740      // We found a free pair, initialize it.
     741      init_pair(pair, fg, bg);
     742      cpmgr->pairs[fg+1][bg+1] = pair;
     743      cpmgr->next++;
     744    }
     745    else if (bg != OWL_COLOR_DEFAULT) {
     746      // We still don't have a pair, drop the background color. Too bad.
     747      owl_function_debugmsg("colorpairs: color shortage - dropping background color.");
     748      pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT);
     749    }
     750    else {
     751      // We still don't have a pair, defaults all around.
     752      owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color.");
     753      pair = 0;
    746754    }
    747755  }
  • functions.c

    raf9b92e rc2c5c77  
    14401440  wnoutrefresh(owl_global_get_curs_typwin(&g));
    14411441  wnoutrefresh(owl_global_get_curs_msgwin(&g));
     1442
     1443  if (owl_popwin_is_active(owl_global_get_popwin(&g))) {
     1444    owl_popwin_refresh(owl_global_get_popwin(&g));
     1445  }
    14421446 
    14431447  sepbar("");
     
    30183022{
    30193023  owl_fmtext fm;
    3020 
     3024  int i;
     3025 
    30213026  owl_fmtext_init_null(&fm);
    30223027  owl_fmtext_append_normal(&fm, "default: ");
     
    30443049  owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT);
    30453050
     3051  for(i = 8; i < COLORS; ++i) {
     3052    char* str1 = owl_sprintf("%4i:     ",i);
     3053    char* str2 = owl_sprintf("%i\n",i);
     3054    owl_fmtext_append_normal(&fm,str1);
     3055    owl_fmtext_append_normal_color(&fm, str2, i, OWL_COLOR_DEFAULT);
     3056    owl_free(str1);
     3057     owl_free(str2);
     3058  }
     3059 
    30463060  owl_function_popless_fmtext(&fm);
    30473061  owl_fmtext_free(&fm);
     
    37193733  owl_fmtext_free(&fm);
    37203734}
     3735
     3736int owl_function_get_color_count()
     3737{
     3738     return COLORS;
     3739}
  • mainwin.c

    r8fa9562 rc2c5c77  
    7979    for (p=0; p<q; p++) {
    8080      f=owl_list_get_element(filtlist, p);
    81       if (owl_filter_message_match(f, m)) {
    82         if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
    83         if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
     81      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
     82          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
     83        if (owl_filter_message_match(f, m)) {
     84          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
     85          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
     86        }
    8487      }
    8588    }
  • owl.c

    r72c210f rc2c5c77  
    331331  owl_function_debugmsg("startup: creating splash message");
    332332  strcpy(startupmsg, "-----------------------------------------------------------------------\n");
    333   sprintf(buff,      "Welcome to barnowl version %s.  Press 'h' for on-line help. \n", OWL_VERSION_STRING);
     333  sprintf(buff,      "Welcome to barnowl version %s.  Press 'h' for on-line help.            \n", OWL_VERSION_STRING);
    334334  strcat(startupmsg, buff);
    335335  strcat(startupmsg, "                                                                       \n");
    336   strcat(startupmsg, "This is a development build of barnowl. If you are using this  \n");
    337   strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu      \n");
     336  strcat(startupmsg, "This is a development build of barnowl. If you are using this          \n");
     337  strcat(startupmsg, "build regularly, please add yourself to barnowl-users@mit.edu          \n");
    338338  strcat(startupmsg, "                                                                 ^ ^   \n");
    339339  strcat(startupmsg, "                                                                 OvO   \n");
  • owl.h

    rb3a40c7 rc2c5c77  
    104104#define OWL_COLOR_CYAN      6
    105105#define OWL_COLOR_WHITE     7
    106 #define OWL_COLOR_DEFAULT   8
     106#define OWL_COLOR_DEFAULT   -1
    107107
    108108#define OWL_EDITWIN_STYLE_MULTILINE 0
     
    252252  char *textbuff;
    253253  char *fmbuff;
    254   char *fgcolorbuff;
    255   char *bgcolorbuff;
     254  short *fgcolorbuff;
     255  short *bgcolorbuff;
    256256} owl_fmtext;
    257257
     
    526526typedef struct _owl_colorpair_mgr {
    527527  int next;
    528   int **pairs;
     528  short **pairs;
    529529} owl_colorpair_mgr;
    530530
  • perlglue.xs

    r3066d23 rc2c5c77  
    296296                owl_global_add_style(&g, s);
    297297        }
     298
     299int
     300getnumcolors()
     301        CODE:
     302                RETVAL = owl_function_get_color_count();
     303        OUTPUT:
     304                RETVAL
     305
     306void
     307_remove_filter(filterName)
     308        char *filterName
     309        CODE:
     310        {
     311                /* Don't delete the current view, or the 'all' filter */
     312                if (strcmp(filterName, owl_view_get_filtname(owl_global_get_current_view(&g)))
     313                    && strcmp(filterName, "all")) {
     314                        owl_global_remove_filter(&g,filterName);
     315                }
     316        }
  • util.c

    rd524c83 rc2c5c77  
    390390}
    391391
     392int owl_util_find_trans_short(short *in, int len)
     393{
     394  int i;
     395  for (i=1; i<len; i++) {
     396    if (in[i] != in[0]) return(i-1);
     397  }
     398  return(i);
     399}
     400
    392401/* downcase the string 'foo' */
    393402void downstr(char *foo)
     
    488497int owl_util_string_to_color(char *color)
    489498{
     499  int c;
    490500  if (!strcasecmp(color, "black")) {
    491501    return(OWL_COLOR_BLACK);
     
    507517    return(OWL_COLOR_DEFAULT);
    508518  }
     519  c = atoi(color);
     520  if (c >= -1 && c < COLORS) {
     521    return(c);
     522  }
    509523  return(-1);
    510524}
Note: See TracChangeset for help on using the changeset viewer.