1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-28 03:06:20 -04:00

The union of the color and the node_number in the struct screen_char.

The long term goal is good looking of the Python docs in ELinks, especially
background colors. Every start tag and every text node would have associated
a natural number. Those numbers would be "drawn" in the document instead
of colors. Finally, the screen driver would change numbers into colors.

This will be done in small steps. The next step is to implement this change
in the screen driver.
This commit is contained in:
witekfl 2012-03-03 11:27:58 +01:00
parent 9c0d7dde79
commit 36070d3277
7 changed files with 56 additions and 52 deletions

View File

@ -254,8 +254,8 @@ decode_esc_color(unsigned char *text, int *line_pos, int width,
get_screen_char_color(template, &color, 0, mode);
set_term_color(&ch, &color, 0, COLOR_MODE_16);
b1 = background = (ch.color[0] >> 4) & 7;
f1 = foreground = ch.color[0] & 15;
b1 = background = (ch.c.color[0] >> 4) & 7;
f1 = foreground = ch.c.color[0] & 15;
while (tail < end) {
unsigned char kod = (unsigned char)strtol(begin, &tail, 10);

View File

@ -285,7 +285,7 @@ set_term_color16(struct screen_char *schar, enum color_flags flags,
if (use_inverse(bg, fg)) {
schar->attr |= SCREEN_ATTR_STANDOUT;
}
schar->color[0] = (bg << 4 | fg);
schar->c.color[0] = (bg << 4 | fg);
}
color_T
@ -337,32 +337,32 @@ get_screen_char_color(struct screen_char *schar, struct color_pair *pair,
/* If the desired color mode was not compiled in,
* use 16 colors. */
case COLOR_MODE_16:
bg = (schar->color[0] >> 4) & 7;
fg = schar->color[0];
bg = (schar->c.color[0] >> 4) & 7;
fg = schar->c.color[0];
pair->foreground = get_term_color16(fg);
pair->background = get_term_color16(bg);
break;
#ifdef CONFIG_88_COLORS
case COLOR_MODE_88:
pair->foreground = get_term_color88(schar->color[0]);
pair->background = get_term_color88(schar->color[1]);
pair->foreground = get_term_color88(schar->c.color[0]);
pair->background = get_term_color88(schar->c.color[1]);
break;
#endif
#ifdef CONFIG_256_COLORS
case COLOR_MODE_256:
pair->foreground = get_term_color256(schar->color[0]);
pair->background = get_term_color256(schar->color[1]);
pair->foreground = get_term_color256(schar->c.color[0]);
pair->background = get_term_color256(schar->c.color[1]);
break;
#endif
#ifdef CONFIG_TRUE_COLOR
case COLOR_MODE_TRUE_COLOR:
pair->foreground = ((schar->color[0] << 16)
| (schar->color[1] << 8)
| schar->color[2]);
pair->foreground = ((schar->c.color[0] << 16)
| (schar->c.color[1] << 8)
| schar->c.color[2]);
pair->background = ((schar->color[3] << 16)
| (schar->color[4] << 8)
| schar->color[5]);
pair->background = ((schar->c.color[3] << 16)
| (schar->c.color[4] << 8)
| schar->c.color[5]);
break;
#endif
case COLOR_MODE_DUMP:
@ -433,12 +433,12 @@ set_term_color(struct screen_char *schar, struct color_pair *pair,
pair->foreground = (pair->background == 0) ? 0xffffff : 0;
}
}
schar->color[0] = (pair->foreground >> 16) & 255; /* r */
schar->color[1] = (pair->foreground >> 8) & 255; /* g */
schar->color[2] = pair->foreground & 255; /* b */
schar->color[3] = (pair->background >> 16) & 255; /* r */
schar->color[4] = (pair->background >> 8) & 255; /* g */
schar->color[5] = pair->background & 255; /* b */
schar->c.color[0] = (pair->foreground >> 16) & 255; /* r */
schar->c.color[1] = (pair->foreground >> 8) & 255; /* g */
schar->c.color[2] = pair->foreground & 255; /* b */
schar->c.color[3] = (pair->background >> 16) & 255; /* r */
schar->c.color[4] = (pair->background >> 8) & 255; /* g */
schar->c.color[5] = pair->background & 255; /* b */
return;
#endif
case COLOR_MODE_DUMP:
@ -483,8 +483,8 @@ set_term_color(struct screen_char *schar, struct color_pair *pair,
}
}
TERM_COLOR_FOREGROUND_256(schar->color) = fg;
TERM_COLOR_BACKGROUND_256(schar->color) = bg;
TERM_COLOR_FOREGROUND_256(schar->c.color) = fg;
TERM_COLOR_BACKGROUND_256(schar->c.color) = bg;
break;
#endif
#ifdef CONFIG_TRUE_COLOR

View File

@ -26,10 +26,10 @@
#if SCREEN_COLOR_SIZE > 1
#define clear_screen_char_color(schar) \
do { memset((schar)->color, 0, SCREEN_COLOR_SIZE); } while (0)
do { memset((schar)->c.color, 0, SCREEN_COLOR_SIZE); } while (0)
#else
#define clear_screen_char_color(schar) \
do { (schar)->color[0] = 0; } while (0)
do { (schar)->c.color[0] = 0; } while (0)
#endif

View File

@ -25,6 +25,7 @@ struct terminal;
* XXX: The bold mask is used as part of the color encoding. */
enum screen_char_attr {
SCREEN_ATTR_UNSEARCHABLE = 0x01,
SCREEN_ATTR_NODE_NUMBER = 0x02,
SCREEN_ATTR_BOLD = 0x08,
SCREEN_ATTR_ITALIC = 0x10,
SCREEN_ATTR_UNDERLINE = 0x20,
@ -51,8 +52,11 @@ struct screen_char {
/** Attributes are ::screen_char_attr bits. */
unsigned char attr;
/** The fore- and background color. */
unsigned char color[SCREEN_COLOR_SIZE];
union {
/** The fore- and background color. */
unsigned char color[SCREEN_COLOR_SIZE];
unsigned int node_number;
} c;
};
/** @relates screen_char */

View File

@ -828,7 +828,7 @@ add_char16(struct string *screen, struct screen_driver *driver,
add_bytes_to_string(screen, "\033[1m", 4);
} else {
/* Force repainting of the other attributes. */
state->color[0] = ch->color[0] + 1;
state->color[0] = ch->c.color[0] + 1;
}
}
@ -836,9 +836,9 @@ add_char16(struct string *screen, struct screen_driver *driver,
#ifdef CONFIG_UTF8
!(driver->opt.utf8_cp && ch->data == UCS_NO_CHAR) &&
#endif /* CONFIG_UTF8 */
!compare_color_16(ch->color, state->color)
!compare_color_16(ch->c.color, state->color)
) {
copy_color_16(state->color, ch->color);
copy_color_16(state->color, ch->c.color);
add_bytes_to_string(screen, "\033[0", 3);
@ -852,9 +852,9 @@ add_char16(struct string *screen, struct screen_driver *driver,
* - An unsupported color mode. Use 16 colors. */
if (driver->opt.color_mode != COLOR_MODE_MONO) {
unsigned char code[6] = ";30;40";
unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(ch->color);
unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(ch->c.color);
code[2] += TERM_COLOR_FOREGROUND_16(ch->color);
code[2] += TERM_COLOR_FOREGROUND_16(ch->c.color);
if (!driver->opt.transparent || bgcolor != 0) {
code[5] += bgcolor;
@ -936,8 +936,8 @@ add_char_color(struct string *screen, const struct string *seq, unsigned char co
add_bytes_to_string(screen, &seq->source[seq_pos], seq->length - seq_pos);
}
#define add_background_color(str, seq, chr) add_char_color(str, &(seq)[1], (chr)->color[1])
#define add_foreground_color(str, seq, chr) add_char_color(str, &(seq)[0], (chr)->color[0])
#define add_background_color(str, seq, chr) add_char_color(str, &(seq)[1], (chr)->c.color[1])
#define add_foreground_color(str, seq, chr) add_char_color(str, &(seq)[0], (chr)->c.color[0])
/** Time critical section. */
static inline void
@ -972,7 +972,7 @@ add_char256(struct string *screen, struct screen_driver *driver,
add_bytes_to_string(screen, "\033[1m", 4);
} else {
/* Force repainting of the other attributes. */
state->color[0] = ch->color[0] + 1;
state->color[0] = ch->c.color[0] + 1;
}
}
@ -983,12 +983,12 @@ add_char256(struct string *screen, struct screen_driver *driver,
#ifdef CONFIG_UTF8
!(driver->opt.utf8_cp && ch->data == UCS_NO_CHAR) &&
#endif /* CONFIG_UTF8 */
!compare_color_256(ch->color, state->color)
!compare_color_256(ch->c.color, state->color)
) {
copy_color_256(state->color, ch->color);
copy_color_256(state->color, ch->c.color);
add_foreground_color(screen, driver->opt.color256_seqs, ch);
if (!driver->opt.transparent || ch->color[1] != 0) {
if (!driver->opt.transparent || ch->c.color[1] != 0) {
add_background_color(screen, driver->opt.color256_seqs, ch);
}
@ -1015,8 +1015,8 @@ static const struct string color_true_seqs[] = {
/* foreground: */ TERM_STRING("\033[0;38;2"),
/* background: */ TERM_STRING("\033[48;2"),
};
#define add_true_background_color(str, seq, chr) add_char_true_color(str, &(seq)[1], &(chr)->color[3])
#define add_true_foreground_color(str, seq, chr) add_char_true_color(str, &(seq)[0], &(chr)->color[0])
#define add_true_background_color(str, seq, chr) add_char_true_color(str, &(seq)[1], &(chr)->c.color[3])
#define add_true_foreground_color(str, seq, chr) add_char_true_color(str, &(seq)[0], &(chr)->c.color[0])
static inline void
add_char_true_color(struct string *screen, const struct string *seq, unsigned char *colors)
{
@ -1097,7 +1097,7 @@ add_char_true(struct string *screen, struct screen_driver *driver,
add_bytes_to_string(screen, "\033[1m", 4);
} else {
/* Force repainting of the other attributes. */
state->color[0] = ch->color[0] + 1;
state->color[0] = ch->c.color[0] + 1;
}
}
@ -1108,12 +1108,12 @@ add_char_true(struct string *screen, struct screen_driver *driver,
#ifdef CONFIG_UTF8
!(driver->opt.utf8_cp && ch->data == UCS_NO_CHAR) &&
#endif /* CONFIG_UTF8 */
!compare_color_true(ch->color, state->color)
!compare_color_true(ch->c.color, state->color)
) {
copy_color_true(state->color, ch->color);
copy_color_true(state->color, ch->c.color);
add_true_foreground_color(screen, color_true_seqs, ch);
if (!driver->opt.transparent || !background_is_black(ch->color)) {
if (!driver->opt.transparent || !background_is_black(ch->c.color)) {
add_true_background_color(screen, color_true_seqs, ch);
}
@ -1166,9 +1166,9 @@ add_char_true(struct string *screen, struct screen_driver *driver,
if (is_last_line && x == xmax) \
break; \
\
if (compare_bg_color(pos->color, current->color)) { \
if (compare_bg_color(pos->c.color, current->c.color)) { \
/* No update for exact match. */ \
if (compare_fg_color(pos->color, current->color)\
if (compare_fg_color(pos->c.color, current->c.color)\
&& pos->data == current->data \
&& pos->attr == current->attr) \
continue; \

View File

@ -68,17 +68,17 @@ DUMP_FUNCTION_SPECIALIZED(struct document *document, struct dump_output *out)
= document->data[y].chars[x].attr;
#ifdef DUMP_COLOR_MODE_16
const unsigned char color1
= document->data[y].chars[x].color[0];
= document->data[y].chars[x].c.color[0];
#elif defined(DUMP_COLOR_MODE_256)
const unsigned char color1
= document->data[y].chars[x].color[0];
= document->data[y].chars[x].c.color[0];
const unsigned char color2
= document->data[y].chars[x].color[1];
= document->data[y].chars[x].c.color[1];
#elif defined(DUMP_COLOR_MODE_TRUE)
const unsigned char *const new_foreground
= &document->data[y].chars[x].color[0];
= &document->data[y].chars[x].c.color[0];
const unsigned char *const new_background
= &document->data[y].chars[x].color[3];
= &document->data[y].chars[x].c.color[3];
#endif /* DUMP_COLOR_MODE_TRUE */
c = document->data[y].chars[x].data;

View File

@ -271,7 +271,7 @@ draw_current_link(struct session *ses, struct document_view *doc_view)
if (i == cursor_offset) {
int blockable = (!link_is_textinput(link)
&& co->color != template->color);
&& co->c.color != template->c.color);
set_cursor(term, x, y, blockable);
set_window_ptr(ses->tab, x, y);