diff --git a/NEWS.adoc b/NEWS.adoc index c98d6cf5c..4b25b2a29 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -9,6 +9,7 @@ Improvements: - Jump from blame to commit. (#355) - Start blame of an uncommitted deleted line from HEAD so the line's origin can be traced. (#1008) - Add line-graphics = auto. (#834) + - Allow maxwidth to be expressed in % of the view width. Bug fixes: diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index d99441a7d..6a0504e45 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -467,7 +467,9 @@ author:: 1 and 10, the author name will be abbreviated to the author's initials. When set to zero, the width is automatically sized to fit the content. - 'maxwidth' (int): Maximum width of the column. Permit automatically - sizing content, up to this limit. + sizing content, up to this limit. Can be specified either as the number + of columns, e.g. '15', or as a percentage of the view width, e.g. '20%', + where the maximum is 100%. commit-title:: - 'graph' (mixed) [no|v2|v1]: Whether to show the revision graph in the @@ -501,7 +503,9 @@ file-name:: - 'width' (int): Width of the column. When set to zero, the width is automatically sized to fit the content. - 'maxwidth' (int): Maximum width of the column. Permit automatically - sizing content, up to this limit. + sizing content, up to this limit. Can be specified either as the number + of columns, e.g. '15', or as a percentage of the view width, e.g. '20%', + where the maximum is 100%. file-size:: - 'display' (mixed) [default|units|]: How to display file sizes. @@ -534,7 +538,9 @@ ref:: - 'width' (int): Fixed width for the column. When set to zero, the width is automatically sized to fit the content. - 'maxwidth' (int): Maximum width of the column. Permit automatically - sizing content, up to this limit. + sizing content, up to this limit. Can be specified either as the number + of columns, e.g. '15', or as a percentage of the view width, e.g. '20%', + where the maximum is 100%. status:: - 'display' (mixed) [no|short|long|]: How to display the status diff --git a/src/options.c b/src/options.c index 07a136e4b..e0decfab9 100644 --- a/src/options.c +++ b/src/options.c @@ -631,6 +631,16 @@ parse_option(struct option_info *option, const char *prefix, const char *arg) } } + if (strstr(name, "-maxwidth") && strchr(arg, '%') && + parse_int(option->value, arg, 0, 100) == SUCCESS) { + int *value = option->value; + + /* Use negative values to signify maxwidth is + * not fixed but is a % of the view width. */ + *value *= -1; + return SUCCESS; + } + if (!strcmp(name, "line-number-interval") || !strcmp(name, "tab-size")) return parse_int(option->value, arg, 1, 1024); diff --git a/src/view.c b/src/view.c index 0447bc017..ee6fa1113 100644 --- a/src/view.c +++ b/src/view.c @@ -1443,6 +1443,8 @@ get_view_column(struct view *view, enum view_column_type type) return NULL; } +#define MAXWIDTH(maxwidth) (width == 0 ? maxwidth < 0 ? -maxwidth * view->width / 100 : maxwidth : 0) + bool view_column_info_update(struct view *view, struct line *line) { @@ -1461,7 +1463,7 @@ view_column_info_update(struct view *view, struct line *line) switch (column->type) { case VIEW_COLUMN_AUTHOR: width = column->opt.author.width; - maxwidth = width == 0 ? column->opt.author.maxwidth : 0; + maxwidth = MAXWIDTH(column->opt.author.maxwidth); break; case VIEW_COLUMN_COMMIT_TITLE: @@ -1473,7 +1475,7 @@ view_column_info_update(struct view *view, struct line *line) case VIEW_COLUMN_FILE_NAME: width = column->opt.file_name.width; - maxwidth = width == 0 ? column->opt.file_name.maxwidth : 0; + maxwidth = MAXWIDTH(column->opt.file_name.maxwidth); break; case VIEW_COLUMN_FILE_SIZE: @@ -1506,7 +1508,7 @@ view_column_info_update(struct view *view, struct line *line) case VIEW_COLUMN_REF: width = column->opt.ref.width; - maxwidth = width == 0 ? column->opt.ref.maxwidth : 0; + maxwidth = MAXWIDTH(column->opt.ref.maxwidth); break; case VIEW_COLUMN_SECTION: diff --git a/test/tigrc/width-test b/test/tigrc/width-test index 25c249c78..01f6908a5 100755 --- a/test/tigrc/width-test +++ b/test/tigrc/width-test @@ -175,6 +175,29 @@ c819b08eb5b05dde4df5 10| 2013-11-26 23:39 -05 Jonas Fonseca * Extrac [main] ee912870202200a0b9cf4fd86ba57243212d341e - commit 1 of 48 29% EOF +test_case main-maxwidths-10% \ + --script=' + :set main-view = id:yes,width=20 line-number:yes,interval=5,width=20 date:default,width=20 author:full,maxwidth=10% commit-title:yes,graph,refs,overflow=no + :refresh + ' \ + <