Changeset fa86732


Ignore:
Timestamp:
Jan 16, 2007, 5:43:26 PM (18 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
32fa306
Parents:
855dc8d
git-author:
Nelson Elhage <nelhage@mit.edu> (01/16/07 17:43:23)
git-committer:
Nelson Elhage <nelhage@mit.edu> (01/16/07 17:43:26)
Message:
Adding filter-based word wrapping. Still need a heuristic for when not
to wordwrap.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    r8203afd rfa86732  
    250250
    251251  f=owl_malloc(sizeof(owl_filter));
     252  owl_filter_init_fromstring(f, "wordwrap", "not ( type ^admin$ or type ^zephyr$ ) ");
     253  owl_list_append_element(owl_global_get_filterlist(&g), f);
     254
     255  f=owl_malloc(sizeof(owl_filter));
    252256  owl_filter_init_fromstring(f, "trash", "class ^mail$ or opcode ^ping$ or type ^admin$ or ( not login ^none$ )");
    253257  owl_list_append_element(owl_global_get_filterlist(&g), f);
  • stylefunc.c

    rbc9436f rfa86732  
    99void owl_style_basic_format_body(owl_fmtext *fm, owl_message *m) {
    1010  char *indent, *body;
     11  owl_filter *f;
     12  int wrap = 0;
    1113
    1214  /* get the body */
    1315  body=owl_strdup(owl_message_get_body(m));
    14   body=realloc(body, strlen(body)+30);
    15 
    16   /* add a newline if we need to */
    17   if (body[0]!='\0' && body[strlen(body)-1]!='\n') {
    18     strcat(body, "\n");
     16
     17  f = owl_global_get_filter(&g, "wordwrap");
     18  if(f && owl_filter_message_match(f, m))
     19    wrap = 1;
     20
     21  if(wrap) {
     22    int cols, i, width, word;
     23    char *tab, *tok, *ws = " \t\n\r";
     24    cols = owl_global_get_cols(&g) - OWL_MSGTAB - 1;
     25
     26    tab = owl_malloc(OWL_MSGTAB+1);
     27    for(i = 0; i < OWL_MSGTAB; i++) {
     28      tab[i] = ' ';
     29    }
     30    tab[OWL_MSGTAB] = 0;
     31
     32    tok = strtok(body, ws);
     33    tab[OWL_MSGTAB-1] = 0;
     34    owl_fmtext_append_normal(fm, tab);
     35    tab[OWL_MSGTAB-1] = ' ';
     36    width = 0;
     37
     38    while(tok) {
     39      word = strlen(tok);
     40      if(word + width + 1 < cols) {
     41        owl_fmtext_append_normal(fm, " ");
     42        owl_fmtext_append_normal(fm, tok);
     43        width += word + 1;
     44      } else {
     45        owl_fmtext_append_normal(fm, "\n");
     46        owl_fmtext_append_normal(fm, tab);
     47        owl_fmtext_append_normal(fm, tok);
     48        width = word;
     49      }
     50      tok = strtok(NULL, ws);
     51    }
     52    owl_fmtext_append_normal(fm, "\n");
     53
     54    owl_free(tab);
     55  } else {
     56    /* do the indenting into indent */
     57    indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
     58    owl_text_indent(indent, body, OWL_MSGTAB);
     59    owl_fmtext_append_ztext(fm, indent);
     60    if(body[strlen(body)-1] != '\n')
     61      owl_fmtext_append_ztext(fm, "\n");
     62    owl_free(indent);
    1963  }
    2064
    21   /* do the indenting into indent */
    22   indent=owl_malloc(strlen(body)+owl_text_num_lines(body)*OWL_MSGTAB+10);
    23   owl_text_indent(indent, body, OWL_MSGTAB);
    24   owl_fmtext_append_ztext(fm, indent);
    25 
    26   owl_free(indent);
    2765  owl_free(body);
    2866}
Note: See TracChangeset for help on using the changeset viewer.