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

Color leading spaces with the color of the first non-space character.

Also color trailing spaces with the color of the last character.

See for example gtk-doc.
This commit is contained in:
witekfl 2012-07-11 11:14:03 +02:00
parent aead2de59a
commit 42d2433f4b
3 changed files with 38 additions and 3 deletions

View File

@ -141,6 +141,17 @@ draw_char_data(struct terminal *term, int x, int y, unsigned char data)
set_screen_dirty(term->screen, y, y);
}
void
draw_space(struct terminal *term, int x, int y, struct screen_char *color)
{
struct screen_char *screen_char = get_char(term, x, y);
if (!screen_char) return;
screen_char->data = ' ';
if (color) screen_char->c = color->c;
}
/*! Used by viewer to copy over a document.
* When doing frame drawing @a x can be different than 0. */
void

View File

@ -260,6 +260,9 @@ void draw_char(struct terminal *term, int x, int y,
struct color_pair *color);
#endif /* CONFIG_UTF8 */
void draw_space(struct terminal *term, int x, int y,
struct screen_char *color);
/** Draws area defined by @a box using the same colors and attributes. */
void draw_box(struct terminal *term, struct box *box,
unsigned char data, enum screen_char_attr attr,

View File

@ -203,6 +203,8 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
struct view_state *vs;
struct terminal *term;
struct box *box;
struct screen_char *last = NULL;
int vx, vy;
int y;
@ -287,13 +289,32 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
for (y = int_max(vy, 0);
y < int_min(doc_view->document->height, box->height + vy);
y++) {
struct screen_char *first = NULL;
int i, j;
int st = int_max(vx, 0);
int en = int_min(doc_view->document->data[y].length,
box->width + vx);
if (en - st <= 0) continue;
draw_line(term, box->x + st - vx, box->y + y - vy, en - st,
&doc_view->document->data[y].chars[st]);
if (en - st > 0) {
draw_line(term, box->x + st - vx, box->y + y - vy,
en - st,
&doc_view->document->data[y].chars[st]);
last = &doc_view->document->data[y].chars[en - 1];
}
for (i = st; i < en; i++) {
if (doc_view->document->data[y].chars[i].data != ' ') {
first = &doc_view->document->data[y].chars[i];
break;
}
}
for (j = st + 1; j < i; j++) {
draw_space(term, box->x + j - vx, box->y + y - vy,
first);
}
for (i = en ? en : 1; i < box->width + vx - 1; i++) {
draw_space(term, box->x + i - vx, box->y + y - vy,
last);
}
}
draw_view_status(ses, doc_view, active);
if (has_search_word(doc_view))