jart / bestline

ANSI Standard X3.64 Teletypewriter Command Session Library
Other
443 stars 29 forks source link

Issues with long lines #14

Open jsteemann opened 2 years ago

jsteemann commented 2 years ago

Just compiled bestline_example and tried its Unicode-handling, because I looking for a replacement of a hacked version of linenoise with partial Unicode support.

The following was run in a terminal of size 80x24 in a gnome terminal window on Ubuntu 21.10.

$ echo $TERM
xterm-256color

The initial prompt is hello>, which is fine. Pasting the string πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’ into bestline also works fine. Now when pasting the same string πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’ again, the line would be longer than 80 characters, so bestline wraps the line (correctly). However, on its way to there bestline prints the complete input line once again for each overflow character.

Example ("x" denotes cursor position): Initial:

hello> x

After pasting the string once:

hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’x

After pasting the string twice:

hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
α‹­αŠ¨αˆ°αˆ΅α’x

This should instead be just

hello> πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ αŠ α‹­αŠ¨αˆ°αˆ΅α’πŸ’©πŸΊπŸŒ§ β›ˆ 🌩 ⚑πŸ”₯πŸ’₯🌨 "αˆ°αˆ›α‹­ αŠ α‹­α‰³αˆ¨αˆ΅ αŠ•αŒ‰αˆ₯ አ
α‹­αŠ¨αˆ°αˆ΅α’x

As a follow-up, I was trying to go down in history (pressing the down arrow key), which brings up the last used line. It provides the correct line, but pressing it several times moves everything else up even one line. This shouldn't be the case because when there is room to display the last full history entry, nothing should be moved around.

Thanks for the amazing work on bestline! IMO a modern linenoise successor is much needed!

jart commented 2 years ago

Thanks for the detailed report. Still working to fully debug the software to get it ready for release and help like this is invaluable. I intend to dive into this sometime in the next two weeks. If you spot any other blockers then please file issues. Feature requests are welcome too.