From 4a405bf4534731fb6f0ff2ea50e2c205dc071726 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Thu, 29 Jul 2021 12:29:43 +0200 Subject: [PATCH] Autoscroll in pager (#1223) Autoscroll the pager view if a new option `pager-autoscroll` is set to `on`. [tk: tweaked the code and added doc] --- doc/tigrc.5.adoc | 5 +++++ include/tig/options.h | 1 + src/pager.c | 3 +++ tigrc | 1 + 4 files changed, 10 insertions(+) diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 36b6c78ba..20c42b009 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -364,6 +364,11 @@ The following variables can be set: Mouse support requires that ncurses itself support mouse events and that you have enabled mouse support in ~/.tigrc with `set mouse = true`. +'pager-autoscroll' (bool):: + + Whether to scroll automatically the pager view while loading. Move the + cursor out of the last line to stop scrolling and back in to resume. + 'pgrp' (bool):: Make tig process-group leader when starting and clean all processes diff --git a/include/tig/options.h b/include/tig/options.h index 5c526e178..f636e6741 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -62,6 +62,7 @@ typedef struct view_column *view_settings; _(mouse, bool, VIEW_NO_FLAGS) \ _(mouse_scroll, int, VIEW_NO_FLAGS) \ _(mouse_wheel_cursor, bool, VIEW_NO_FLAGS) \ + _(pager_autoscroll, bool, VIEW_NO_FLAGS) \ _(pager_view, view_settings, VIEW_NO_FLAGS) \ _(pgrp, bool, VIEW_NO_FLAGS) \ _(reference_format, struct ref_format **, VIEW_NO_FLAGS) \ diff --git a/src/pager.c b/src/pager.c index 5d35eface..0f81e110d 100644 --- a/src/pager.c +++ b/src/pager.c @@ -137,6 +137,9 @@ pager_common_read(struct view *view, const char *data, enum line_type type, stru static bool pager_read(struct view *view, struct buffer *buf, bool force_stop) { + if (opt_pager_autoscroll && view->pos.offset + view->height == view->lines - 1) + do_scroll_view(view, 1); + if (!buf) { if (!diff_done_highlight(view->private)) { report("Failed run the diff-highlight program: %s", opt_diff_highlight); diff --git a/tigrc b/tigrc index 0b47182b3..73f658637 100644 --- a/tigrc +++ b/tigrc @@ -143,6 +143,7 @@ set mouse = no # Enable mouse support? set mouse-scroll = 3 # Number of lines to scroll via the mouse set mouse-wheel-cursor = no # Prefer moving the cursor to scrolling the view? set pgrp = no # Make tig process-group leader? +set pager-autoscroll = no # Scroll the pager view automatically while loading? # User-defined commands # ---------------------