jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 218 forks source link

[consoleui] Make it easier to extend `ConsolePrompt` #1068

Closed quintesse closed 2 months ago

quintesse commented 2 months ago

This PR is meant as somewhat of a first step towards fixing #1051 . When trying out different scenarios I was running into the issue that ConsolePrompt has all this useful code but it's somewhat hard to extend it because all its innards are private. So the first commit is simply making those private fields and methods protected.

The second commit splits up the prompt() method. It's quite a big method that has both a loop and a whole bunch of of code to handle the different kinds of prompt elements that are supported. The fact that all that code is inside the loop makes it basically impossible to add any new element types or to try to handle any of them differently without basically copying and pasting the entire code to a new class. So the second commit splits the prompt() method in two: the public prompt() still has the loop but the loop is now simplified to mostly calling a new protected method called promptElement(). This gives a subclass the possibility to override the promptElement() method to, for example, add support for a new custom element type.

They are not big changes but they make experimenting with the consoleui a whole lot easier and more powerful.

Wdyt @mattirn ?