threads / patch / 17979

patchMake height of split view configurable

Subject: [tig PATCH 0/1] Make height of split view configurable

## tl;dr

3 messages between Feb 23, 2009 and Feb 25, 2009. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

tilo@tilo-schwarz.de· Feb 23, 2009, 22:24 UTC · lore
Rationale: On a large display with many rows it would be nice to be
able to configure the heights of the views in the split view. For
example, I like to have the lower diff view be 90% of the total
view height.

As it is, the patch lets the height of the lower view be configurable. Is it may be better to configure the height of the upper view?

Any input on variable nameing, code style etc. of course welcome.
Tilo Schwarz (1):
  Make height of split view configurable
 NEWS        |    3 +++
 tig.c       |   30 +++++++++++++++++++-----------
 tigrc.5.txt |    8 ++++++++
 3 files changed, 30 insertions(+), 11 deletions(-)
tilo@tilo-schwarz.de· Feb 23, 2009, 22:24 UTC · re: tilo@tilo-schwarz.de · lore

[PATCH 1/1] Make height of split view configurable

Signed-off-by: Tilo Schwarz <tilo@tilo-schwarz.de>
---
 NEWS        |    3 +++
 tig.c       |   30 +++++++++++++++++++-----------
 tigrc.5.txt |    8 ++++++++
 3 files changed, 30 insertions(+), 11 deletions(-)
Show changes to 3 files +30 −11

NEWS, tig.c, tigrc.5.txt

diff --git a/NEWS b/NEWS
index 15d898b..a48ed16 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,9 @@ Improvements:
  - Tree view: sort entries by name, date or author. Toggling is bound to
    'i' by default, with 'I' controlling whether or not to sort in
    ascending order.
+ - Make height of the lower view in a split view configurable by setting the
+   'split-view-height' variable to a number or a percentage. Defaults to 66% of
+   the total view height.
 
 Bug fixes:
 
diff --git a/tig.c b/tig.c
index 58d7bd0..ad77c95 100644
--- a/tig.c
+++ b/tig.c
@@ -72,6 +72,7 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
 
 #define ABS(x)		((x) >= 0  ? (x) : -(x))
 #define MIN(x, y)	((x) < (y) ? (x) :  (y))
+#define MAX(x, y)	((x) > (y) ? (x) :  (y))
 
 #define ARRAY_SIZE(x)	(sizeof(x) / sizeof(x[0]))
 #define STRING_SIZE(x)	(sizeof(x) - 1)
@@ -111,7 +112,8 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma
 
 #define TAB_SIZE	8
 
-#define	SCALE_SPLIT_VIEW(height)	((height) * 2 / 3)
+#define	SCALE_SPLIT_VIEW (2.0 / 3.0)
+#define MIN_VIEW_HEIGHT 4
 
 #define NULL_ID		"0000000000000000000000000000000000000000"
 
@@ -913,6 +915,7 @@ static bool opt_rev_graph		= FALSE;
 static bool opt_show_refs		= TRUE;
 static int opt_num_interval		= NUMBER_INTERVAL;
 static double opt_hscroll		= 0.50;
+static double opt_scale_split_view	= SCALE_SPLIT_VIEW;
 static int opt_tab_size			= TAB_SIZE;
 static int opt_author_cols		= AUTHOR_COLS-1;
 static char opt_path[SIZEOF_STR]	= "";
@@ -1594,6 +1597,9 @@ option_set_command(int argc, const char *argv[])
 	if (!strcmp(argv[0], "horizontal-scroll"))
 		return parse_step(&opt_hscroll, argv[2]);
 
+	if (!strcmp(argv[0], "split-view-height"))
+		return parse_step(&opt_scale_split_view, argv[2]);
+
 	if (!strcmp(argv[0], "tab-size"))
 		return parse_int(&opt_tab_size, argv[2], 1, 1024);
 
@@ -2223,6 +2229,15 @@ update_view_title(struct view *view)
 	wnoutrefresh(view->title);
 }
 
+static int
+apply_step(double step, int value)
+{
+	if (step >= 1)
+		return (int) step;
+	value *= step + 0.01;
+	return value ? value : 1;
+}
+
 static void
 resize_display(void)
 {
@@ -2240,7 +2255,9 @@ resize_display(void)
 	if (view != base) {
 		/* Horizontal split. */
 		view->width   = base->width;
-		view->height  = SCALE_SPLIT_VIEW(base->height);
+		view->height  = apply_step(opt_scale_split_view, base->height);
+		view->height  = MAX(view->height, MIN_VIEW_HEIGHT);
+		view->height  = MIN(view->height, base->height - MIN_VIEW_HEIGHT);
 		base->height -= view->height;
 
 		/* Make room for the title bar. */
@@ -2353,15 +2370,6 @@ goto_view_line(struct view *view, unsigned long offset, unsigned long lineno)
 	return FALSE;
 }
 
-static int
-apply_step(double step, int value)
-{
-	if (step >= 1)
-		return (int) step;
-	value *= step + 0.01;
-	return value ? value : 1;
-}
-
 /* Scrolling backend */
 static void
 do_scroll_view(struct view *view, int lines)
diff --git a/tigrc.5.txt b/tigrc.5.txt
index 8b9628f..e5de692 100644
--- a/tigrc.5.txt
+++ b/tigrc.5.txt
@@ -125,6 +125,14 @@ The following variables can be set:
 	always ensured that at least one column is scrolled. The default is to
 	scroll '50%' of the view width.
 
+'split-view-height' (mixed)::
+
+	Height of the lower view in a split view. Can be specified either as
+	the number of rows, e.g. '5', or as a percentage of the view height,
+	e.g. '80%', where the maximum is 100%. It is always ensured that the
+	smaller of the views is at least four rows high. The default is a view
+	height of '66%'.
+
 'commit-encoding' (string)::
 
 	The encoding used for commits. The default is UTF-8. Not this option
-- 
1.5.6.5
Jonas Fonseca· Feb 25, 2009, 22:17 UTC · re: tilo@tilo-schwarz.de · lore

Re: [tig PATCH 0/1] Make height of split view configurable

On Mon, Feb 23, 2009 at 23:24,  <tilo@tilo-schwarz.de> wrote:
Show 7 quoted lines
> Rationale: On a large display with many rows it would be nice to be
> able to configure the heights of the views in the split view. For
> example, I like to have the lower diff view be 90% of the total
> view height.
>
> As it is, the patch lets the height of the lower view be configurable.
> Is it may be better to configure the height of the upper view?
I don't know, the way you have done it seems reasonable.
> Any input on variable nameing, code style etc. of course welcome.

Very, very clean and nicely done with the reusing of the parse/apply step code. Thanks.

-- 
Jonas Fonseca

← back to recent threads