veeso / termscp

🖥 A feature rich terminal UI file transfer and explorer with support for SCP/SFTP/FTP/S3/SMB
https://termscp.veeso.dev
MIT License
1.61k stars 46 forks source link

[BUG] - Panics when displaying long non-ascii filenames #104

Closed CircuitCoder closed 2 years ago

CircuitCoder commented 2 years ago

Description

When displaying files with long non-ascii filenames (locally or remotely), termscp panics. Presumably this is due to incorrect line-wrap / ellipsis handling?

Especially, if PWD contains files with long non-ascii filename, then termscp immediately panics on startup.

Steps to reproduce

$ mkdir -p /tmp/termscp-test
$ cd /tmp/termscp-test
$ echo > 喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵
# With a narrow terminal
$ termscp
thread 'main' panicked at 'byte index 23 is not a char boundary; it is inside '喵' (bytes 21..24) of `喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵`', /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/termscp-0.8.1/src/explorer/formatter.rs:308:37
                            note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behaviour

Should not panic when display any filename.

Environment

Log

(I tested in /root/tmp)

2022-03-29T16:32:05+0000 [INFO] Reading directory /root/tmp 2022-03-29T16:32:05+0000 [INFO] Stating file /root/tmp/喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵喵

CircuitCoder commented 2 years ago

On second thought, encoded width in UTF-8 doesn't always correspond to a glyph's displayed width. If precise handling of Unicode is expected, additional crates may be needed (e.g. unicode_width).