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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: expand horizontal split support to all views
To:
gameoftrees@openbsd.org
Date:
Fri, 1 Jul 2022 01:10:08 +1000

Download raw body.

Thread
This makes hsplits available to the remaining parent->child view
combinations:

log -> tree
log -> ref
tree -> log
tree -> ref
ref -> tree

Now, hsplits are available for all the same parent->child combinations
as vsplits.

In tog, we only allow one level of child views. Views opened from child
views become a new parent view as per this excerpt (cf. tog.c:489):

 * When a new view is opened from within a parent view, this new view
 * becomes a child view of the parent view, replacing any existing child.
 *
 * When a new view is opened from within a child view, this new view
 * becomes a parent view which will obscure the views below until the
 * user quits the new parent view by typing 'q'.

As such, whether using v- or h-splits, if you run:

$ tog
t # tree opens in split
return # blame opens in fullscreen

However, if you then open a commit from that new blame (parent) view, it will
open in the current split mode (i.e., h- or v-split) as a child view.

Stefan suggested in a recent thread that the blame view in the above
example should open in a hsplit; however, this doesn't currently happen
with vsplits. Do we want to change this behaviour for both splits?

diff /home/mark/src/git/got-current
commit - 0dca135e7628142c56b3f71c3b5eb875f4fe6c7f
path + /home/mark/src/git/got-current
blob - e7cd627fd82955639423a579cf6346f539437542
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -787,6 +787,13 @@ view_is_fullscreen(struct tog_view *view)
 	return view->nlines == LINES && view->ncols == COLS;
 }

