Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable truncation-delimiter w/ utf8 suggestion/special value #646

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/tigrc.5.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
2 changes: 1 addition & 1 deletion src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
12 changes: 12 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
213 changes: 213 additions & 0 deletions test/tigrc/truncation-test
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tigrc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down