bhauman / rebel-readline

Terminal readline library for Clojure dialects
Eclipse Public License 1.0
684 stars 37 forks source link

Flush adds an extra newline #175

Open aaronlahey opened 6 years ago

aaronlahey commented 6 years ago

Hi! It seems that calling (flush) adds an extra newline to the output. Is this expected or is there a way to disable this behavior?

Thanks!

~ :: clj
Clojure 1.9.0
user=> (do (print \.) (flush) (print \.) (flush))
..nil
user=>
~ :: clojure -Sdeps "{:deps {com.bhauman/rebel-readline {:mvn/version \"0.1.4\"}}}" -m rebel-readline.main
[Rebel readline] Type :repl/help for online help info
user=> (do (print \.) (flush) (print \.) (flush))
.
.
nil
dundalek commented 5 years ago

I encountered this also. Looks like it is an intentional behavior to ensure the prompt is displayed properly:

https://github.com/bhauman/rebel-readline/blob/1fc954215bc287ad590dac8e52c782d6077fee55/rebel-readline/src/rebel_readline/clojure/main.clj#L70 https://github.com/bhauman/rebel-readline/blob/1fc954215bc287ad590dac8e52c782d6077fee55/rebel-readline/src/rebel_readline/jline_api.clj#L337

An alternative might be to read out the cursor positon and insert a newline only if the cursor is not on the first column.