#825790 w3m: -cols should work without -dump

Package:
w3m
Source:
w3m
Description:
WWW browsable pager with excellent tables/frames support
Submitter:
Eric Wong
Date:
2024-09-01 10:39:02 UTC
Severity:
normal
Tags:
#825790#5
Date:
2016-05-29 22:47:15 UTC
From:
To:
In other words, there should be a way to forcibly wrap long
lines of text when using w3m interactively.

I looked around the source and docs but could not find a
way to do it, but please tell me if I missed something.

This is an accessibility issue as it makes it hard to read some
sites.

For now, I pipe the buffer within (using "|") to another w3m
invocation:

	w3m -dump -cols 64 -T text/html


Btw, is upstream still around (their mailing lists are dead) or
is Debian considered upstream?

Thank you for maintaining w3m.

#825790#10
Date:
2016-05-30 11:12:42 UTC
From:
To:
I could not find the feature in w3m.  Resize your terminal window
to adjust.

Probably, the mailing lists w3m-dev@w3m.jp and w3m-dev-en@w3m.jp
are still available, though last post is on 2015, archived at Gmane:

  - http://blog.gmane.org/gmane.comp.web.w3m.devel
  - http://blog.gmane.org/gmane.comp.web.w3m.devel.english

However, the upstream has been inactive since May 2012, so Debian's
w3m may be considered as an actively maintained upstream.

Thanks,
--
Tatsuya Kinoshita

#825790#15
Date:
2016-05-30 12:29:03 UTC
From:
To:
Tatsuya Kinoshita <tats@debian.org> wrote:

Thanks for the response.  I think I was inside a <pre> block
and it would not wrap with a small terminal.

I can see most HTML wraps, but there should be a way to force
wrapping for <pre> since it can go beyond the terminal.

Ah, http://w3m.sourceforge.net/ pointed me to
sic.med.tohoku.ac.jp domains, I did not know w3m.jp.
Thanks again.

#825790#20
Date:
2024-08-25 14:55:33 UTC
From:
To:
Below is a patch for this.

Eric, just in case you are still interested I also have a patch to force
folding in <pre> tags.

Fixes Debian BTS #825790, Debian BTS #941335, GitHub Issue #253.

Fixes: https://todo.sr.ht/~rkta/w3m/23
---
 main.c  |   13 +++++--------
 terms.c |    3 +++
 2 files changed, 8 insertions(+), 8 deletions(-)
--- a/main.c
+++ b/main.c
@@ -132,6 +132,7 @@ static int searchKeyNum(void);
 #define usage() fusage(stderr, 1)

 int enable_inline_image;
+extern int opt_cols;

 static void
 fversion(FILE * f)
