"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: tog: "search wrapped" notifications
To:
Mikhail <mp39590@gmail.com>
Cc:
gameoftrees@openbsd.org
Date:
Mon, 1 May 2023 12:10:32 +1000

Download raw body.

Thread
On 23-04-30 02:54PM, Mikhail wrote:
> In continuation of this thread:
> https://marc.info/?l=gameoftrees&m=167606517310115&w=2
> 
> Inlined patch adds "search wrapped" and "diff navigation wrapped" for
> searches and file/hunk diff navigation.

I like this, thanks! I've made one tiny change: now that view is being
passed to the diff_{next,prev}_index() routines, we no longer need to
pass view->state.diff.

> It also makes the notification highlighted with wstandout(), since in my
> testing on large screen it helps to notice the wrap arounds.

This is the only part of the change that I'm not too sure about. I don't
exactly object, but would rather wait to make sure there are no
objections from anyone else either. I vaguely recall naddy having
a preference for less attributes--but that may have involved the more
fancy attributes like bold. I'm also not a fan of too many decorations.

But if there are no objections I'll commit this in a day or two.

Thank you :)

PS. I don't know how but I missed op's message in the linked thread
(pasting here for convenience):

----8<------------
maybe we could have tog display "no more matches" and stop.  Then, if
n is pressed again right after, it wraps.

This is the standard behaviour of isearch on Emacs, which I find quite
nice since it's clear when you have reached the last match and can still
wrap around if you want to.
------------>8----

I really like this idea!

If this is something you would like, too, Mikhail, and have the time to
implement, this would be nice to have. Otherwise I can do this after
exams in a few weeks.

diff /home/mark/src/got
commit - 79cd0a74be4fd59c3cbfc4f35772ba4336b950be
path + /home/mark/src/got
blob - 09cd112bc1ff0346edd8a4dd37b64c38e1d41113
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -1596,7 +1596,9 @@ action_report(struct tog_view *view)
 
 	wmove(v->window, v->nlines - 1, 0);
 	wclrtoeol(v->window);
+	wstandout(v->window);
 	wprintw(v->window, ":%s", view->action);
+	wstandend(v->window);
 	wrefresh(v->window);
 
 	/*
@@ -5281,6 +5283,8 @@ search_next_view_match(struct tog_view *view)
 				break;
 			}
 
+			view->action = "search wrapped";
+
 			if (view->searching == TOG_SEARCH_FORWARD)
 				lineno = 1;
 			else
@@ -5570,15 +5574,18 @@ diff_prev_index(struct tog_diff_view_state *s, enum go
 }
 
 static void
-diff_prev_index(struct tog_diff_view_state *s, enum got_diff_line_type type)
+diff_prev_index(struct tog_view *view, enum got_diff_line_type type)
 {
-	int start, i;
+	struct tog_diff_view_state	*s = &view->state.diff;
+	int				 start, i;
 
 	i = start = s->first_displayed_line - 1;
 
 	while (s->lines[i].type != type) {
-		if (i == 0)
+		if (i == 0) {
+			view->action = "diff navigation wrapped";
 			i = s->nlines - 1;
+		}
 		if (--i == start)
 			return; /* do nothing, requested type not in file */
 	}
@@ -5588,15 +5595,18 @@ diff_next_index(struct tog_diff_view_state *s, enum go
 }
 
 static void
-diff_next_index(struct tog_diff_view_state *s, enum got_diff_line_type type)
+diff_next_index(struct tog_view *view, enum got_diff_line_type type)
 {
-	int start, i;
+	struct tog_diff_view_state	*s = &view->state.diff;
+	int				 start, i;
 
 	i = start = s->first_displayed_line + 1;
 
 	while (s->lines[i].type != type) {
-		if (i == s->nlines - 1)
+		if (i == s->nlines - 1) {
+			view->action = "diff navigation wrapped";
 			i = 0;
+		}
 		if (++i == start)
 			return; /* do nothing, requested type not in file */
 	}
@@ -5721,16 +5731,16 @@ input_diff_view(struct tog_view **new_view, struct tog
 		free(line);
 		break;
 	case '(':
-		diff_prev_index(s, GOT_DIFF_LINE_BLOB_MIN);
+		diff_prev_index(view, GOT_DIFF_LINE_BLOB_MIN);
 		break;
 	case ')':
-		diff_next_index(s, GOT_DIFF_LINE_BLOB_MIN);
+		diff_next_index(view, GOT_DIFF_LINE_BLOB_MIN);
 		break;
 	case '{':
-		diff_prev_index(s, GOT_DIFF_LINE_HUNK);
+		diff_prev_index(view, GOT_DIFF_LINE_HUNK);
 		break;
 	case '}':
-		diff_next_index(s, GOT_DIFF_LINE_HUNK);
+		diff_next_index(view, GOT_DIFF_LINE_HUNK);
 		break;
 	case '[':
 		if (s->diff_context > 0) {
@@ -7637,6 +7647,7 @@ search_next_tree_view(struct tog_view *view)
 				te = got_object_tree_get_first_entry(s->tree);
 			else
 				te = got_object_tree_get_last_entry(s->tree);
+			view->action = "search wrapped";
 		}
 
 		if (match_tree_entry(te, &view->regex)) {
@@ -8398,6 +8409,7 @@ search_next_ref_view(struct tog_view *view)
 				re = TAILQ_FIRST(&s->refs);
 			else
 				re = TAILQ_LAST(&s->refs, tog_reflist_head);
+			view->action = "search wrapped";
 		}
 
 		if (match_reflist_entry(re, &view->regex)) {

-- 
Mark Jamsek <fnc.bsdbox.org|got.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68