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

Add support for forcing wrapping at the screen boundary

This patch modifies ELinks wrapping behavior slightly.

 * The wrap command now toggles line wrapping in HTML mode, as well as
   text mode.  Note that when the HTML view of a page is wrapped, its
   source view is unwrapped, and vice versa.
 * Tabs in text-mode lines are now handled correctly.
 * Wrapping a line that reaches exactly to the edge of the screen will
   no longer produce a blank line in text mode.
 * Text within extra-wide table cells is now wrapped to less than the
   screen width, to eliminate sideways scrolling.

The last point is only enabled by setting TABLE_LINE_PADDING to a
non-negative number, in the src/setup.h header file, because it is a
significant change of behavior from previous versions.
This commit is contained in:
Eric Wald 2006-02-15 15:46:21 +01:00 committed by Jonas Fonseca
parent 4b1425f762
commit c38e8dc40b
3 changed files with 19 additions and 4 deletions

View File

@ -643,7 +643,13 @@ del_chars(struct html_context *html_context, int x, int y)
move_links(html_context, x, y, -1, -1); move_links(html_context, x, y, -1, -1);
} }
#define overlap(x) int_max((x).width - (x).rightmargin, 0) #if TABLE_LINE_PADDING < 0
# define overlap_width(x) (x).width
#else
# define overlap_width(x) int_min((x).width, \
html_context->options->box.width - TABLE_LINE_PADDING)
#endif
#define overlap(x) int_max(overlap_width(x) - (x).rightmargin, 0)
static int inline static int inline
split_line_at(struct html_context *html_context, int width) split_line_at(struct html_context *html_context, int width)
@ -1379,7 +1385,7 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
part->cx += charslen; part->cx += charslen;
renderer_context.nobreak = 0; renderer_context.nobreak = 0;
if (!html_is_preformatted()) { if (!(html_context->options->wrap || html_is_preformatted())) {
while (part->cx > overlap(par_format) while (part->cx > overlap(par_format)
&& part->cx > par_format.leftmargin) { && part->cx > par_format.leftmargin) {
int x = split_line(html_context); int x = split_line(html_context);

View File

@ -447,16 +447,18 @@ add_document_lines(struct plain_renderer *renderer)
unsigned char *source = renderer->source; unsigned char *source = renderer->source;
int length = renderer->length; int length = renderer->length;
int was_empty_line = 0; int was_empty_line = 0;
int was_wrapped = 0;
for (; length > 0; renderer->lineno++) { for (; length > 0; renderer->lineno++) {
unsigned char *xsource; unsigned char *xsource;
int width, added, only_spaces = 1, spaces = 0, was_spaces = 0; int width, added, only_spaces = 1, spaces = 0, was_spaces = 0;
int last_space = 0; int last_space = 0;
int tab_spaces = 0;
int step = 0; int step = 0;
int doc_width = int_min(renderer->max_width, length); int doc_width = int_min(renderer->max_width, length);
/* End of line detection: We handle \r, \r\n and \n types. */ /* End of line detection: We handle \r, \r\n and \n types. */
for (width = 0; width < doc_width; width++) { for (width = 0; width + tab_spaces < doc_width; width++) {
if (source[width] == ASCII_CR) if (source[width] == ASCII_CR)
step++; step++;
if (source[width + step] == ASCII_LF) if (source[width + step] == ASCII_LF)
@ -469,6 +471,8 @@ add_document_lines(struct plain_renderer *renderer)
spaces++; spaces++;
else else
was_spaces++; was_spaces++;
if (source[width] == '\t')
tab_spaces += 7 - ((width + tab_spaces) % 8);
} else { } else {
only_spaces = 0; only_spaces = 0;
was_spaces = 0; was_spaces = 0;
@ -476,7 +480,7 @@ add_document_lines(struct plain_renderer *renderer)
} }
if (only_spaces && step) { if (only_spaces && step) {
if (renderer->compress && was_empty_line) { if (was_wrapped || (renderer->compress && was_empty_line)) {
/* Successive empty lines will appear as one. */ /* Successive empty lines will appear as one. */
length -= step + spaces; length -= step + spaces;
source += step + spaces; source += step + spaces;
@ -493,6 +497,7 @@ add_document_lines(struct plain_renderer *renderer)
} else { } else {
was_empty_line = 0; was_empty_line = 0;
was_wrapped = !step;
if (was_spaces && step) { if (was_spaces && step) {
/* Drop trailing whitespaces. */ /* Drop trailing whitespaces. */

View File

@ -106,4 +106,8 @@
#define DEFAULT_TERMINAL_WIDTH 80 #define DEFAULT_TERMINAL_WIDTH 80
#define DEFAULT_TERMINAL_HEIGHT 25 #define DEFAULT_TERMINAL_HEIGHT 25
/* If this is non-negative, lines in extra-wide table cells will be wrapped
* to fit in the screen, with this much extra space. Try 4. */
#define TABLE_LINE_PADDING -1
#endif #endif