diff options
author | Roland Walker <walker@pobox.com> | 2017-07-05 11:58:21 -0400 |
---|---|---|
committer | Jonas Fonseca <jonas.fonseca@gmail.com> | 2017-07-06 18:06:40 -0400 |
commit | b24eacfcddeb6e85b5a0250ce09ea986b9fa6ada (patch) | |
tree | 96c3f4900ba7c29f30895350c9d3836c46f66f46 | |
parent | fdf3cd76468296251ef1e206569981fca33ca15c (diff) |
configurable truncation-delimiter w/ utf8 suggest
-rw-r--r-- | doc/tigrc.5.adoc | 6 | ||||
-rw-r--r-- | include/tig/options.h | 1 | ||||
-rw-r--r-- | src/draw.c | 2 | ||||
-rw-r--r-- | src/options.c | 12 | ||||
-rwxr-xr-x | test/tigrc/truncation-test | 213 | ||||
-rw-r--r-- | tigrc | 1 |
6 files changed, 234 insertions, 1 deletions
diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 9b69f7dd..99753bd2 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -190,6 +190,12 @@ The following variables can be set: What type of character graphics for line drawing. +'truncation-delimiter' (mixed) [utf-8|<string>]:: + + A single character to draw where columns are truncated. The default is + "~". The special value "utf-8" refers to the character "⋯" + ("Midline Horizontal Ellipsis"). + 'horizontal-scroll' (mixed):: Interval to scroll horizontally in each step. Can be specified either diff --git a/include/tig/options.h b/include/tig/options.h index 0b91f6d0..0753b7a0 100644 --- a/include/tig/options.h +++ b/include/tig/options.h @@ -76,6 +76,7 @@ typedef struct view_column *view_settings; _(status_view, view_settings, VIEW_NO_FLAGS) \ _(tab_size, int, VIEW_NO_FLAGS) \ _(tree_view, view_settings, VIEW_NO_FLAGS) \ + _(truncation_delimiter, const char *, VIEW_NO_FLAGS) \ _(vertical_split, enum vertical_split, VIEW_RESET_DISPLAY | VIEW_DIFF_LIKE) \ _(wrap_lines, bool, VIEW_NO_FLAGS) \ _(wrap_search, bool, VIEW_NO_FLAGS) \ @@ -76,7 +76,7 @@ draw_chars(struct view *view, enum line_type type, const char *string, int lengt if (trimmed && use_tilde) { set_view_attr(view, LINE_DELIMITER); - waddch(view->win, '~'); + waddstr(view->win, opt_truncation_delimiter ? opt_truncation_delimiter : "~"); col++; } diff --git a/src/options.c b/src/options.c index cb2e78c4..3c6f5b12 100644 --- a/src/options.c +++ b/src/options.c @@ -643,6 +643,18 @@ parse_option(struct option_info *option, const char *prefix, const char *arg) return ERROR_OUT_OF_MEMORY; } + if (!strcmp(name, "truncation-delimiter")) { + if (!strcmp(alloc, "utf-8") || !strcmp(alloc, "utf8")) { + alloc = strdup("⋯"); + if (!alloc) + return ERROR_OUT_OF_MEMORY; + } else if (utf8_width_of(alloc, -1, -1) != 1) { + alloc = strdup("~"); + if (!alloc) + return ERROR_OUT_OF_MEMORY; + } + } + free((void *) *value); *value = alloc; return SUCCESS; diff --git a/test/tigrc/truncation-test b/test/tigrc/truncation-test new file mode 100755 index 00000000..cb386388 --- /dev/null +++ b/test/tigrc/truncation-test @@ -0,0 +1,213 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh + +export LINES=16 +export COLUMNS=100 + +in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz" + +test_case delimiter-default \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE~ 5| Redistribution and use in source and binary forms, with or without modification, +LICE~ 8| * Redistributions of source code must retain the above copyright notice, +READ~ 27| time you save a source file, a compilation of the project is triggered. +comm~ 633| * Extract a plan for resatisfaction starting from the given source +comm~ 649| * Assume: sources are all satisfied. +comm~ 651| Planner.prototype.makePlan = function (sources) { +comm~ 654| var todo = sources; +comm~ 671| var sources = new OrderedCollection(); +comm~ 676| sources.add(c); +comm~ 678| return this.makePlan(sources); +comm~ 2| // Redistribution and use in source and binary forms, with or without +comm~ 6| // * Redistributions of source code must retain the above copyright +comm~ 45| Object.extend = function(destination, source) { +comm~ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-literal \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = _ + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE_ 5| Redistribution and use in source and binary forms, with or without modification, +LICE_ 8| * Redistributions of source code must retain the above copyright notice, +READ_ 27| time you save a source file, a compilation of the project is triggered. +comm_ 633| * Extract a plan for resatisfaction starting from the given source +comm_ 649| * Assume: sources are all satisfied. +comm_ 651| Planner.prototype.makePlan = function (sources) { +comm_ 654| var todo = sources; +comm_ 671| var sources = new OrderedCollection(); +comm_ 676| sources.add(c); +comm_ 678| return this.makePlan(sources); +comm_ 2| // Redistribution and use in source and binary forms, with or without +comm_ 6| // * Redistributions of source code must retain the above copyright +comm_ 45| Object.extend = function(destination, source) { +comm_ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-quoted-literal \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = "_" + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE_ 5| Redistribution and use in source and binary forms, with or without modification, +LICE_ 8| * Redistributions of source code must retain the above copyright notice, +READ_ 27| time you save a source file, a compilation of the project is triggered. +comm_ 633| * Extract a plan for resatisfaction starting from the given source +comm_ 649| * Assume: sources are all satisfied. +comm_ 651| Planner.prototype.makePlan = function (sources) { +comm_ 654| var todo = sources; +comm_ 671| var sources = new OrderedCollection(); +comm_ 676| sources.add(c); +comm_ 678| return this.makePlan(sources); +comm_ 2| // Redistribution and use in source and binary forms, with or without +comm_ 6| // * Redistributions of source code must retain the above copyright +comm_ 45| Object.extend = function(destination, source) { +comm_ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-empty-fallback \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = "" + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE~ 5| Redistribution and use in source and binary forms, with or without modification, +LICE~ 8| * Redistributions of source code must retain the above copyright notice, +READ~ 27| time you save a source file, a compilation of the project is triggered. +comm~ 633| * Extract a plan for resatisfaction starting from the given source +comm~ 649| * Assume: sources are all satisfied. +comm~ 651| Planner.prototype.makePlan = function (sources) { +comm~ 654| var todo = sources; +comm~ 671| var sources = new OrderedCollection(); +comm~ 676| sources.add(c); +comm~ 678| return this.makePlan(sources); +comm~ 2| // Redistribution and use in source and binary forms, with or without +comm~ 6| // * Redistributions of source code must retain the above copyright +comm~ 45| Object.extend = function(destination, source) { +comm~ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-too-long-fallback \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = multicharacter + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE~ 5| Redistribution and use in source and binary forms, with or without modification, +LICE~ 8| * Redistributions of source code must retain the above copyright notice, +READ~ 27| time you save a source file, a compilation of the project is triggered. +comm~ 633| * Extract a plan for resatisfaction starting from the given source +comm~ 649| * Assume: sources are all satisfied. +comm~ 651| Planner.prototype.makePlan = function (sources) { +comm~ 654| var todo = sources; +comm~ 671| var sources = new OrderedCollection(); +comm~ 676| sources.add(c); +comm~ 678| return this.makePlan(sources); +comm~ 2| // Redistribution and use in source and binary forms, with or without +comm~ 6| // * Redistributions of source code must retain the above copyright +comm~ 45| Object.extend = function(destination, source) { +comm~ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-special-value \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = utf8 + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE⋯ 5| Redistribution and use in source and binary forms, with or without modification, +LICE⋯ 8| * Redistributions of source code must retain the above copyright notice, +READ⋯ 27| time you save a source file, a compilation of the project is triggered. +comm⋯ 633| * Extract a plan for resatisfaction starting from the given source +comm⋯ 649| * Assume: sources are all satisfied. +comm⋯ 651| Planner.prototype.makePlan = function (sources) { +comm⋯ 654| var todo = sources; +comm⋯ 671| var sources = new OrderedCollection(); +comm⋯ 676| sources.add(c); +comm⋯ 678| return this.makePlan(sources); +comm⋯ 2| // Redistribution and use in source and binary forms, with or without +comm⋯ 6| // * Redistributions of source code must retain the above copyright +comm⋯ 45| Object.extend = function(destination, source) { +comm⋯ 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +test_case delimiter-utf8-literal \ + --tigrc=' + set line-graphics = ascii + set grep-view = file-name:yes,width=5 line-number:yes,interval=1 text + set truncation-delimiter = … + ' \ + --script=' + :g + source<Enter> + :refresh + ' \ + <<EOF +LICE… 5| Redistribution and use in source and binary forms, with or without modification, +LICE… 8| * Redistributions of source code must retain the above copyright notice, +READ… 27| time you save a source file, a compilation of the project is triggered. +comm… 633| * Extract a plan for resatisfaction starting from the given source +comm… 649| * Assume: sources are all satisfied. +comm… 651| Planner.prototype.makePlan = function (sources) { +comm… 654| var todo = sources; +comm… 671| var sources = new OrderedCollection(); +comm… 676| sources.add(c); +comm… 678| return this.makePlan(sources); +comm… 2| // Redistribution and use in source and binary forms, with or without +comm… 6| // * Redistributions of source code must retain the above copyright +comm… 45| Object.extend = function(destination, source) { +comm… 46| for (var property in source) { +[grep] LICENSE - line 1 of 24 58% +EOF + +run_test_cases @@ -73,6 +73,7 @@ set show-changes = yes # Show changes commits in the main view? set wrap-lines = no # Wrap long lines in pager views? set tab-size = 8 # Number of spaces to use when expanding tabs set line-graphics = default # Enum: ascii, default, utf-8 +set truncation-delimiter = ~ # Character drawn for truncations, or "utf-8" # Format reference names based on type. # - head : The current HEAD. |