Persist 'k' command in mothra and add matching -k flag (thanks piroko)

"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." --Jeremy O'Brien<neutral@fastmail.com> on 9fans
This commit is contained in:
23hiro 2018-06-27 19:20:28 +02:00
parent 902eceee63
commit 2f1b8246e2
4 changed files with 14 additions and 7 deletions

View file

@ -56,6 +56,8 @@ There are a number of options:
Alt display. Starts in alt display mode, see menu Alt display. Starts in alt display mode, see menu
commands table below. commands table below.
.TP .TP
.B -k
Kill images. Don't fetch/display images.
.B -m .B -m
Specify the Specify the
.IR webfs (4) .IR webfs (4)
@ -132,7 +134,7 @@ Jump to page
from the list of previously viewed pages. from the list of previously viewed pages.
.TP .TP
.BI k .BI k
Kill images on the current page. Toggle killing of images.
.TP .TP
.BI m .BI m
Enter or exit moth mode. Enter or exit moth mode.

View file

@ -14,6 +14,7 @@
#include "rtext.h" #include "rtext.h"
int debug=0; int debug=0;
int verbose=0; /* -v flag causes html errors to be written to file-descriptor 2 */ 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 defdisplay=1; /* is the default (initial) display visible? */
int visxbar=0; /* horizontal scrollbar visible? */ int visxbar=0; /* horizontal scrollbar visible? */
int topxbar=0; /* horizontal scrollbar at top? */ int topxbar=0; /* horizontal scrollbar at top? */
@ -306,6 +307,7 @@ void main(int argc, char *argv[]){
ARGBEGIN{ ARGBEGIN{
case 'd': debug=1; break; case 'd': debug=1; break;
case 'v': verbose=1; break; case 'v': verbose=1; break;
case 'k': killimgs=1; break;
case 'm': case 'm':
if(mtpt = ARGF()) if(mtpt = ARGF())
break; break;
@ -329,7 +331,7 @@ void main(int argc, char *argv[]){
switch(argc){ switch(argc){
default: default:
Usage: Usage:
fprint(2, "Usage: %s [-dva] [-m mtpt] [url]\n", argv0); fprint(2, "Usage: %s [-dvak] [-m mtpt] [url]\n", argv0);
exits("usage"); exits("usage");
case 0: case 0:
url=getenv("url"); url=getenv("url");
@ -687,6 +689,8 @@ void docmd(Panel *p, char *s){
mothon(current, !mothmode); mothon(current, !mothmode);
break; break;
case 'k': case 'k':
killimgs = !killimgs;
if (killimgs)
killpix(current); killpix(current);
break; break;
case 'w': case 'w':
@ -837,7 +841,7 @@ void gettext(Www *w, int fd, int type){
break; break;
case 0: case 0:
if(type==HTML) if(type==HTML)
plrdhtml(w->url->fullname, fd, w); plrdhtml(w->url->fullname, fd, w, killimgs);
else else
plrdplain(w->url->fullname, fd, w); plrdplain(w->url->fullname, fd, w);
_exits(0); _exits(0);

View file

@ -78,7 +78,7 @@ enum{
}; };
void finish(Www *w); void finish(Www *w);
void plrdhtml(char *, int, Www *); void plrdhtml(char *, int, Www *, int);
void plrdplain(char *, int, Www *); void plrdplain(char *, int, Www *);
void htmlerror(char *, int, char *, ...); /* user-supplied routine */ void htmlerror(char *, int, char *, ...); /* user-supplied routine */
void seturl(Url *, char *, char *); void seturl(Url *, char *, char *);

View file

@ -704,7 +704,7 @@ void plrdplain(char *name, int fd, Www *dst){
plaintext(&g); plaintext(&g);
finish(dst); finish(dst);
} }
void plrdhtml(char *name, int fd, Www *dst){ void plrdhtml(char *name, int fd, Www *dst, int killimgs){
int tagerr; int tagerr;
Stack *sp; Stack *sp;
char buf[20]; char buf[20];
@ -1222,6 +1222,7 @@ void plrdhtml(char *name, int fd, Www *dst){
} }
pl_popstate(g.state); pl_popstate(g.state);
*g.tp='\0'; *g.tp='\0';
if (!killimgs)
getpix(dst->text, dst); getpix(dst->text, dst);
finish(dst); finish(dst);
return; return;