From ed1afeb648416e4bb5da8baa6fc564e2a1ac7ed2 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 26 May 2023 19:46:07 +0200 Subject: [PATCH] [options] Added bool option document.plain.sixel --- src/config/options.inc | 6 ++++++ src/document/options.c | 1 + src/document/options.h | 4 ++++ src/document/plain/renderer.c | 7 ++++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/config/options.inc b/src/config/options.inc index 05d61a6f..63f3cf0c 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -868,6 +868,12 @@ static union option_info config_options_info[] = { N_("Change ascii border characters to frame borders. Usage example: " "mysql --pager=elinks")), +#ifdef CONFIG_LIBSIXEL + INIT_OPT_BOOL("document.plain", N_("Sixel"), + "sixel", OPT_ZERO, 0, + N_("Whether to display sixel images in plain text documents.")), +#endif + INIT_OPT_TREE("document", N_("URI passing"), "uri_passing", OPT_SORT | OPT_AUTOCREATE, N_("Rules for passing URIs to external commands. When one " diff --git a/src/document/options.c b/src/document/options.c index 5247ec9f..7ec9f4fa 100644 --- a/src/document/options.c +++ b/src/document/options.c @@ -115,6 +115,7 @@ init_document_options(struct session *ses, struct document_options *doo) doo->image_link.tagging = get_opt_int("document.browse.images.image_link_tagging", ses); doo->image_link.show_any_as_links = get_opt_bool("document.browse.images.show_any_as_links", ses); #ifdef CONFIG_LIBSIXEL + doo->sixel = get_opt_bool("document.plain.sixel", ses); if (ses && ses->tab->term) { doo->cell_width = ses->tab->term->cell_width; doo->cell_height = ses->tab->term->cell_height; diff --git a/src/document/options.h b/src/document/options.h index 86f8c202..c6c5536e 100644 --- a/src/document/options.h +++ b/src/document/options.h @@ -161,6 +161,10 @@ struct document_options { unsigned int utf8:1; #endif /* CONFIG_UTF8 */ unsigned int dump:1; + +#ifdef CONFIG_LIBSIXEL + unsigned int sixel:1; +#endif /** Active link coloring. * This is mostly here to make use of this option cache so * link drawing is faster. --jonas */ diff --git a/src/document/plain/renderer.c b/src/document/plain/renderer.c index a32bfde4..83218816 100644 --- a/src/document/plain/renderer.c +++ b/src/document/plain/renderer.c @@ -56,6 +56,8 @@ struct plain_renderer { /* Are we doing line compression */ unsigned int compress:1; + + unsigned int sixel:1; }; #define realloc_document_links(doc, size) \ @@ -642,7 +644,7 @@ add_document_line(struct plain_renderer *renderer, template_->attr |= pos->attr; } else if (line_char == 27) { #ifdef CONFIG_LIBSIXEL - if (line_pos + 1 < width && line[line_pos + 1] == 'P') { // && line_pos + 2 < width && line[line_pos + 2] == 'q') { + if (renderer->sixel && line_pos + 1 < width && line[line_pos + 1] == 'P') { // && line_pos + 2 < width && line[line_pos + 2] == 'q') { while (1) { char *end = (char *)memchr(line + line_pos + 1, 27, width - line_pos - 1); @@ -1013,6 +1015,9 @@ render_plain_document(struct cache_entry *cached, struct document *document, renderer.lineno = 0; renderer.convert_table = convert_table; renderer.compress = document->options.plain_compress_empty_lines; +#ifdef CONFIG_LIBSIXEL + renderer.sixel = document->options.sixel; +#endif renderer.max_width = document->options.wrap ? document->options.document_width : INT_MAX;