+static int
+view_is_hsplit_top(struct tog_view *view)
+{
+	return view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
+	    view_is_splitscreen(view->child);
+}
+
 static void
 view_border(struct tog_view *view)
 {
@@ -962,8 +969,7 @@ view_search_start(struct tog_view *view)
 	if (view->nlines < 1)
 		return NULL;

-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		v = view->child;

 	mvwaddstr(v->window, v->nlines - 1, 0, "/");
@@ -1005,8 +1011,7 @@ get_compound_key(struct tog_view *view, int c)
 	struct tog_view	*v = view;
 	int		 x, n = 0;

-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		v = view->child;
 	else if (view->mode == TOG_VIEW_SPLIT_VERT && view->parent)
 		v = view->parent;
@@ -2312,7 +2317,7 @@ tree_view_walk_path(struct tog_tree_view_state *s,
 }

 static const struct got_error *
-browse_commit_tree(struct tog_view **new_view, int begin_x,
+browse_commit_tree(struct tog_view **new_view, int begin_y, int begin_x,
     struct commit_queue_entry *entry, const char *path,
     const char *head_ref_name, struct got_repository *repo)
 {
@@ -2320,7 +2325,7 @@ browse_commit_tree(struct tog_view **new_view, int beg
 	struct tog_tree_view_state *s;
 	struct tog_view *tree_view;

-	tree_view = view_open(0, 0, 0, begin_x, TOG_VIEW_TREE);
+	tree_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_TREE);
 	if (tree_view == NULL)
 		return got_error_from_errno("view_open");

@@ -2809,8 +2814,7 @@ log_move_cursor_down(struct tog_view *view, int page)
 	if (!page) {
 		int eos = view->nlines - 2;

-		if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-		    view_is_splitscreen(view->child))
+		if (view_is_hsplit_top(view))
 			--eos;  /* border consumes the last line */
 		if (s->selected < MIN(eos, s->commits.ncommits - 1))
 			++s->selected;
@@ -2912,11 +2916,9 @@ input_log_view(struct tog_view **new_view, struct tog_
 	}

 	eos = nscroll = view->nlines - 1;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--eos;  /* border */

-
 	switch (ch) {
 	case 'q':
 		s->quit = 1;
@@ -3016,7 +3018,7 @@ input_log_view(struct tog_view **new_view, struct tog_
 		}
 		break;
 	case KEY_ENTER:
-	case '\r': {
+	case '\r':
 		view->count = 0;
 		if (s->selected_entry == NULL)
 			break;
@@ -3031,7 +3033,8 @@ input_log_view(struct tog_view **new_view, struct tog_
 		if (err)
 			break;

-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {  /* safe to split */
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {  /* safe to split */
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -3053,20 +3056,27 @@ input_log_view(struct tog_view **new_view, struct tog_
 		} else
 			*new_view = diff_view;
 		break;
-	}
 	case 't':
 		view->count = 0;
 		if (s->selected_entry == NULL)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = browse_commit_tree(&tree_view, begin_x,
+			view_get_split(view, &begin_y, &begin_x);
+		err = browse_commit_tree(&tree_view, begin_y, begin_x,
 		    s->selected_entry, s->in_repo_path, s->head_ref_name,
 		    s->repo);
 		if (err)
 			break;
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		tree_view->focussed = 1;
+		tree_view->mode = view->mode;
+		tree_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -3145,9 +3155,8 @@ input_log_view(struct tog_view **new_view, struct tog_
 	case 'r':
 		view->count = 0;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		ref_view = view_open(view->nlines, view->ncols,
-		    view->begin_y, begin_x, TOG_VIEW_REF);
+			view_get_split(view, &begin_y, &begin_x);
+		ref_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_REF);
 		if (ref_view == NULL)
 			return got_error_from_errno("view_open");
 		err = open_ref_view(ref_view, s->repo);
@@ -3155,8 +3164,16 @@ input_log_view(struct tog_view **new_view, struct tog_
 			view_close(ref_view);
 			return err;
 		}
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		ref_view->focussed = 1;
+		ref_view->mode = view->mode;
+		ref_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -5367,8 +5384,7 @@ input_blame_view(struct tog_view **new_view, struct to
 	int eos, nscroll, begin_y = 0, begin_x = 0;

 	eos = nscroll = view->nlines - 2;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--eos;  /* border */

 	switch (ch) {
@@ -5575,7 +5591,8 @@ input_blame_view(struct tog_view **new_view, struct to
 			view_close(diff_view);
 			break;
 		}
-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -5794,8 +5811,7 @@ draw_tree_entries(struct tog_view *view, const char *p
 	int limit = view->nlines;

 	s->ndisplayed = 0;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--limit;  /* border */

 	werase(view->window);
@@ -6070,7 +6086,7 @@ done:
 }

 static const struct got_error *
-log_selected_tree_entry(struct tog_view **new_view, int begin_x,
+log_selected_tree_entry(struct tog_view **new_view, int begin_y, int begin_x,
     struct tog_tree_view_state *s)
 {
 	struct tog_view *log_view;
@@ -6079,7 +6095,7 @@ log_selected_tree_entry(struct tog_view **new_view, in

 	*new_view = NULL;

-	log_view = view_open(0, 0, 0, begin_x, TOG_VIEW_LOG);
+	log_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_LOG);
 	if (log_view == NULL)
 		return got_error_from_errno("view_open");

@@ -6327,7 +6343,7 @@ input_tree_view(struct tog_view **new_view, struct tog
 	struct tog_tree_view_state *s = &view->state.tree;
 	struct tog_view *log_view, *ref_view;
 	struct got_tree_entry *te;
-	int begin_x = 0, n, nscroll = view->nlines - 3;
+	int begin_y = 0, begin_x = 0, n, nscroll = view->nlines - 3;

 	switch (ch) {
 	case 'i':
@@ -6339,10 +6355,18 @@ input_tree_view(struct tog_view **new_view, struct tog
 		if (!s->selected_entry)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = log_selected_tree_entry(&log_view, begin_x, s);
+			view_get_split(view, &begin_y, &begin_x);
+		err = log_selected_tree_entry(&log_view, begin_y, begin_x, s);
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		log_view->focussed = 1;
+		log_view->mode = view->mode;
+		log_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -6357,9 +6381,8 @@ input_tree_view(struct tog_view **new_view, struct tog
 	case 'r':
 		view->count = 0;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		ref_view = view_open(view->nlines, view->ncols,
-		    view->begin_y, begin_x, TOG_VIEW_REF);
+			view_get_split(view, &begin_y, &begin_x);
+		ref_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_REF);
 		if (ref_view == NULL)
 			return got_error_from_errno("view_open");
 		err = open_ref_view(ref_view, s->repo);
@@ -6367,8 +6390,16 @@ input_tree_view(struct tog_view **new_view, struct tog
 			view_close(ref_view);
 			return err;
 		}
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		ref_view->focussed = 1;
+		ref_view->mode = view->mode;
+		ref_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)
@@ -6536,7 +6567,8 @@ input_tree_view(struct tog_view **new_view, struct tog
 			if (err)
 				break;

-			if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+			if (view_is_parent_view(view) &&
+			    view->mode == TOG_VIEW_SPLIT_HRZN) {
 				err = view_init_hsplit(view, begin_y);
 				if (err)
 					break;
@@ -7070,8 +7102,7 @@ show_ref_view(struct tog_view *view)
 	werase(view->window);

 	s->ndisplayed = 0;
-	if (view->mode == TOG_VIEW_SPLIT_HRZN && view->child &&
-	    view_is_splitscreen(view->child))
+	if (view_is_hsplit_top(view))
 		--limit;  /* border */

 	if (limit == 0)
@@ -7209,7 +7240,7 @@ show_ref_view(struct tog_view *view)
 }

 static const struct got_error *
-browse_ref_tree(struct tog_view **new_view, int begin_x,
+browse_ref_tree(struct tog_view **new_view, int begin_y, int begin_x,
     struct tog_reflist_entry *re, struct got_repository *repo)
 {
 	const struct got_error *err = NULL;
@@ -7227,7 +7258,7 @@ browse_ref_tree(struct tog_view **new_view, int begin_
 	}


-	tree_view = view_open(0, 0, 0, begin_x, TOG_VIEW_TREE);
+	tree_view = view_open(0, 0, begin_y, begin_x, TOG_VIEW_TREE);
 	if (tree_view == NULL) {
 		err = got_error_from_errno("view_open");
 		goto done;
@@ -7290,7 +7321,8 @@ input_ref_view(struct tog_view **new_view, struct tog_
 		if (err)
 			break;

-		if (view->mode == TOG_VIEW_SPLIT_HRZN) {
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
 			err = view_init_hsplit(view, begin_y);
 			if (err)
 				break;
@@ -7316,13 +7348,21 @@ input_ref_view(struct tog_view **new_view, struct tog_
 		if (!s->selected_entry)
 			break;
 		if (view_is_parent_view(view))
-			begin_x = view_split_begin_x(view->begin_x);
-		err = browse_ref_tree(&tree_view, begin_x, s->selected_entry,
-		    s->repo);
+			view_get_split(view, &begin_y, &begin_x);
+		err = browse_ref_tree(&tree_view, begin_y, begin_x,
+		    s->selected_entry, s->repo);
 		if (err || tree_view == NULL)
 			break;
+		if (view_is_parent_view(view) &&
+		    view->mode == TOG_VIEW_SPLIT_HRZN) {
+			err = view_init_hsplit(view, begin_y);
+			if (err)
+				break;
+		}
 		view->focussed = 0;
 		tree_view->focussed = 1;
+		tree_view->mode = view->mode;
+		tree_view->nlines = view->lines - begin_y;
 		if (view_is_parent_view(view)) {
 			err = view_close_child(view);
 			if (err)

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