shithub: gopher

Download patch

ref: 2fe0168b9a1f4db52036fe12d23b46ccdc9cd0e5
parent: 3c6cac0bb49c746db39833c27fb24044ccf52c11
author: telephil9 <telephil9@gmail.com>
date: Wed Apr 29 01:36:00 EDT 2020

Add text shortcuts for back, next and quit

	Similar to mothra, typing b, n or q in the entry perform back, next or quit actions.

--- a/gopher.c
+++ b/gopher.c
@@ -17,6 +17,7 @@
 Panel *root;
 Panel *backp;
 Panel *fwdp;
+Panel *entryp;
 Panel *urlp;
 Panel *textp;
 Panel *statusp;
@@ -509,9 +510,28 @@
 entryhit(Panel *p, char *t)
 {
 	USED(p);
-	if(strlen(t)<=0)
+	switch(strlen(t)){
+	case 0:
 		return;
-	visitaddr(t);
+	case 1:
+		switch(*t){
+		case 'b':
+			backhit(backp, 1);
+			break;
+		case 'n':
+			nexthit(fwdp, 1);
+			break;
+		case 'q':
+			exits(nil);
+			break;
+		default:
+			message("unknown command %s", t);
+			break;
+		}
+		break;
+	default:
+		visitaddr(t);
+	}
 	plinitentry(p, PACKN|FILLX, 0, "", entryhit);
 	pldraw(p, screen);
 }
@@ -528,7 +548,7 @@
 	plbutton(p, PACKW|BITMAP, backi, backhit);
 	plbutton(p, PACKW|BITMAP, fwdi, nexthit);
 	pllabel(p, PACKW, "Go:");
-	plentry(p, PACKN|FILLX, 0, "", entryhit);
+	entryp = plentry(p, PACKN|FILLX, 0, "", entryhit);
 	p = plgroup(root, PACKN|FILLX);
 	urlp = pllabel(p, PACKN|FILLX, "");
 	plplacelabel(urlp, PLACEW);
@@ -537,6 +557,7 @@
 	xbar = plscrollbar(p, IGNORE);
 	textp = pltextview(p, PACKE|EXPAND, ZP, nil, nil);
 	plscroll(textp, xbar, ybar);
+	plgrabkb(entryp);
 }
 
 void
@@ -622,6 +643,7 @@
 		case Ekeyboard:
 			switch(e.kbdc){
 			default:
+				plgrabkb(entryp);
 				plkeyboard(e.kbdc);
 				break;
 			case Khome: