|
199 | 199 | (display-repl-status :stopped)
|
200 | 200 | (a.assoc (state) :repl nil))))
|
201 | 201 |
|
202 |
| -; By default, there is no way for us to tell the difference between |
203 |
| -; normal stdout log messages and the result of the expression we evaluated. |
204 |
| -; This is because if an expression results in the literal value None, the python |
205 |
| -; interpreter will not print out anything. |
206 |
| -; Replacing this hook ensures that the last line in the output after |
207 |
| -; sending a command is the result of the command. |
208 |
| -; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook |
209 |
| -(def update-python-displayhook |
210 |
| - (str.join "\n" ["import sys" |
211 |
| - "def format_output(val):" |
212 |
| - " print(repr(val))" |
213 |
| - "sys.displayhook = format_output\n"])) |
| 202 | +(def initialise-repl-code |
| 203 | + ;; By default, there is no way for us to tell the difference between |
| 204 | + ;; normal stdout log messages and the result of the expression we evaluated. |
| 205 | + ;; This is because if an expression results in the literal value None, the python |
| 206 | + ;; interpreter will not print out anything. |
| 207 | + ;; Replacing this hook ensures that the last line in the output after |
| 208 | + ;; sending a command is the result of the command. |
| 209 | + ;; Relevant docs: https://docs.python.org/3/library/sys.html#sys.displayhook |
| 210 | + |
| 211 | + ;; We also set the `__name__` to something else so `__main__` blocks aren't executed. |
| 212 | + (str.join |
| 213 | + "\n" |
| 214 | + ["import sys" |
| 215 | + "def conjure_format_output(val):" |
| 216 | + " print(repr(val))" |
| 217 | + "sys.displayhook = conjure_format_output\n" |
| 218 | + "__name__ = '__repl__'"])) |
214 | 219 |
|
215 | 220 | (defn start []
|
216 | 221 | (if (state :repl)
|
|
238 | 243 | (with-repl-or-warn
|
239 | 244 | (fn [repl]
|
240 | 245 | (repl.send
|
241 |
| - (prep-code update-python-displayhook) |
| 246 | + (prep-code initialise-repl-code) |
242 | 247 | (fn [msgs] nil)
|
243 | 248 | nil)))))
|
244 | 249 |
|
|
0 commit comments