@@ -713,7 +714,7 @@ main(int argc, char **argv)
 	    else if (!strcmp("-cols", argv[i])) {
 		if (++i >= argc)
 		    usage();
-		COLS = atoi(argv[i]);
+		opt_cols = atoi(argv[i]);
 	    }
 	    else if (!strcmp("-ppc", argv[i])) {
 		double ppc;
@@ -904,14 +905,10 @@ main(int argc, char **argv)
 	CookieFile = rcFile(COOKIE_FILE);
 #endif

-    if (!isatty(1) && !w3m_dump) {
-	/* redirected output */
+    if (!isatty(1) && !w3m_dump) /* redirected output */
 	w3m_dump = DUMP_BUFFER;
-    }
-    if (w3m_dump) {
-	if (COLS == 0)
-	    COLS = DEFAULT_COLS;
-    }
+    if (w3m_dump)
+	COLS = opt_cols ? opt_cols : DEFAULT_COLS;

 #ifdef USE_BINMODE_STREAM
     setmode(fileno(stdout), O_BINARY);
--- a/terms.c
+++ b/terms.c
@@ -426,6 +426,7 @@ char *T_cd, *T_ce, *T_kr, *T_kl, *T_cr,
     *T_ti, *T_te, *T_nd, *T_as, *T_ae, *T_eA, *T_ac, *T_op;

 int LINES, COLS;
+int opt_cols;
 #if defined(__CYGWIN__)
 int LASTLINE;
 #endif				/* defined(__CYGWIN__) */
@@ -1255,6 +1256,8 @@ setlinescols(void)
 	LINES = tgetnum("li");	/* number of line */
     if (COLS <= 0)
 	COLS = tgetnum("co");	/* number of column */
+    if (opt_cols && COLS > opt_cols)
+	COLS = opt_cols;
 #if defined(__CYGWIN__)
     LASTLINE = LINES - (isWinConsole == TERM_CYGWIN_RESERVE_IME ? 2 : 1);
 #endif				/* defined(__CYGWIN__) */

#825790#25
Date:
2024-08-31 19:01:21 UTC
From:
To:
Rene Kita <me@rkta.de> wrote:

Thanks, I am still interested in the <pre> folding patch as well.
I didn't find an improvement from using
Do-not-override-cols-option-value.patch on my <pre>-heavy sites

Thanks again.

#825790#30
Date:
2024-09-01 10:37:37 UTC
From:
To:
[...]

Patch is below.
because of the many <pre>s, right? Thanks for testing.

Your welcome.

I don't expect those patches to be available in Debian in the near
future. You might check out my fork at [0], those patches are currently
staged in branch 'next' for some beta testing.

[0]: https://sr.ht/~rkta/w3m


Some bug trackers are really annoying to read, because they place
comments in <pre> elements. They usually provide some CSS to make it
readable.

As we do not speak CSS, add a command to reload the page folding those
long lines. This is a one-time operation. Additionally add an option to
make this behaviour permanent.
---
 doc-de/README.func |  1 +
 doc/README.func    |  1 +
 file.c             |  7 +++++--
 fm.h               |  1 +
 main.c             | 11 +++++++++++
 proto.h            |  1 +
 rc.c               |  3 +++
 7 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/doc-de/README.func b/doc-de/README.func
index cb175db4..7adabfba 100644
--- a/doc-de/README.func
+++ b/doc-de/README.func
@@ -31,6 +31,7 @@ EXEC_SHELL	Führe Shell-Befehl aus und zeige Ausgabe an
 EXIT		Sofort beenden
 EXTERN		Verwende externen Browser zur Anzeige
 EXTERN_LINK	Verwende externen Browser zur Anzeige des Linkziels
+FOLD_PRE	Erzwinge Umbruch von langen Zeilen in <pre>-Elementen
 FRAME		Wechsle zwischen Kennung und Umsetzung von HTML-Frames
 GOTO		Öffne angegebenes Dokument in neuem Puffer
 GOTO_HOME	Zurück zur Startseite (die Variablen HTTP_HOME oder WWW_HOME spezifiziert wurden)
diff --git a/doc/README.func b/doc/README.func
index 55523a4b..65ca1f84 100644
--- a/doc/README.func
+++ b/doc/README.func
@@ -31,6 +31,7 @@ EXEC_SHELL	Execute shell command and display output
 EXIT		Quit without confirmation
 EXTERN		Display using an external browser
 EXTERN_LINK	Display target using an external browser
+FOLD_PRE	Fold long lines in <pre> elements
 FRAME		Toggle rendering HTML frames
 GOTO		Open specified document in a new buffer
 GOTO_HOME	Return to the homepage (specified HTTP_HOME or WWW_HOME variable)
diff --git a/file.c b/file.c
index fb0a75ef..74927de9 100644
--- a/file.c
+++ b/file.c
@@ -30,6 +30,7 @@

 #define MAX_INPUT_SIZE 80 /* TODO - max should be screen line length */

+extern int fold_pre;
 static int frame_source = 0;
 static int need_number = 0;

@@ -2604,7 +2605,7 @@ check_breakpoint(struct readbuffer *obuf, int pre_mode, char *ch)
     int tlen, len = obuf->line->length;

     append_tags(obuf);
-    if (pre_mode)
+    if (pre_mode && !fold_pre)
 	return;
     tlen = obuf->line->length - len;
     if (tlen > 0
@@ -6695,7 +6696,8 @@ HTMLlineproc0(char *line, struct html_feed_environ *h_env, int internal)
 			proc_mchar(obuf, 1, delta, &str, mode);
 		}
 		if (obuf->flag & (RB_SPECIAL & ~RB_PRE_INT))
-		    continue;
+		    if (!fold_pre)
+			continue;
 	    }
 	    else {
 		if (!IS_SPACE(*str))
@@ -6923,6 +6925,7 @@ loadHTMLBuffer(URLFile *f, Buffer *newBuf)
 	if (src)
 	    newBuf->sourcefile = tmp->ptr;
     }
