mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-11 05:29:28 -04:00
plain_renderer: cg-log -c | elinks works. The code needs cleanup
This commit is contained in:
parent
1feab80c13
commit
88c146a395
@ -6,6 +6,7 @@
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "elinks.h"
|
||||
|
||||
@ -226,6 +227,55 @@ print_document_link(struct plain_renderer *renderer, int lineno,
|
||||
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
|
||||
add_document_line(struct plain_renderer *renderer,
|
||||
unsigned char *line, int line_width)
|
||||
@ -292,6 +342,12 @@ add_document_line(struct plain_renderer *renderer,
|
||||
: '\0';
|
||||
|
||||
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:
|
||||
if (!(expanded + line_pos)) {
|
||||
/* We've backspaced to the start of the line */
|
||||
@ -371,6 +427,7 @@ add_document_line(struct plain_renderer *renderer,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
normal:
|
||||
{
|
||||
int added_chars = 0;
|
||||
|
||||
|
@ -225,7 +225,7 @@ static unsigned char fg_color[16][8] = {
|
||||
#define CMPCODE(c) (((c) << 1 | (c) >> 2) & TERM_COLOR_MASK)
|
||||
#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,
|
||||
unsigned char fg, unsigned char bg)
|
||||
{
|
||||
|
@ -55,6 +55,9 @@ enum color_mode {
|
||||
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. */
|
||||
/* If @flags has masked in the COLOR_INCREASE_CONTRAST the foreground color will
|
||||
* be adjusted. */
|
||||
|
Loading…
Reference in New Issue
Block a user