mirror of
https://github.com/rkd77/elinks.git
synced 2024-10-05 04:24:03 -04: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:
parent
8ce8740359
commit
3ce3f01f30
@ -643,7 +643,13 @@ del_chars(struct html_context *html_context, int x, int y)
|
||||
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
|
||||
split_line_at(struct html_context *html_context, int width)
|
||||
@ -1380,7 +1386,7 @@ put_chars(struct html_context *html_context, unsigned char *chars, int charslen)
|
||||
part->cx += charslen;
|
||||
renderer_context.nobreak = 0;
|
||||
|
||||
if (!html_is_preformatted()) {
|
||||
if (!(html_context->options->wrap || html_is_preformatted())) {
|
||||
while (part->cx > overlap(par_format)
|
||||
&& part->cx > par_format.leftmargin) {
|
||||
int x = split_line(html_context);
|
||||
|
@ -447,16 +447,18 @@ add_document_lines(struct plain_renderer *renderer)
|
||||
unsigned char *source = renderer->source;
|
||||
int length = renderer->length;
|
||||
int was_empty_line = 0;
|
||||
int was_wrapped = 0;
|
||||
|
||||
for (; length > 0; renderer->lineno++) {
|
||||
unsigned char *xsource;
|
||||
int width, added, only_spaces = 1, spaces = 0, was_spaces = 0;
|
||||
int last_space = 0;
|
||||
int tab_spaces = 0;
|
||||
int step = 0;
|
||||
int doc_width = int_min(renderer->max_width, length);
|
||||
|
||||
/* 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)
|
||||
step++;
|
||||
if (source[width + step] == ASCII_LF)
|
||||
@ -469,6 +471,8 @@ add_document_lines(struct plain_renderer *renderer)
|
||||
spaces++;
|
||||
else
|
||||
was_spaces++;
|
||||
if (source[width] == '\t')
|
||||
tab_spaces += 7 - ((width + tab_spaces) % 8);
|
||||
} else {
|
||||
only_spaces = 0;
|
||||
was_spaces = 0;
|
||||
@ -476,7 +480,7 @@ add_document_lines(struct plain_renderer *renderer)
|
||||
}
|
||||
|
||||
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. */
|
||||
length -= step + spaces;
|
||||
source += step + spaces;
|
||||
@ -493,6 +497,7 @@ add_document_lines(struct plain_renderer *renderer)
|
||||
|
||||
} else {
|
||||
was_empty_line = 0;
|
||||
was_wrapped = !step;
|
||||
|
||||
if (was_spaces && step) {
|
||||
/* Drop trailing whitespaces. */
|
||||
|
@ -106,4 +106,8 @@
|
||||
#define DEFAULT_TERMINAL_WIDTH 80
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user