[NREPL-9] (read-line) doesn't prompt for input after a (read) Created: 19/Feb/12 Updated: 21/Feb/12 Resolved: 21/Feb/12 |
|
| Status: | Closed |
| Project: | tools.nrepl |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Defect | Priority: | Minor |
| Reporter: | Colin Jones | Assignee: | Chas Emerick |
| Resolution: | Completed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
When (read-line) is preceded by (read), it already has a newline in the stream, and returns "" immediately rather than prompting for input. (read) then (read-line) works fine in the stock Clojure repl because the REPL shares STDIN with the in used by the normal (read) and (read-line) calls. So when the REPL's loop does clojure.main/repl-read (to get my evaluation input "(read-line)"), it skips whitespace before the read for the thing to eval, reads that thing, and then skips a newline, if that's the next thing: https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L145-161 That allows the .read calls generated by the (read-line) execution to start after a trailing newline left in the stream. We can do the same thing in nrepl.middleware.session/add-stdin on an eval message, but we need to check .ready first, to avoid sending unnecessary :need-input requests back to the client. I think this does belong in add-stdin, since it's essentially a stdin concern, even though it acts on the eval message. I've got one test exposing the problem, and one proving we only eat newlines, not any old trailing character. I had to stick :stdin-reader on the session to enable consuming the newline from the middleware - not sure whether there's a way to do without it that I'm not seeing. |
| Comments |
| Comment by Chas Emerick [ 21/Feb/12 5:17 AM ] |
|
Thanks for chasing this down! Patch applied to master. |