I sometimes find myself on either slow or data-capped network links where 
downloading images isn't ideal. Attached is a simple patch to mothra that 
changes the 'k' command to not only remove already-downloaded images from a 
page, but also toggle a state such that mothra won't attempt to download images 
on future visited sites until 'k' is toggled again. This also adds a '-k' flag 
to mothra which enables the flag at startup. 
diff -r 65adb71807cf sys/man/1/mothra
--- a/sys/man/1/mothra	Fri Jun 22 14:49:18 2018 +0200
+++ b/sys/man/1/mothra	Sat Jun 23 09:56:12 2018 -0400
@@ -56,6 +56,8 @@
 Alt display. Starts in alt display mode, see menu
 commands table below.
 .TP
+.B -k
+Kill images. Don't fetch/display images.
 .B -m
 Specify the
 .IR webfs (4)
@@ -132,7 +134,7 @@
 from the list of previously viewed pages.
 .TP
 .BI k
-Kill images on the current page.
+Toggle killing of images.
 .TP
 .BI m
 Enter or exit moth mode.
diff -r 65adb71807cf sys/src/cmd/mothra/mothra.c
--- a/sys/src/cmd/mothra/mothra.c	Fri Jun 22 14:49:18 2018 +0200
+++ b/sys/src/cmd/mothra/mothra.c	Sat Jun 23 09:56:12 2018 -0400
@@ -14,6 +14,7 @@
 #include "rtext.h"
 int debug=0;
 int verbose=0;		/* -v flag causes html errors to be written to file-descriptor 2 */
+int killimgs=0;	/* should mothra kill images? */
 int defdisplay=1;	/* is the default (initial) display visible? */
 int visxbar=0;	/* horizontal scrollbar visible? */
 int topxbar=0;	/* horizontal scrollbar at top? */
@@ -306,6 +307,7 @@
 	ARGBEGIN{
 	case 'd': debug=1; break;
 	case 'v': verbose=1; break;
+	case 'k': killimgs=1; break;
 	case 'm':
 		if(mtpt = ARGF())
 			break;
@@ -329,7 +331,7 @@
 	switch(argc){
 	default:
 	Usage:
-		fprint(2, "Usage: %s [-dva] [-m mtpt] [url]\n", argv0);
+		fprint(2, "Usage: %s [-dvak] [-m mtpt] [url]\n", argv0);
 		exits("usage");
 	case 0:
 		url=getenv("url");
@@ -687,7 +689,9 @@
 		mothon(current, !mothmode);
 		break;
 	case 'k':
-		killpix(current);
+		killimgs = !killimgs;
+		if (killimgs)
+			killpix(current);
 		break;
 	case 'w':
 	case 'W':
@@ -837,7 +841,7 @@
 		break;
 	case 0:
 		if(type==HTML)
-			plrdhtml(w->url->fullname, fd, w);
+			plrdhtml(w->url->fullname, fd, w, killimgs);
 		else
 			plrdplain(w->url->fullname, fd, w);
 		_exits(0);
diff -r 65adb71807cf sys/src/cmd/mothra/mothra.h
--- a/sys/src/cmd/mothra/mothra.h	Fri Jun 22 14:49:18 2018 +0200
+++ b/sys/src/cmd/mothra/mothra.h	Sat Jun 23 09:56:12 2018 -0400
@@ -78,7 +78,7 @@
 };
 
 void finish(Www *w);
-void plrdhtml(char *, int, Www *);
+void plrdhtml(char *, int, Www *, int);
 void plrdplain(char *, int, Www *);
 void htmlerror(char *, int, char *, ...);	/* user-supplied routine */
 void seturl(Url *, char *, char *);
diff -r 65adb71807cf sys/src/cmd/mothra/rdhtml.c
--- a/sys/src/cmd/mothra/rdhtml.c	Fri Jun 22 14:49:18 2018 +0200
+++ b/sys/src/cmd/mothra/rdhtml.c	Sat Jun 23 09:56:12 2018 -0400
@@ -704,7 +704,7 @@
 	plaintext(&g);
 	finish(dst);
 }
-void plrdhtml(char *name, int fd, Www *dst){
+void plrdhtml(char *name, int fd, Www *dst, int killimgs){
 	int tagerr;
 	Stack *sp;
 	char buf[20];
@@ -1222,7 +1222,8 @@
 		}
 		pl_popstate(g.state);
 		*g.tp='\0';
-		getpix(dst->text, dst);
+		if (!killimgs)
+			getpix(dst->text, dst);
 		finish(dst);
 		return;
 	}

Reply via email to