Paper
Paper copied to clipboard
Command autocomplete/history does not directly write to terminal
Expected behavior
When the user presses Tab after typing an incomplete command, the correct text is filled in or the text has a color applied to it.
When the user presses an up/down arrow key, previous commands are shown.
Observed/Actual behavior
When the user presses Tab after typing an incomplete command, whitespace is added after the user's provided text OR no action happens.
When the user presses an up/down arrow key, the ASCII formatting of the arrow key is added OR no action happens.
Steps/models to reproduce
On Linux or Windows: Change the calling process of Java to a terminal other than that it started with, then run Java. Read data from this terminal's stdout. Send user input to the server by writing to the server's stdin.
Plugin and Datapack List
None
Paper version
Any Paper version with command autocomplete or command history
Other
The behavior of the command autocomplete and history feature does not directly write to the correct terminal buffer, which is preventing software such as Hajime from letting users use this feature. See https://github.com/Slackadays/Hajime/issues/15
This issue manifests if the terminal file descriptor of the server is read directly with a syscall like read(). All normal text comes out just fine, and colors created by commands work perfectly, but the application of colors to typed-in text does not work.
In Hajime's case, this was originally due to the provided user input being in canonical mode which prevents the server from reading what the user is typing in until they press the Enter key. However, even after switching out of canonical mode, which now sends individual characters to the server instead, the issue persists where the server does not send ASCII color formatting (or ASCII + regular characters in the case of command history) to the file descriptor which Hajime reads and presents to the user. Debugging shows that the server isn't simply sending data that's garbled, but rather none at all. This indicated that Paper (or Java) is using a nonstandard way to modifying user input, while the correct way is to send ASCII formatting sequences.
Not really sure how we'd deal with this, as this doesn't even sound like an issue on our side, more on jline's
Yeah how much power do we even have with the terminal logic in general with our current library? I'm not really knowledgeable in this field, but we in general have a lot of weird issues with the terminal. https://github.com/PaperMC/Paper/issues/2712
somebody would need to dig in to see if this is a paper, TCA, jline or java issue. terminal handling overall is a giant can of worms, so it will be hard to find somebody willing to do that 🙈