9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] mothra back patch
@ 2018-09-03 18:13 Jeremy O'Brien
  2018-09-13 12:57 ` Jeremy O'Brien
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremy O'Brien @ 2018-09-03 18:13 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 446 bytes --]

Several people (myself included) have expressed interest in a "go back" feature for mothra that follows the order of links visited. Attached is my patch implementing this. I've tried to keep it as simple as possible. Clicking links in the alt bar will change the current page in the nav stack, but the stack only gets pushed to when a new link is visited (either via clicking a link on a page, typing a URL manually in the URL bar, or plumbing).

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mothra_back.diff --]
[-- Type: text/x-patch; name="mothra_back.diff", Size: 2416 bytes --]

diff -r d310bf4b5f74 sys/man/1/mothra
--- a/sys/man/1/mothra	Sat Sep 01 15:11:46 2018 +0200
+++ b/sys/man/1/mothra	Mon Sep 03 14:07:33 2018 -0400
@@ -100,6 +100,10 @@
 .B moth mode
 menu option again exits moth mode.
 .TP
+.B back
+Navigate backwards through visited link history.  The order of this
+navigation is independent from the order shown in the alt display.
+.TP
 .B snarf
 Copy the current entry text or selected page text to snarf buffer.
 If nothing is selected, the current URL is copied.
@@ -126,6 +130,9 @@
 .B a
 Toggle alt display.
 .TP
+.BI b
+Navigate backwards through visited link history.
+.TP
 .BI g " url
 Go to the page with the given URL.
 .TP
diff -r d310bf4b5f74 sys/src/cmd/mothra/mothra.c
--- a/sys/src/cmd/mothra/mothra.c	Sat Sep 01 15:11:46 2018 +0200
+++ b/sys/src/cmd/mothra/mothra.c	Mon Sep 03 14:07:33 2018 -0400
@@ -79,6 +79,8 @@
 Url *selection=0;
 int mothmode;
 int kickpipe[2];
+int history[NWWW];
+int histindex = 0;
 
 void docmd(Panel *, char *);
 void doprev(Panel *, int, int);
@@ -93,6 +95,7 @@
 char *buttons[]={
 	"alt display",
 	"moth mode",
+	"back",
 	"snarf",
 	"paste",
 	"search",
@@ -556,6 +559,7 @@
 	int i;
 	new=www(index);
 	if(new==current && (tag==0 || tag[0]==0)) return;
+	history[histindex] = index;
 	if(current)
 		current->yoffs=plgetpostextview(text);
 	current=new;
@@ -685,6 +689,9 @@
 		else
 			message("Usage: j index");
 		break;
+	case 'b':
+		hit3(3, 2);
+		break;
 	case 'm':
 		mothon(current, !mothmode);
 		break;
@@ -1054,6 +1061,7 @@
 			}
 			plinitlist(list, PACKN|FILLX, genwww, 8, doprev);
 			if(defdisplay) pldraw(list, screen);
+			histindex = (histindex+1) % NWWW;
 			setcurrent(i, selection->tag);
 			break;
 		case GIF:
@@ -1193,15 +1201,19 @@
 		mothon(current, !mothmode);
 		break;
 	case 2:
+		histindex = (histindex-1) % NWWW;
+		doprev(nil, 1, wwwtop-history[histindex]-1);
+		break;
+	case 3:
 		snarf(plkbfocus);
 		break;
-	case 3:
+	case 4:
 		paste(plkbfocus);
 		break;
-	case 4:
+	case 5:
 		search();
 		break;
-	case 5:
+	case 6:
 		if(!selection){
 			message("no url selected");
 			break;
@@ -1221,11 +1233,11 @@
 		fprint(fd, "<p><a href=\"%s\">%s</a>\n", urlstr(selection), urlstr(selection));
 		close(fd);
 		break;
-	case 6:
+	case 7:
 		snprint(name, sizeof(name), "file:%s/hit.html", mkhome());
 		geturl(name, -1, 1, 0);
 		break;
-	case 7:
+	case 8:
 		if(confirm(3))
 			exits(0);
 		break;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9front] mothra back patch
  2018-09-03 18:13 [9front] mothra back patch Jeremy O'Brien
@ 2018-09-13 12:57 ` Jeremy O'Brien
  2018-09-13 13:18   ` Steve Simon
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremy O'Brien @ 2018-09-13 12:57 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 263 bytes --]

For all zero of you out there using this patch, attached is a bugfixed version since I didn't realize C modulus could return negative numbers. Also included a patch that adds both go back and go forward functionality with 'f'. The patches are mutually exclusive.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mothra_back.diff --]
[-- Type: text/x-patch; name="mothra_back.diff", Size: 2430 bytes --]

diff -r eca280998901 sys/man/1/mothra
--- a/sys/man/1/mothra	Tue Sep 11 00:23:35 2018 -0700
+++ b/sys/man/1/mothra	Thu Sep 13 08:38:08 2018 -0400
@@ -100,6 +100,10 @@
 .B moth mode
 menu option again exits moth mode.
 .TP
+.B back
+Navigate backwards through visited link history.  The order of this
+navigation is independent from the order shown in the alt display.
+.TP
 .B snarf
 Copy the current entry text or selected page text to snarf buffer.
 If nothing is selected, the current URL is copied.
@@ -126,6 +130,9 @@
 .B a
 Toggle alt display.
 .TP
+.BI b
+Navigate backwards through visited link history.
+.TP
 .BI g " url
 Go to the page with the given URL.
 .TP
diff -r eca280998901 sys/src/cmd/mothra/mothra.c
--- a/sys/src/cmd/mothra/mothra.c	Tue Sep 11 00:23:35 2018 -0700
+++ b/sys/src/cmd/mothra/mothra.c	Thu Sep 13 08:38:08 2018 -0400
@@ -79,6 +79,8 @@
 Url *selection=0;
 int mothmode;
 int kickpipe[2];
+int history[NWWW];
+int histindex = -1;
 
 void docmd(Panel *, char *);
 void doprev(Panel *, int, int);
@@ -93,6 +95,7 @@
 char *buttons[]={
 	"alt display",
 	"moth mode",
+	"back",
 	"snarf",
 	"paste",
 	"search",
@@ -556,6 +559,7 @@
 	int i;
 	new=www(index);
 	if(new==current && (tag==0 || tag[0]==0)) return;
+	history[histindex] = index;
 	if(current)
 		current->yoffs=plgetpostextview(text);
 	current=new;
@@ -685,6 +689,9 @@
 		else
 			message("Usage: j index");
 		break;
+	case 'b':
+		hit3(3, 2);
+		break;
 	case 'm':
 		mothon(current, !mothmode);
 		break;
@@ -1054,6 +1061,7 @@
 			}
 			plinitlist(list, PACKN|FILLX, genwww, 8, doprev);
 			if(defdisplay) pldraw(list, screen);
+			histindex = (histindex+1) % NWWW;
 			setcurrent(i, selection->tag);
 			break;
 		case GIF:
@@ -1193,15 +1201,21 @@
 		mothon(current, !mothmode);
 		break;
 	case 2:
+		if (histindex <= 0)
+			break;
+		histindex--;
+		doprev(nil, 1, wwwtop-history[histindex]-1);
+		break;
+	case 3:
 		snarf(plkbfocus);
 		break;
-	case 3:
+	case 4:
 		paste(plkbfocus);
 		break;
-	case 4:
+	case 5:
 		search();
 		break;
-	case 5:
+	case 6:
 		if(!selection){
 			message("no url selected");
 			break;
@@ -1221,11 +1235,11 @@
 		fprint(fd, "<p><a href=\"%s\">%s</a>\n", urlstr(selection), urlstr(selection));
 		close(fd);
 		break;
-	case 6:
+	case 7:
 		snprint(name, sizeof(name), "file:%s/hit.html", mkhome());
 		geturl(name, -1, 1, 0);
 		break;
-	case 7:
+	case 8:
 		if(confirm(3))
 			exits(0);
 		break;

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: mothra_back_and_forward.diff --]
[-- Type: text/x-patch; name="mothra_back_and_forward.diff", Size: 2648 bytes --]

diff -r eca280998901 sys/man/1/mothra
--- a/sys/man/1/mothra	Tue Sep 11 00:23:35 2018 -0700
+++ b/sys/man/1/mothra	Thu Sep 13 08:37:17 2018 -0400
@@ -100,6 +100,10 @@
 .B moth mode
 menu option again exits moth mode.
 .TP
+.B back
+Navigate backwards through visited link history.  The order of this
+navigation is independent from the order shown in the alt display.
+.TP
 .B snarf
 Copy the current entry text or selected page text to snarf buffer.
 If nothing is selected, the current URL is copied.
@@ -126,6 +130,12 @@
 .B a
 Toggle alt display.
 .TP
+.BI b
+Navigate backwards through visited link history.
+.TP
+.BI f
+Navigate forwards through visisted link history.
+.TP
 .BI g " url
 Go to the page with the given URL.
 .TP
diff -r eca280998901 sys/src/cmd/mothra/mothra.c
--- a/sys/src/cmd/mothra/mothra.c	Tue Sep 11 00:23:35 2018 -0700
+++ b/sys/src/cmd/mothra/mothra.c	Thu Sep 13 08:37:17 2018 -0400
@@ -79,6 +79,8 @@
 Url *selection=0;
 int mothmode;
 int kickpipe[2];
+int history[NWWW];
+int histindex = -1;
 
 void docmd(Panel *, char *);
 void doprev(Panel *, int, int);
@@ -93,6 +95,7 @@
 char *buttons[]={
 	"alt display",
 	"moth mode",
+	"back",
 	"snarf",
 	"paste",
 	"search",
@@ -556,6 +559,7 @@
 	int i;
 	new=www(index);
 	if(new==current && (tag==0 || tag[0]==0)) return;
+	history[histindex] = index;
 	if(current)
 		current->yoffs=plgetpostextview(text);
 	current=new;
@@ -685,6 +689,15 @@
 		else
 			message("Usage: j index");
 		break;
+	case 'b':
+		hit3(3, 2);
+		break;
+	case 'f':
+		if (histindex+1 == NWWW || history[histindex+1] == 0)
+			break;
+		histindex++;
+		doprev(nil, 1, wwwtop-history[histindex]-1);
+		break;
 	case 'm':
 		mothon(current, !mothmode);
 		break;
@@ -1054,6 +1067,7 @@
 			}
 			plinitlist(list, PACKN|FILLX, genwww, 8, doprev);
 			if(defdisplay) pldraw(list, screen);
+			histindex = (histindex+1) % NWWW;
 			setcurrent(i, selection->tag);
 			break;
 		case GIF:
@@ -1193,15 +1207,21 @@
 		mothon(current, !mothmode);
 		break;
 	case 2:
+		if (histindex <= 0)
+			break;
+		histindex--;
+		doprev(nil, 1, wwwtop-history[histindex]-1);
+		break;
+	case 3:
 		snarf(plkbfocus);
 		break;
-	case 3:
+	case 4:
 		paste(plkbfocus);
 		break;
-	case 4:
+	case 5:
 		search();
 		break;
-	case 5:
+	case 6:
 		if(!selection){
 			message("no url selected");
 			break;
@@ -1221,11 +1241,11 @@
 		fprint(fd, "<p><a href=\"%s\">%s</a>\n", urlstr(selection), urlstr(selection));
 		close(fd);
 		break;
-	case 6:
+	case 7:
 		snprint(name, sizeof(name), "file:%s/hit.html", mkhome());
 		geturl(name, -1, 1, 0);
 		break;
-	case 7:
+	case 8:
 		if(confirm(3))
 			exits(0);
 		break;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [9front] mothra back patch
  2018-09-13 12:57 ` Jeremy O'Brien
