Fix #1280: babashka REPL doesn't quit right after ctrl-d (#1450)

the problem is that parser/parse-next waits for an enter before returning an object
we can use peek-char to pre-emptively react to any EOF at the start of the line
in case of not-start-of-line, parse-next takes over

Co-authored-by: Alice Margatroid <code@alice.bunkerlabs.net>
This commit is contained in:
Gabe 2022-12-14 15:57:07 +02:00 committed by GitHub
parent dc2502ebae
commit 965c177bca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,13 +63,14 @@
(eval-form sci-ctx `(apply require (quote ~m/repl-requires)))))
:read (or read
(fn [_request-prompt request-exit]
(let [v (parser/parse-next sci-ctx in)]
(skip-if-eol in)
(if (or (identical? :repl/quit v)
(identical? :repl/exit v)
(identical? parser/eof v))
request-exit
v))))
(if (nil? (r/peek-char in))
request-exit
(let [v (parser/parse-next sci-ctx in)]
(skip-if-eol in)
(if (or (identical? :repl/quit v)
(identical? :repl/exit v))
request-exit
v)))))
:eval (or eval
(fn [expr]
(sci/with-bindings {sci/file "<repl>"