Flexible filename truncation (#1029)
* allow flexible truncation of filenames As of now, lf truncates always at the end. So for long filenames one can not see the end (especially not the file ending, like .jpeg or .pdf). [MidnightCommander](https://github.com/MidnightCommander/mc/) truncates too long filenames in the middle, so it's possible to see the beginning and the end of the too long filename. This commit allows to specify a flexible point for the truncation in percent of the available space. * The default value of 100 for the new `truncatepct` option means no change in lf behaviour. * More adhering to naming convention. * Improve error message for invalid `truncatepct` values. * Remove redundant test cases. * FIXUP Add dummy empty line to make `go fmt` happy. * Avoid explicit "cast" to rune array. * fix(doc.go): remove line with single dot This was there to avoid that `go fmt` touches the next item with `waitmsg`. However, removing the spaces before the example list items has the same effect.
This commit is contained in:
1 parent
e885abe1a3
commit
b1a851953b
9 files changed
+120
-1
No files matched your search
@@ -83,6 +83,47 @@ func TestRuneSliceWidthRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRuneSliceWidthLastRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
rs []rune
|
||||
maxWidth int
|
||||
exp []rune
|
||||
}{
|
||||
{[]rune{}, 0, []rune{}},
|
||||
{[]rune{}, 1, []rune{}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 0, []rune{}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 1, []rune{' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 2, []rune{'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 3, []rune{'ı', 'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 4, []rune{'a', 'ı', 'b', ' '}},
|
||||
{[]rune{'a', 'ı', 'b', ' '}, 5, []rune{'a', 'ı', 'b', ' '}},
|
||||
{[]rune{'世', '界', '世', '界'}, 0, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 1, []rune{}},
|
||||
{[]rune{'世', '界', '世', '界'}, 2, []rune{'界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 3, []rune{'界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 4, []rune{'世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 5, []rune{'世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 6, []rune{'界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 7, []rune{'界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 8, []rune{'世', '界', '世', '界'}},
|
||||
{[]rune{'世', '界', '世', '界'}, 9, []rune{'世', '界', '世', '界'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 0, []rune{}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 1, []rune{'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 2, []rune{'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 3, []rune{'界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 4, []rune{'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 5, []rune{'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 6, []rune{'世', 'a', '界', 'ı'}},
|
||||
{[]rune{'世', 'a', '界', 'ı'}, 7, []rune{'世', 'a', '界', 'ı'}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if got := runeSliceWidthLastRange(test.rs, test.maxWidth); !reflect.DeepEqual(got, test.exp) {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", test.rs, test.exp, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEscape(t *testing.T) {
|
||||
tests := []struct {
|
||||
s string
|
||||
|
||||
Reference in new issue
Block a user