1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

plain_renderer: cg-log -c | elinks works. The code needs cleanup

This commit is contained in:
Witold Filipczyk 2006-05-07 15:49:08 +02:00 committed by Witold Filipczyk
parent 1feab80c13
commit 88c146a395
3 changed files with 61 additions and 1 deletions

View File

@ -6,6 +6,7 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdio.h>
#include "elinks.h" #include "elinks.h"
@ -226,6 +227,55 @@ print_document_link(struct plain_renderer *renderer, int lineno,
return len; return len;
} }
static inline int
change_colors(struct screen_char *template, unsigned char *text, struct document *document)
{
unsigned char fg, bg, bold;
unsigned char *start = text;
#if defined(CONFIG_88_COLORS) || defined(CONFIG_256_COLORS)
fg = template->color[0];
bg = template->color[1];
#else
fg = template->color[0] & 15;
bg = template->color[0] >> 4;
#endif
bold = template->attr & SCREEN_ATTR_BOLD;
for (start = text; *text && *text != 'm'; text++) {
switch (*text) {
case ';':
break;
case '3':
text++;
if (*text >= '0' && *text < '9')
fg = *text - '0';
else
fg = 7;
break;
case '4':
text++;
if (*text >= '0' && *text < '9')
bg = *text - '0';
else
bg = 0;
break;
case '1':
bold = SCREEN_ATTR_BOLD;
break;
case '0':
bold = 0;
break;
default:
break;
}
}
fg |= bold;
set_term_color16(template, document->options.color_flags, fg, bg);
return (int)(text - start);
}
static inline int static inline int
add_document_line(struct plain_renderer *renderer, add_document_line(struct plain_renderer *renderer,
unsigned char *line, int line_width) unsigned char *line, int line_width)
@ -292,6 +342,12 @@ add_document_line(struct plain_renderer *renderer,
: '\0'; : '\0';
switch (line_char) { switch (line_char) {
case 27:
if (next_char != '[') goto normal;
line_pos += 2;
line_pos += change_colors(&saved_renderer_template, &line[line_pos], document);
*template = saved_renderer_template;
break;
case ASCII_BS: case ASCII_BS:
if (!(expanded + line_pos)) { if (!(expanded + line_pos)) {
/* We've backspaced to the start of the line */ /* We've backspaced to the start of the line */
@ -371,6 +427,7 @@ add_document_line(struct plain_renderer *renderer,
break; break;
} }
default: default:
normal:
{ {
int added_chars = 0; int added_chars = 0;

View File

@ -225,7 +225,7 @@ static unsigned char fg_color[16][8] = {
#define CMPCODE(c) (((c) << 1 | (c) >> 2) & TERM_COLOR_MASK) #define CMPCODE(c) (((c) << 1 | (c) >> 2) & TERM_COLOR_MASK)
#define use_inverse(bg, fg) CMPCODE(fg & TERM_COLOR_MASK) < CMPCODE(bg) #define use_inverse(bg, fg) CMPCODE(fg & TERM_COLOR_MASK) < CMPCODE(bg)
static inline void inline void
set_term_color16(struct screen_char *schar, enum color_flags flags, set_term_color16(struct screen_char *schar, enum color_flags flags,
unsigned char fg, unsigned char bg) unsigned char fg, unsigned char bg)
{ {

View File

@ -55,6 +55,9 @@ enum color_mode {
COLOR_MODES, /* XXX: Keep last */ COLOR_MODES, /* XXX: Keep last */
}; };
inline void set_term_color16(struct screen_char *schar, enum color_flags flags,
unsigned char fg, unsigned char bg);
/* Mixes the color pair and attributes to a terminal text color. */ /* Mixes the color pair and attributes to a terminal text color. */
/* If @flags has masked in the COLOR_INCREASE_CONTRAST the foreground color will /* If @flags has masked in the COLOR_INCREASE_CONTRAST the foreground color will
* be adjusted. */ * be adjusted. */