jline / jline2

Jline 2.x
http://jline.github.com/jline2/
Other
711 stars 183 forks source link

jline3 "fresh-line" logic problematical #257

Closed PerBothner closed 8 years ago

PerBothner commented 8 years ago

In LineReaderImpl's readLine method there is logic to "Make sure we position the cursor on column 0". (Search for a comment with that text.) I.e. do nothing if we're at column 0 but otherwise move to the start of the next line. (This is the CommonLisp "fresh-line" function.)

I believe this logic causes more problems than it solves. Most obviously, I'm confused by the use of "~". The actual "~" shows in the output (at least in my usage), which is obviously a problem.

If we replace the initial "~" by (one more) space, we get the desired effect. (Though only if thd terminal supports vt100-style line-wrap.) However, copy and paste is wrong because terminals (such as xterm) that keep track on line-wrapping think the previous line is wrapped.

With xterm and similar we can make use of a cursor position request and go to a new line unless the column is 0. This does require an extra round-trip to the terminal. I don't believe there is a terminfo capability for cursor position request, but checking TERM for "xterm" is probably good enough in practice.

My recommendation: Drop the entire functionality (it is not handled by GNU readline), and make "fresh-line" be the responsibility of the application, not jline. Concretely, remove the lines starting with "Make sure we position the cursor on column 0" and ending with "print(sb.toAnsi(terminal));".

PerBothner commented 8 years ago

If we keep the "fresh-line" functionality, could we at least make it controlled by an Option? I can create a pull request either way: controlled by an option, or jusr remove the functionality.

gnodet commented 8 years ago

PR merged with an option to opt-in the auto fresh line behaviour.