Skip to content

Commit

Permalink
Allow maxwidth to be expressed in % of the view width
Browse files Browse the repository at this point in the history
  • Loading branch information
koutcher committed Dec 13, 2020
1 parent c27de8f commit e4305b9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
12 changes: 9 additions & 3 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|<bool>]: How to display file sizes.
Expand Down Expand Up @@ -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|<bool>]: How to display the status
Expand Down
10 changes: 10 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions test/tigrc/width-test
Original file line number Diff line number Diff line change
Expand Up @@ -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
' \
<<EOF
ee912870202200a0b9cf 1| 2014-03-01 17:26 -05 Jonas Fonseca * [master] WIP: Upgrade to 0.4-SNAPSHOT and DCE
a1dcf1aaa11470978db1 | 2014-03-01 15:59 -05 Jonas Fonseca * Add type parameter for js.Dynamic
296fc90ba2c47ba3d2b6 | 2014-01-16 22:51 -05 Jonas Fonseca * Move classes under org.scalajs.benchmark package scope
b4ad81f17b4c3fc33ed5 | 2014-01-16 17:43 -05 Jonas Fonseca * Bump Scala.js version to 0.3-SNAPSHOT
4a68cf3c338f5724d838 5| 2014-01-16 17:39 -05 Jonas Fonseca * Integrate app code into the benchmark infrastructure
e59a941c4e7d51cd172e | 2014-01-16 07:47 -08 Jonas Fonseca M-. Merge pull request #4 from phaller/patch-1
940efafc379db7c6df99 | 2014-01-16 15:32 +01 Philipp Haller | * Fix link to Dart benchmark harness
110e090f815f40d649f5 | 2013-12-17 00:02 +01 Jonas Fonseca *-' Update links to reflect project name change
894a53e03a017642abdc | 2013-12-03 23:35 -05 Jonas Fonseca * Use Scala.js 0.2-SNAPSHOT
c819b08eb5b05dde4df5 10| 2013-11-26 23:39 -05 Jonas Fonseca * Extract the benchmark list variable name; fix push to use scoped variable
5bd6df6603f25ff035f1 | 2013-11-26 23:31 -05 Jonas Fonseca * Solve the easiest sudoku grid
988c77aad5798f1e087e | 2013-11-26 23:22 -05 Jonas Fonseca * Disable phantomjs by default
5d84af022bc87ef13c29 | 2013-11-26 22:55 -05 Jonas Fonseca * Exclude Sudoku when running all benchmarks
5d80606b72b490e213a0 | 2013-11-26 22:52 -05 Jonas Fonseca * Fix reference setup to work for node
[main] ee912870202200a0b9cf4fd86ba57243212d341e - commit 1 of 48 29%
EOF

### tree-view

test_case tree-widths-default \
Expand Down

0 comments on commit e4305b9

Please sign in to comment.