On Mon, 31 Mar 2025 17:22:45 GMT, David M. Lloyd <d...@openjdk.org> wrote:

>> The `java.io.Console` has several backends: a simple on in `java.base`, a 
>> more convenient one in `jdk.internal.le` (with line-reading based on JLine) 
>> and one for JShell.
>> 
>> The backend based on JLine is proving to be a somewhat problematic - JLine 
>> is very powerful, possibly too powerful and complex for the simple task of 
>> editing a line with no completion, no history, no variables, no commands, 
>> etc. As a consequence, there are inevitable sharp edges in this backend.
>> 
>> The idea in this PR is to replace the use of JLine in the `jdk.internal.le` 
>> backend with a simple escape code interpreter, that only handles a handful 
>> of keys/codes (left/right arrow, home, end, delete, backspace, enter), and 
>> ignores the rest. The goal is to have something simple with less surprising 
>> behavior.
>
> src/jdk.internal.le/share/classes/jdk/internal/console/SimpleConsoleReader.java
>  line 75:
> 
>> 73:                     }
>> 74:                     continue READ;
>> 75:                 case '\033':
> 
> If this is meant to be platform-agnostic, is it really safe to make these 
> assumptions about the ability to produce or interpret escape codes and to 
> make assumptions about their behavior on the user's terminal? I don't think 
> it would even be safe to assume a single terminal type or interpretation on 
> POSIX-type OSes; that's what things like `terminfo`/`termcap` are supposed to 
> be for, right?

In theory, yes, that's what `terminfo` is supposed to do. But `terminfo` has 
its own set of problems, and what we get from a terminal and what we send to 
the terminal is so simple and generally supported, that it should be possible 
to make it work on all realistic terminals(*). Or is there a particular 
terminal you have in mind?

(*) I admit I've forgot that `\E[7~`/`\E[8~` is Home/End as well. I'll fix that.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24242#discussion_r2022656839

Reply via email to