+    fold_pre |= FoldPre;

     loadHTMLstream(f, newBuf, src, newBuf->bufferprop & BP_FRAME);

diff --git a/fm.h b/fm.h
index a2ca9ead..5353589e 100644
--- a/fm.h
+++ b/fm.h
@@ -1058,6 +1058,7 @@ global int ignore_null_img_alt init(TRUE);
 #define DISPLAY_INS_DEL_FONTIFY	2
 global int displayInsDel init(DISPLAY_INS_DEL_NORMAL);
 global int FoldTextarea init(FALSE);
+global int FoldPre init(FALSE);
 global int FoldLine init(FALSE);
 #define DEFAULT_URL_EMPTY	0
 #define DEFAULT_URL_CURRENT	1
diff --git a/main.c b/main.c
index 144c21b7..4c0b8613 100644
--- a/main.c
+++ b/main.c
@@ -129,6 +129,7 @@ static int searchKeyNum(void);

 int enable_inline_image;
 extern int opt_cols;
+int fold_pre;

 static void
 fversion(FILE * f)
@@ -4963,6 +4964,14 @@ DEFUN(vwSrc, SOURCE VIEW, "Toggle between HTML shown or processed")
     displayBuffer(Currentbuf, B_NORMAL);
 }

+DEFUN(foldPre, FOLD_PRE, "Fold long lines in <pre> elements")
+{
+    fold_pre = 1;
+    Currentbuf->need_reshape = TRUE;
+    displayBuffer(Currentbuf, B_FORCE_REDRAW);
+    fold_pre = FoldPre;
+}
+
 /* reload */
 DEFUN(reload, RELOAD, "Load current document anew")
 {
@@ -4990,6 +4999,7 @@ DEFUN(reload, RELOAD, "Load current document anew")
 	disp_err_message("Can't reload stdin", TRUE);
 	return;
     }
+    fold_pre = FoldPre;
     copyBuffer(&sbuf, Currentbuf);
     if (Currentbuf->bufferprop & BP_FRAME &&
 	(fbuf = Currentbuf->linkBuffer[LB_N_FRAME])) {
@@ -5086,6 +5096,7 @@ DEFUN(reload, RELOAD, "Load current document anew")
 	restorePosition(Currentbuf, &sbuf);
     }
     displayBuffer(Currentbuf, B_FORCE_REDRAW);
+    fold_pre = FoldPre;
 }

 /* reshape */
diff --git a/proto.h b/proto.h
index ed0d2369..ef8216e0 100644
--- a/proto.h
+++ b/proto.h
@@ -99,6 +99,7 @@ extern void peekURL(void);
 extern void peekIMG(void);
 extern void curURL(void);
 extern void vwSrc(void);
+extern void foldPre(void);
 extern void reload(void);
 extern void reshape(void);
 extern void chkURL(void);
diff --git a/rc.c b/rc.c
index 2fcacb56..151771dd 100644
--- a/rc.c
+++ b/rc.c
@@ -98,6 +98,7 @@ static int OptionEncode = FALSE;
 #define CMT_DISP_BORDERS N_("Display table borders, ignore value of BORDER")
 #define CMT_DISABLE_CENTER N_("Disable center alignment")
 #define CMT_FOLD_TEXTAREA N_("Fold lines in TEXTAREA")
+#define CMT_FOLD_PRE N_("Fold lines in PRE")
 #define CMT_DISP_INS_DEL N_("Display INS, DEL, S and STRIKE element")
 #define CMT_COLOR        N_("Display with color")
 #define CMT_HINTENSITY_COLOR N_("Use high-intensity colors")
@@ -436,6 +437,8 @@ struct param_ptr params1[] = {
      CMT_DISABLE_CENTER, NULL},
     {"fold_textarea", P_CHARINT, PI_ONOFF, (void *)&FoldTextarea,
      CMT_FOLD_TEXTAREA, NULL},
+    {"fold_pre", P_CHARINT, PI_ONOFF, (void *)&FoldPre,
+     CMT_FOLD_PRE, NULL},
     {"display_ins_del", P_INT, PI_SEL_C, (void *)&displayInsDel,
      CMT_DISP_INS_DEL, displayinsdel},
     {"ignore_null_img_alt", P_INT, PI_ONOFF, (void *)&ignore_null_img_alt,
-- 
2.46.0