Had to fix patches #5 and again #9 (the caption string of options 
shouldn't end with '.')

-- 
 ‎أحمد المحمودي (Ahmed El-Mahmoudy)
  Digital design engineer
 GPG KeyID: 0x9DCA0B27 (@ subkeys.pgp.net)
 GPG Fingerprint: 087D 3767 8CAC 65B1 8F6C  156E D325 C3C8 9DCA 0B27
Provide different color for text areas in insert mode.
The color is controlled by

  document.browse.links.active_link.insert_mode_colors.background
  document.browse.links.active_link.insert_mode_colors.text

Also avoid overloading local variable "i" in get_current_link().
By: yozoh...@gmail.com
---
 src/config/options.inc  |   12 ++++++++++++
 src/document/document.c |    2 ++
 src/document/options.c  |    2 ++
 src/document/options.h  |    1 +
 src/viewer/text/link.c  |   17 ++++++++++++-----
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/src/config/options.inc b/src/config/options.inc
index 340ab93..7098854 100644
--- a/src/config/options.inc
+++ b/src/config/options.inc
@@ -294,6 +294,18 @@ static struct option_info config_options_info[] = {
                "text", 0, "black",
                N_("Default text color.")),
 
+       INIT_OPT_TREE("document.browse.links.active_link", N_("Insert mode 
colors"),
+               "insert_mode_colors", 0,
+               N_("Insert mode colors.")),
+
+       INIT_OPT_COLOR("document.browse.links.active_link.insert_mode_colors", 
N_("Background color for text field in insert mode"),
+               "background", 0, "#0000ff",
+               N_("Background color for text field in insert mode")),
+
+       INIT_OPT_COLOR("document.browse.links.active_link.insert_mode_colors", 
N_("Text color for text field in insert mode"),
+               "text", 0, "black",
+               N_("Text color for text field in insert mode.")),
+
        INIT_OPT_BOOL("document.browse.links.active_link", N_("Enable color"),
                "enable_color", 0, 0,
                N_("Enable use of the active link background and text color "
diff --git a/src/document/document.c b/src/document/document.c
index 5424f6f..19ee2d0 100644
--- a/src/document/document.c
+++ b/src/document/document.c
@@ -234,6 +234,8 @@ update_cached_document_options(struct session *ses)
        memset(&active_link, 0, sizeof(active_link));   /* Safer. */
        active_link.color.foreground = 
get_opt_color("document.browse.links.active_link.colors.text", ses);
        active_link.color.background = 
get_opt_color("document.browse.links.active_link.colors.background", ses);
+       active_link.insert_mode_color.foreground = 
get_opt_color("document.browse.links.active_link.insert_mode_colors.text", ses);
+       active_link.insert_mode_color.background = 
get_opt_color("document.browse.links.active_link.insert_mode_colors.background",
 ses);
        active_link.enable_color = 
get_opt_bool("document.browse.links.active_link.enable_color", ses);
        active_link.invert = 
get_opt_bool("document.browse.links.active_link.invert", ses);
        active_link.underline = 
get_opt_bool("document.browse.links.active_link.underline", ses);
diff --git a/src/document/options.c b/src/document/options.c
index b681fda..9208d64 100644
--- a/src/document/options.c
+++ b/src/document/options.c
@@ -52,6 +52,8 @@ init_document_options(struct session *ses, struct 
document_options *doo)
 
        doo->active_link.color.foreground = 
get_opt_color("document.browse.links.active_link.colors.text", ses);
        doo->active_link.color.background = 
get_opt_color("document.browse.links.active_link.colors.background", ses);
+       doo->active_link.insert_mode_color.foreground = 
get_opt_color("document.browse.links.active_link.insert_mode_colors.text", ses);
+       doo->active_link.insert_mode_color.background = 
get_opt_color("document.browse.links.active_link.insert_mode_colors.background",
 ses);
 
        if (get_opt_bool("document.colors.increase_contrast", ses))
                doo->color_flags |= COLOR_INCREASE_CONTRAST;
diff --git a/src/document/options.h b/src/document/options.h
index d3bd29a..52c1956 100644
--- a/src/document/options.h
+++ b/src/document/options.h
@@ -20,6 +20,7 @@ struct active_link_options {
        unsigned int bold:1;
        unsigned int invert:1;
        struct active_link_options_colors color;
+       struct active_link_options_colors insert_mode_color;
 };
 
 /** This mostly acts as a option cache so rendering will be faster. However it
diff --git a/src/viewer/text/link.c b/src/viewer/text/link.c
index a9021b0..eaa15f1 100644
--- a/src/viewer/text/link.c
+++ b/src/viewer/text/link.c
@@ -165,7 +165,7 @@ get_link_cursor_offset(struct document_view *doc_view, 
struct link *link)
 /** Initialise a static template character with the colour and attributes
  * appropriate for an active link and return that character. */
 static inline struct screen_char *
-init_link_drawing(struct document_view *doc_view, struct link *link, int 
invert)
+init_link_drawing(struct document_view *doc_view, struct link *link, int 
invert, int input)
 {
        struct document_options *doc_opts;
        static struct screen_char template;
@@ -187,8 +187,13 @@ init_link_drawing(struct document_view *doc_view, struct 
link *link, int invert)
                template.attr |= SCREEN_ATTR_BOLD;
 
        if (doc_opts->active_link.enable_color) {
-               colors.foreground = doc_opts->active_link.color.foreground;
-               colors.background = doc_opts->active_link.color.background;
+               if (input) {
+                       colors.foreground = 
doc_opts->active_link.insert_mode_color.foreground;
+                       colors.background = 
doc_opts->active_link.insert_mode_color.background;
+               } else {
+                       colors.foreground = 
doc_opts->active_link.color.foreground;
+                       colors.background = 
doc_opts->active_link.color.background;
+               }
        } else {
                colors.foreground = link->color.foreground;
                colors.background = link->color.background;
@@ -231,6 +236,7 @@ draw_current_link(struct session *ses, struct document_view 
*doc_view)
        struct link *link;
        int cursor_offset;
        int xpos, ypos;
+       int invert, input;
        int i;
 
        assert(term && doc_view && doc_view->vs);
@@ -242,8 +248,9 @@ draw_current_link(struct session *ses, struct document_view 
*doc_view)
        link = get_current_link(doc_view);
        if (!link) return;
 
-       i = !link_is_textinput(link) || ses->insert_mode == INSERT_MODE_OFF;
-       template = init_link_drawing(doc_view, link, i);
+       invert = !link_is_textinput(link) || ses->insert_mode == 
INSERT_MODE_OFF;
+       input = ses->insert_mode == INSERT_MODE_ON;
+       template = init_link_drawing(doc_view, link, invert, input);
        if (!template) return;
 
        xpos = doc_view->box.x - doc_view->vs->x;
-- 
1.6.3

_______________________________________________
elinks-dev mailing list
elinks-dev@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-dev
Add preferred_document_width option.
Option document.browse.preferred_document_width controls the
width of the document, so that documents are rendered with narrower
width than screen width.  Makes it easier to read paragraphs.

Patch originally from Sharon Wood <ds...@pele.cx>, see bug #1063.

Instead of using max_document_width as the hard limit to the document
width, it uses a soft limit, where if the document does not fit (due to
tables, etc.), then larger width is used.  This reduces the need for
horizontal scrolling for wide documents.

Also added toggle-document-width action to toggle between preferred
width and full screen width.  Initial toggle status is determined by
document.browse.use_preferred_document_width option.
By: yozoh...@gmail.com
---
 src/config/actions-main.inc        |    1 +
 src/config/options.inc             |   10 ++++++++++
 src/document/html/parser.c         |    2 +-
 src/document/html/parser/forms.c   |    8 ++++----
 src/document/html/parser/general.c |    2 +-
 src/document/html/renderer.c       |    4 ++--
 src/document/options.c             |    7 +++++++
 src/document/options.h             |    1 +
 src/document/plain/renderer.c      |    2 +-
 src/document/renderer.c            |    3 +--
 src/viewer/action.c                |    5 +++++
 11 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/src/config/actions-main.inc b/src/config/actions-main.inc
index 21ff838..25543f1 100644
--- a/src/config/actions-main.inc
+++ b/src/config/actions-main.inc
@@ -117,6 +117,7 @@ ACTION_(MAIN, "toggle-css", TOGGLE_CSS, N__("Toggle 
rendering of page using CSS"
 ACTION_(MAIN, "toggle-display-images", TOGGLE_DISPLAY_IMAGES, N__("Toggle 
displaying of links to images"), 0),
 ACTION_(MAIN, "toggle-display-tables", TOGGLE_DISPLAY_TABLES, N__("Toggle 
rendering of tables"), 0),
 ACTION_(MAIN, "toggle-document-colors", TOGGLE_DOCUMENT_COLORS, N__("Toggle 
usage of document specific colors"), 0),
+ACTION_(MAIN, "toggle-document-width", TOGGLE_DOCUMENT_WIDTH, N__("Toggle use 
of document width"), 0),
 ACTION_(MAIN, "toggle-html-plain", TOGGLE_HTML_PLAIN, N__("Toggle rendering 
page as HTML / plain text"), 0),
 ACTION_(MAIN, "toggle-mouse", TOGGLE_MOUSE, N__("Toggle mouse handling"), 0),
 ACTION_(MAIN, "toggle-numbered-links", TOGGLE_NUMBERED_LINKS, N__("Toggle 
displaying of links numbers"), 0),
diff --git a/src/config/options.inc b/src/config/options.inc
index 7098854..468d0ca 100644
--- a/src/config/options.inc
+++ b/src/config/options.inc
@@ -464,6 +464,16 @@ static struct option_info config_options_info[] = {
                "margin_width", 0, 0, 100, 3,
                N_("Horizontal text margin.")),
 
+       INIT_OPT_INT("document.browse", N_("Preferred document width"),
+               "preferred_document_width", 0, 0, 9999, 80,
+               N_("Try to fit the document within this width.  If set to zero,"
+               "use screen width.")),
+
+       INIT_OPT_BOOL("document.browse", N_("Whether to use preferred document 
width"),
+               "use_preferred_document_width", 0, 1,
+               N_("Whether to use preferred document width.  If set to zero,\n"
+               "use screen width.  If set to one, use 
preferred_document_width.")),
+
        INIT_OPT_BOOL("document.browse", N_("Document meta refresh"),
                "refresh", 0, 1,
                N_("Automatically follow document-specified refresh "
diff --git a/src/document/html/parser.c b/src/document/html/parser.c
index f3305db..c3cd635 100644
--- a/src/document/html/parser.c
+++ b/src/document/html/parser.c
@@ -930,7 +930,7 @@ init_html_parser(struct uri *uri, struct document_options 
*options,
        par_format.leftmargin = options->margin;
        par_format.rightmargin = options->margin;
 
-       par_format.width = options->box.width;
+       par_format.width = options->document_width;
        par_format.list_level = par_format.list_number = 0;
        par_format.dd_margin = options->margin;
        par_format.flags = P_NONE;
diff --git a/src/document/html/parser/forms.c b/src/document/html/parser/forms.c
index 95bdf61..9a642b8 100644
--- a/src/document/html/parser/forms.c
+++ b/src/document/html/parser/forms.c
@@ -323,8 +323,8 @@ html_input(struct html_context *html_context, unsigned char 
*a,
        if (fc->size == -1)
                fc->size = html_context->options->default_form_input_size;
        fc->size++;
-       if (fc->size > html_context->options->box.width)
-               fc->size = html_context->options->box.width;
+       if (fc->size > html_context->options->document_width)
+               fc->size = html_context->options->document_width;
        fc->maxlength = get_num(a, "maxlength", cp);
        if (fc->maxlength == -1) fc->maxlength = INT_MAX;
        if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO)
@@ -689,8 +689,8 @@ pp:
                cols = html_context->options->default_form_input_size;
        cols++; /* Add 1 column, other browsers may have different
                   behavior here (mozilla adds 2) --Zas */
-       if (cols > html_context->options->box.width)
-               cols = html_context->options->box.width;
+       if (cols > html_context->options->document_width)
+               cols = html_context->options->document_width;
        fc->cols = cols;
 
        rows = get_num(attr, "rows", html_context->doc_cp);
diff --git a/src/document/html/parser/general.c 
b/src/document/html/parser/general.c
index 063ddcd..195421b 100644
--- a/src/document/html/parser/general.c
+++ b/src/document/html/parser/general.c
@@ -1066,7 +1066,7 @@ html_frameset(struct html_context *html_context, unsigned 
char *a,
        }
 
        if (!html_top->frameset) {
-               width = html_context->options->box.width;
+               width = html_context->options->document_width;
                height = html_context->options->box.height;
                html_context->options->needs_height = 1;
        } else {
diff --git a/src/document/html/renderer.c b/src/document/html/renderer.c
index ecbf534..d0ef32d 100644
--- a/src/document/html/renderer.c
+++ b/src/document/html/renderer.c
@@ -953,7 +953,7 @@ del_chars(struct html_context *html_context, int x, int y)
 # define overlap_width(x) (x).width
 #else
 # define overlap_width(x) int_min((x).width, \
-       html_context->options->box.width - TABLE_LINE_PADDING)
+       html_context->options->document_width - TABLE_LINE_PADDING)
 #endif
 #define overlap(x) int_max(overlap_width(x) - (x).rightmargin, 0)
 
@@ -2456,7 +2456,7 @@ render_html_document(struct cache_entry *cached, struct 
document *document,
 
        part = format_html_part(html_context, start, end, par_format.align,
                                par_format.leftmargin,
-                               document->options.box.width, document,
+                               document->options.document_width, document,
                                0, 0, head.source, 1);
 
        /* Drop empty allocated lines at end of document if any
diff --git a/src/document/options.c b/src/document/options.c
index 9208d64..93d9c7b 100644
--- a/src/document/options.c
+++ b/src/document/options.c
@@ -32,6 +32,13 @@ init_document_options(struct session *ses, struct 
document_options *doo)
 
        doo->use_document_colors = 
get_opt_int("document.colors.use_document_colors", ses);
        doo->margin = get_opt_int("document.browse.margin_width", ses);
+
+       doo->document_width = 0;
+       if (get_opt_bool("document.browse.use_preferred_document_width", ses))
+               doo->document_width = 
get_opt_int("document.browse.preferred_document_width", ses);
+       if (doo->document_width <= 0 || doo->document_width > 
ses->tab->term->width)
+               doo->document_width = ses->tab->term->width;
+
        doo->num_links_key = 
get_opt_int("document.browse.links.number_keys_select_link", ses);
        doo->meta_link_display = get_opt_int("document.html.link_display", ses);
        doo->default_form_input_size = 
get_opt_int("document.browse.forms.input_size", ses);
diff --git a/src/document/options.h b/src/document/options.h
index 52c1956..10dc462 100644
--- a/src/document/options.h
+++ b/src/document/options.h
@@ -58,6 +58,7 @@ struct document_options {
        int use_document_colors;
        int meta_link_display;
        int default_form_input_size;
+       int document_width;
 
        /** @name The default (fallback) colors.
         * @{ */
diff --git a/src/document/plain/renderer.c b/src/document/plain/renderer.c
index 98c0f26..3911c14 100644
--- a/src/document/plain/renderer.c
+++ b/src/document/plain/renderer.c
@@ -634,7 +634,7 @@ 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;
-       renderer.max_width = document->options.wrap ? 
document->options.box.width
+       renderer.max_width = document->options.wrap ? 
document->options.document_width
                                                    : INT_MAX;
 
        document->color.background = 
document->options.default_style.color.background;
diff --git a/src/document/renderer.c b/src/document/renderer.c
index 71e1c69..78d9a19 100644
--- a/src/document/renderer.c
+++ b/src/document/renderer.c
@@ -439,8 +439,7 @@ render_document_frames(struct session *ses, int no_cache)
 
        init_document_options(ses, &doc_opts);
 
-       set_box(&doc_opts.box, 0, 0,
-               ses->tab->term->width, ses->tab->term->height);
+       set_box(&doc_opts.box, 0, 0, ses->tab->term->width, 
ses->tab->term->height);
 
        if (ses->status.show_title_bar) {
                doc_opts.box.y++;
diff --git a/src/viewer/action.c b/src/viewer/action.c
index 66e20bb..7f7f076 100644
--- a/src/viewer/action.c
+++ b/src/viewer/action.c
@@ -604,6 +604,11 @@ do_action(struct session *ses, enum main_action action_id, 
int verbose)
                        toggle_document_option(ses, 
"document.colors.use_document_colors");
                        break;
 
+               case ACT_MAIN_TOGGLE_DOCUMENT_WIDTH:
+                       toggle_document_option(ses, 
"document.browse.use_preferred_document_width");
+                       redraw_terminal_cls(term);
+                       break;
+
                case ACT_MAIN_TOGGLE_HTML_PLAIN:
                        toggle_plain_html(ses, ses->doc_view, 0);
                        break;
-- 
1.6.3

_______________________________________________
elinks-dev mailing list
elinks-dev@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-dev
_______________________________________________
elinks-dev mailing list
elinks-dev@linuxfromscratch.org
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to