Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve handling of carriage return ("\r")
A CARRIAGE RETURN character moves the head of the teletype printer (the carriage) to the beginning of the line, without scrolling the paper (this is done by the LINE FEED "\n") In a contemporary terminal emulator this translates to moving the cursor to the beginning of the current line. Any subsequent output then overwrites what was already on that line. This is how terminal progress bars are implemented. The existing implementation incorrectly treated "\r" as "\n", thus inserting a newline, instead of moving to the beginning of the current line. Instead iterate over the output and deal with "\r" and "\n" the way terminals do, "\r" (ASCII 13) moves to the beginning of the line, "\n" (ASCII 10) moves to the beginning of the next line. Any output overwrites output on the same line after the cursor position. Sample code: ``` (println "aaaa\rbb\ncccc\rdd") ;; Outputs: ;; bbaa ;; ddcc (dotimes [i 20] (print "\r[" (inc i) "]") (flush) (Thread/sleep 500)) ;; prints a counter in place ``` Feedback welcome as I'm not sure of the performance impact of dealing with each character individually. Also not sure what the effect is of propertizing and running cider-repl-preoutput-hook per character. Fixes clojure-emacs#1677 (which was closed but not actually implemented, only worked around)
- Loading branch information