shithub: castor9

Download patch

ref: 5a55f1448d2004d6cb54cbd34172ec3b9925715d
parent: d50835ed8e9c630099318326135a7202465eb708
author: Julien Blanchard <[email protected]>
date: Thu Dec 10 06:12:42 EST 2020

Bring search back

--- a/castor.c
+++ b/castor.c
@@ -403,6 +403,54 @@
 }
 
 void
+search(void)
+{
+	static char last[256];
+	char buf[256];
+	Reprog *re;
+	Rtext *tp;
+	int yoff;
+
+	for(;;){
+		if(hist == nil || hist->c == nil || hist->c->text == nil)
+			return;
+		strncpy(buf, last, sizeof(buf)-1);
+		if(eenter("Search for", buf, sizeof(buf), mouse) <= 0)
+			return;
+		strncpy(last, buf, sizeof(buf)-1);
+		re = regcompnl(buf);
+		if(re == nil){
+			message("%r");
+			continue;
+		}
+		for(tp=hist->c->text;tp;tp=tp->next)
+			if(tp->flags & PL_SEL)
+				break;
+		if(tp == nil)
+			tp = hist->c->text;
+		else {
+			tp->flags &= ~PL_SEL;
+			tp = tp->next;
+		}
+		while(tp != nil){
+			tp->flags &= ~PL_SEL;
+			if(tp->text && *tp->text)
+			if(regexec(re, tp->text, nil, 0)){
+				tp->flags |= PL_SEL;
+				plsetpostextview(textp, tp->topy);
+				break;
+			}
+			tp = tp->next;
+		}
+		free(re);
+		yoff = plgetpostextview(textp);
+		plinittextview(textp, PACKE|EXPAND, ZP, hist->c->text, texthit);
+		plsetpostextview(textp, yoff);
+		pldraw(textp, screen);
+	}
+}
+
+void
 backhit(Panel *p, int b)
 {
 	USED(p);
@@ -442,7 +490,7 @@
 		nexthit(fwdp, 1);
 		break;
 	case Msearch:
-		//search();
+		search();
 		break;
 	case Mexit:
 		exits(nil);