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:
raslop authored and GitHub committed 2023-07-03 12:48:51 +03:00
1 parent e885abe1a3
commit b1a851953b
9 files changed
+120 -1

No files matched your search

+18
View File
@@ -172,6 +172,7 @@ The following options can be used to customize the behavior of lf:
tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
truncatepct int (default 100)
waitmsg string (default 'Press any key to continue')
wrapscan bool (default true)
wrapscroll bool (default false)
@@ -941,6 +942,23 @@ Format string of the file modification time shown in the bottom line.
Truncate character shown at the end when the file name does not fit to the pane.
truncatepct int (default 100)
When a filename is too long to be shown completely, the available space is
partitioned in two pieces. truncatepct defines a fraction (in percent
between 0 and 100) for the size of the first piece, which will show the
beginning of the filename. The second piece will show the end of the filename
and will use the rest of the available space. Both pieces are separated by the
truncation character (truncatechar).
A value of 100 will only show the beginning of the filename,
while a value of 0 will only show the end of the filename, e.g.:
- `set truncatepct 100` -> "very-long-filename-tr~" (default)
- `set truncatepct 50` -> "very-long-f~-truncated"
- `set truncatepct 0` -> "~ng-filename-truncated"
waitmsg string (default 'Press any key to continue')
String shown after commands of shell-wait type.