@ 2018-09-13 13:18   ` Steve Simon
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Simon @ 2018-09-13 13:18 UTC (permalink / raw)
  To: 9front

Beware:

i suspect you are perfectly safe with mothra - it is unlikely to be ported to other compilers. however c does not promise to retain the numerators sign, it is compiler dependant.

been bitten by that one before.

 -Steve



> On 13 Sep 2018, at 1:57 pm, Jeremy O'Brien <neutral@fastmail.com> wrote:
> 
> 
> For all zero of you out there using this patch, attached is a bugfixed version since I didn't realize C modulus could return negative numbers. Also included a patch that adds both go back and go forward functionality with 'f'. The patches are mutually exclusive.
> 
> from postmaster@ewsd:
> The following attachment had content that we can't
> prove to be harmless.  To avoid possible automatic
> execution, we changed the content headers.
> The original header was:
> 
>    Content-Disposition: attachment; filename="mothra_back.diff"
>    Content-Id: <1536843390.41311.17c64c56e970f6795798c532a61c0c0f714224fe.7E4E2EE2@content.messagingengine.com>
>    Content-Transfer-Encoding: base64
>    Content-Type: text/x-patch; name="mothra_back.diff"
> <mothra_back.diff.suspect>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-09-13 13:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-03 18:13 [9front] mothra back patch Jeremy O'Brien
2018-09-13 12:57 ` Jeremy O'Brien
2018-09-13 13:18   ` Steve Simon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).