if (special || a->attr)
{
#ifdef HAVE_COLOR
- if (a->attr & ANSI_COLOR)
+ if ((a->attr & ANSI_COLOR))
{
if (a->pair == -1)
- a->pair = mutt_alloc_color (a->fg,a->bg);
+ a->pair = mutt_alloc_color (a->fg, a->bg);
color = a->pair;
if (a->attr & ANSI_BOLD)
color |= A_BOLD;
lineInfo[n+1].continuation = 1;
/* find the real start of the line */
- m = n;
- while (m >= 0)
- {
+ for (m = n; m >= 0; m--)
if (lineInfo[m].continuation == 0) break;
- m--;
- }
+
(lineInfo[n+1].syntax)[0].first = m;
(lineInfo[n+1].syntax)[0].last = (lineInfo[n].continuation) ?
cnt + (lineInfo[n].syntax)[0].last : cnt;
}
static void
-resolve_types (char *buf, struct line_t *lineInfo, int n, int last,
+resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last,
struct q_class_t **QuoteList, int *q_level, int *force_redraw,
int q_classify)
{
}
}
}
+ else if (mutt_strncmp ("\033[0;m", raw, 5) == 0) /* a little hack... */
+ lineInfo[n].type = MT_COLOR_NORMAL;
else if (mutt_strncmp ("[-- ", buf, 4) == 0)
lineInfo[n].type = MT_COLOR_ATTACHMENT;
else if (mutt_strcmp ("-- \n", buf) == 0 || mutt_strcmp ("-- \r\n", buf) == 0)
}
}
-static int
-fill_buffer (FILE *f, long *last_pos, long offset, unsigned char *buf,
- unsigned char *fmt, size_t blen, int *buf_ready)
-{
- unsigned char *p;
- static int b_read;
-
- if (*buf_ready == 0)
- {
- buf[blen - 1] = 0;
- if (offset != *last_pos)
- fseek (f, offset, 0);
- if (fgets ((char *) buf, blen - 1, f) == NULL)
- {
- fmt[0] = 0;
- return (-1);
- }
- *last_pos = ftell (f);
- b_read = (int) (*last_pos - offset);
- *buf_ready = 1;
-
- /* copy "buf" to "fmt", but without bold and underline controls */
- p = buf;
- while (*p)
- {
- if (*p == '\010' && (p > buf))
- {
- if (*(p+1) == '_') /* underline */
- p += 2;
- else if (*(p+1)) /* bold or overstrike */
- {
- *(fmt-1) = *(p+1);
- p += 2;
- }
- else /* ^H */
- *fmt++ = *p++;
- }
- else
- *fmt++ = *p++;
- }
- *fmt = 0;
- }
- return b_read;
-}
-
static int is_ansi (unsigned char *buf)
{
while (buf && (isdigit(*buf) || *buf == ';'))
return (*buf == 'm');
}
+
static int grok_ansi(unsigned char *buf, int pos, ansi_attr *a)
{
int x = pos;
return pos;
}
+static int
+fill_buffer (FILE *f, long *last_pos, long offset, unsigned char *buf,
+ unsigned char *fmt, size_t blen, int *buf_ready)
+{
+ unsigned char *p;
+ static int b_read;
+
+ if (*buf_ready == 0)
+ {
+ buf[blen - 1] = 0;
+ if (offset != *last_pos)
+ fseek (f, offset, 0);
+ if (fgets ((char *) buf, blen - 1, f) == NULL)
+ {
+ fmt[0] = 0;
+ return (-1);
+ }
+ *last_pos = ftell (f);
+ b_read = (int) (*last_pos - offset);
+ *buf_ready = 1;
+
+ /* copy "buf" to "fmt", but without bold and underline controls */
+ p = buf;
+ while (*p)
+ {
+ if (*p == '\010' && (p > buf))
+ {
+ if (*(p+1) == '_') /* underline */
+ p += 2;
+ else if (*(p+1)) /* bold or overstrike */
+ {
+ *(fmt-1) = *(p+1);
+ p += 2;
+ }
+ else /* ^H */
+ *fmt++ = *p++;
+ }
+ else if (*p == '\033' && *(p+1) == '[' && is_ansi (p + 2)) /* skip ANSI sequence */
+ while (*p++ != 'm')
+ ;
+ else
+ *fmt++ = *p++;
+ }
+ *fmt = 0;
+ }
+ return b_read;
+}
+
+
static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
int flags, ansi_attr *pa, int cnt,
int *pspace, int *pvch, int *pcol, int *pspecial)
while (cnt-ch >= 2 && buf[ch] == '\033' && buf[ch+1] == '[' &&
is_ansi (buf+ch+2))
ch = grok_ansi (buf, ch+2, pa) + 1;
-
+
k = mbrtowc (&wc, (char *)buf+ch, cnt-ch, &mbstate);
if (k == -2 || k == -1)
{
return (-1);
}
- resolve_types ((char *) fmt, *lineInfo, n, *last,
+ resolve_types ((char *) fmt, (char *) buf, *lineInfo, n, *last,
QuoteList, q_level, force_redraw, flags & M_SHOWCOLOR);
/* avoid race condition for continuation lines when scrolling up */
clrtoeol ();
SETCOLOR (MT_COLOR_NORMAL);
BKGDSET (MT_COLOR_NORMAL);
+
}
else
clrtoeol ();