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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: tog: extend log view headline highlight
To:
Game of Trees <gameoftrees@openbsd.org>
Date:
Fri, 9 Sep 2022 00:16:02 +1000

Download raw body.

Thread
On 22-09-03 04:05PM, Stefan Sperling wrote:
> On Sat, Sep 03, 2022 at 11:46:14PM +1000, Mark Jamsek wrote:
> > This is the same idea as the previous diff applied to the log view
> > headline: extend the highlight colour to the full width of the line.
> > 
> > Admittedly subjective again, but I think it looks better in splitscreen
> > when the log view is focussed.
> 
> Yes, this looks nicer.
> 
> The diff view should get the same change, I think. Perhaps other views, too?

Yes, I agree; this should be made consistent across all views. The below
diff does this, plus one other related, albeit minor, change: make the
tree view header like the blame view instead of the ref view. That is,
move the line index to the path line.

For example, before this diff:

----8<-----------------------------------------------------------------
commit 2bd4b7e472a90a7907e78f8b45a7b30fe2d10b97 [1/19]
/

  .gitignore
  CHANGES
  ...
----------------------------------------------------------------->8----

After this diff:

----8<-----------------------------------------------------------------
commit 2bd4b7e472a90a7907e78f8b45a7b30fe2d10b97
[1/19] /

  .gitignore
  CHANGES
  ...
----------------------------------------------------------------->8----

I did this because, imo, the tree view header is more like the blame
view's than the ref view's in that it contains a commit ID, line index,
and path. Plus, in narrow terminals, there's a greater chance the
"commit ID" string will consume COLUMNS such that (part of) the index is
off-screen; whereas, "references" in the ref view is much shorter so the
index is more likely to remain visible. But I'm happy to remove this bit
of the diff if anyone disagrees.

-----------------------------------------------
commit fd13d0fa0bdd232fadb55fb56d591ecbcd63c8a1 (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Thu Sep  8 14:11:50 2022 UTC
 
 tog: make headline highlight extend the full view width
 
 In splitscreen mode, make the active view headline highlight extend the full
 width of view->ncols. While here, format the tree view header like the blame
 view by moving the index to the path line.
 
diff f0f62654dd608d01879094d1f491287f0f7029f1 fd13d0fa0bdd232fadb55fb56d591ecbcd63c8a1
commit - f0f62654dd608d01879094d1f491287f0f7029f1
commit + fd13d0fa0bdd232fadb55fb56d591ecbcd63c8a1
blob - fafcec33d71453b09074d2b18e0708b52a197fbe
blob + 81a72cd907757863416d7c2e4b5924f8413371a0
--- tog/tog.c
+++ tog/tog.c
@@ -2330,16 +2330,14 @@ draw_commits(struct tog_view *view)
 		wstandout(view->window);
 	tc = get_color(&s->colors, TOG_COLOR_COMMIT);
 	if (tc)
-		wattr_on(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
+		wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
-	if (tc)
-		wattr_off(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
 	while (width < view->ncols) {
 		waddch(view->window, ' ');
 		width++;
 	}
+	if (tc)
+		wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL);
 	if (view_needs_focus_indication(view))
 		wstandend(view->window);
 	free(wline);
@@ -3977,10 +3975,10 @@ draw_file(struct tog_view *view, const char *header)
 		waddwstr(view->window, wline);
 		free(wline);
 		wline = NULL;
+		while (width++ < view->ncols)
+			waddch(view->window, ' ');
 		if (view_needs_focus_indication(view))
 			wstandend(view->window);
-		if (width <= view->ncols - 1)
-			waddch(view->window, '\n');
 
 		if (max_lines <= 1)
 			return NULL;
@@ -5214,18 +5212,16 @@ draw_blame(struct tog_view *view)
 		wstandout(view->window);
 	tc = get_color(&s->colors, TOG_COLOR_COMMIT);
 	if (tc)
-		wattr_on(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
+		wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
+	while (width++ < view->ncols)
+		waddch(view->window, ' ');
 	if (tc)
-		wattr_off(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
+		wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL);
 	if (view_needs_focus_indication(view))
 		wstandend(view->window);
 	free(wline);
 	wline = NULL;
-	if (width < view->ncols - 1)
-		waddch(view->window, '\n');
 
 	if (view->gline > blame->nlines)
 		view->gline = blame->nlines;
@@ -6347,6 +6343,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 	const struct got_error *err = NULL;
 	struct got_tree_entry *te;
 	wchar_t *wline;
+	char *index = NULL;
 	struct tog_color *tc;
 	int width, n, nentries, i = 1;
 	int limit = view->nlines;
@@ -6368,16 +6365,18 @@ draw_tree_entries(struct tog_view *view, const char *p
 		wstandout(view->window);
 	tc = get_color(&s->colors, TOG_COLOR_COMMIT);
 	if (tc)
-		wattr_on(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
+		wattr_on(view->window, COLOR_PAIR(tc->colorpair), NULL);
 	waddwstr(view->window, wline);
-	if (tc)
-		wattr_off(view->window,
-		    COLOR_PAIR(tc->colorpair), NULL);
-	if (view_needs_focus_indication(view))
-		wstandend(view->window);
 	free(wline);
 	wline = NULL;
+	while (width++ < view->ncols)
+		waddch(view->window, ' ');
+	if (tc)
+		wattr_off(view->window, COLOR_PAIR(tc->colorpair), NULL);
+	if (view_needs_focus_indication(view))
+		wstandend(view->window);
+	if (--limit <= 0)
+		return NULL;
 
 	i += s->selected;
 	if (s->first_displayed_entry) {
@@ -6386,15 +6385,11 @@ draw_tree_entries(struct tog_view *view, const char *p
 			++i;  /* account for ".." entry */
 	}
 	nentries = got_object_tree_get_nentries(s->tree);
-	wprintw(view->window, " [%d/%d]", i,
-	    nentries + (s->tree == s->root ? 0 : 1));  /* ".." in !root tree */
-
-	if (width < view->ncols - 1)
-		waddch(view->window, '\n');
-	if (--limit <= 0)
-		return NULL;
-	err = format_line(&wline, &width, NULL, parent_path, 0, view->ncols,
-	    0, 0);
+	if (asprintf(&index, "[%d/%d] %s",
+	    i, nentries + (s->tree == s->root ? 0 : 1), parent_path) == -1)
+		return got_error_from_errno("asprintf");
+	err = format_line(&wline, &width, NULL, index, 0, view->ncols, 0, 0);
+	free(index);
 	if (err)
 		return err;
 	waddwstr(view->window, wline);
@@ -7654,14 +7649,14 @@ show_ref_view(struct tog_view *view)
 	if (view_needs_focus_indication(view))
 		wstandout(view->window);
 	waddwstr(view->window, wline);
+	while (width++ < view->ncols)
+		waddch(view->window, ' ');
 	if (view_needs_focus_indication(view))
 		wstandend(view->window);
 	free(wline);
 	wline = NULL;
 	free(line);
 	line = NULL;
-	if (width < view->ncols - 1)
-		waddch(view->window, '\n');
 	if (--limit <= 0)
 		return NULL;
 

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