From: Jonas Fonseca Date: Fri, 13 Feb 2009 13:38:00 +0000 (+0100) Subject: Make behavior of horizontal scrolling configurable X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ab798b42f8724161619360ac838dd138cbda1cad;p=tig.git Make behavior of horizontal scrolling configurable Requested by bill lam. --- diff --git a/NEWS b/NEWS index e52130c..7bd2889 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ Improvements: - Colors for 256-capable terminals can be specified as colorN. - Entering a number in the prompt will jump to that line number. - Handle core.worktree by setting GIT_DIR and GIT_WORK_TREE. + - Make behavior of horizontal scrolling configurable by setting the + 'horizontal-scroll' variable to a number or a percentage. Defaults to + scrolling 50% of the view width. Bug fixes: diff --git a/tig.c b/tig.c index 2b2607b..705e3dd 100644 --- a/tig.c +++ b/tig.c @@ -109,7 +109,6 @@ static size_t utf8_length(const char **string, size_t col, int *width, size_t ma /* The default interval between line numbers. */ #define NUMBER_INTERVAL 5 -#define SCROLL_INTERVAL 1 #define TAB_SIZE 8 @@ -863,6 +862,7 @@ static bool opt_line_graphics = TRUE; 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 int opt_tab_size = TAB_SIZE; static int opt_author_cols = AUTHOR_COLS-1; static char opt_path[SIZEOF_STR] = ""; @@ -1384,6 +1384,27 @@ static const struct enum_map attr_map[] = { #define set_attribute(attr, name) map_enum(attr, attr_map, name) +static int parse_step(double *opt, const char *arg) +{ + *opt = atoi(arg); + if (!strchr(arg, '%')) + return OK; + + /* "Shift down" so 100% and 1 does not conflict. */ + *opt = (*opt - 1) / 100; + if (*opt >= 1.0) { + *opt = 0.99; + config_msg = "Step value larger than 100%"; + return ERR; + } + if (*opt < 0.0) { + *opt = 1; + config_msg = "Invalid step value"; + return ERR; + } + return OK; +} + static int parse_int(int *opt, const char *arg, int min, int max) { @@ -1513,6 +1534,9 @@ option_set_command(int argc, const char *argv[]) if (!strcmp(argv[0], "author-width")) return parse_int(&opt_author_cols, argv[2], 0, 1024); + if (!strcmp(argv[0], "horizontal-scroll")) + return parse_step(&opt_hscroll, argv[2]); + if (!strcmp(argv[0], "tab-size")) return parse_int(&opt_tab_size, argv[2], 1, 1024); @@ -2285,6 +2309,15 @@ 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) @@ -2346,10 +2379,10 @@ scroll_view(struct view *view, enum request request) report("Cannot scroll beyond the first column"); return; } - if (view->yoffset <= SCROLL_INTERVAL) + if (view->yoffset <= apply_step(opt_hscroll, view->width)) view->yoffset = 0; else - view->yoffset -= SCROLL_INTERVAL; + view->yoffset -= apply_step(opt_hscroll, view->width); redraw_view_from(view, 0); report(""); return; @@ -2358,7 +2391,9 @@ scroll_view(struct view *view, enum request request) report("Cannot scroll beyond the last column"); return; } - view->yoffset += SCROLL_INTERVAL; + view->yoffset += apply_step(opt_hscroll, view->width); + if (view->yoffset > view->width) + view->yoffset = view->width; redraw_view(view); report(""); return; diff --git a/tigrc.5.txt b/tigrc.5.txt index d0e8c91..59149ac 100644 --- a/tigrc.5.txt +++ b/tigrc.5.txt @@ -51,6 +51,7 @@ set show-refs = yes # Show references? set show-line-numbers = no # Show line numbers? set line-number-interval = 5 # Interval between line numbers set commit-encoding = "UTF-8" # Commit encoding +set horizontal-scroll = 33% # Scroll 33% of the view width -------------------------------------------------------------------------- Or in the git configuration files: @@ -63,7 +64,7 @@ Or in the git configuration files: tab-size = 8 # Number of spaces per tab -------------------------------------------------------------------------- -The type of variables are either bool, int, and string. +The type of variables are either bool, int, string, or mixed. Valid bool values:: @@ -78,6 +79,11 @@ Valid string values:: A string of characters. Optionally, use either ' or " as delimiters. +Valid mixed values:: + + These values are composites of the above types. The valid values are + specified in the description. + Variables ~~~~~~~~~ @@ -111,6 +117,14 @@ The following variables can be set: Number of spaces per tab. The default is 8 spaces. +'horizontal-scroll' (mixed):: + + Interval to scroll horizontally in each step. Can be specified either + as the number of columns, e.g. '5', or as a percentage of the view + width, e.g. '33%', where the maximum is 100%. For percentages it is + always ensured that at least one column is scrolled. The default is to + scroll '50%' of the view width. + 'commit-encoding' (string):: The encoding used for commits. The default is UTF-8. Not this option