Fork me on GitHub
#cursive
<
2022-10-19
>
hlship22:10:33

Here's an odd question: I'm trying to make io.aviso.pretty smarter about when to emit ANSI escape codes, and when not to. I have a default based on whether (System/console) returns non-nil. This works well for clj and does the right things in pipes and background jobs (it will be nil, so no ANSI). However, in a REPL launched by Cursive, console is still nil. Is there another cheap test I can make to determine if in a Cursive-launched REPL? Otherwise, I have to lean on setting an environment variable to override the console check.

2
hlship16:10:47

Had the idea of checking loaded namespaces and saw cursive.repl.runtime may be a good indicator of running under Cursive.

👍 1
Ivar Refsdal07:10:18

I've used

(def is-cursive?
  (try
    (require '[cursive.repl.runtime])
    true
    (catch Exception _
      false)))
successfully before. Not sure if it's the best solution

flowthing10:10:29

You could probably just do (find-ns 'cursive.repl.runtime).

hlship17:10:08

Ultimnately, I looked for nrepl.core (see https://github.com/AvisoNovate/pretty/blob/master/src/io/aviso/ansi.clj#L35) as this worked for Cursive and for lein repl and for clj. It probably works for Emacs and other editors too, I have to assume that those can handle ANSI color/font codes.

👍 2