This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-30
Channels
- # announcements (2)
- # babashka (37)
- # beginners (64)
- # biff (27)
- # cherry (7)
- # cider (19)
- # clj-kondo (10)
- # clojure-austin (4)
- # clojure-doc (18)
- # clojure-europe (72)
- # clojure-nl (1)
- # clojure-norway (13)
- # clojure-uk (5)
- # clojurescript (18)
- # data-science (28)
- # events (5)
- # graalvm (32)
- # hyperfiddle (6)
- # introduce-yourself (1)
- # jobs (4)
- # joyride (16)
- # juxt (6)
- # malli (7)
- # missionary (3)
- # off-topic (18)
- # pathom (15)
- # portal (14)
- # re-frame (14)
- # reitit (5)
- # releases (1)
- # rum (2)
- # sci (1)
- # shadow-cljs (102)
- # spacemacs (3)
- # sql (6)
- # web-security (2)
- # xtdb (10)
I was working on a clojure project that I wanted to use terminal colors on. The cider REPL currently uses ansi-color-apply
from ansi-color.el
to process output and interpret terminal color sequences. Unfortunately, that package only interprets the most basic color sequences and is very limiting. I did some digging and found xterm-color (https://github.com/atomontage/xterm-color) which supports 256 color and truecolor modes. (what any modern terminal supports) It was a pretty easy drop in replacement:
(add-hook 'cider-repl-preoutput-hook 'xterm-color-filter)
`
Is anyone else using this? Are there any drawbacks? Maybe cider should consider moving to this or adding it to the docs for people to consider using?
Here's a quick example of some colorful output in the cider repl;; based on awk script from -
(defn colors-demo
([]
(colors-demo 77 "/\\"))
([width input-text]
(doseq [[n c] (map-indexed vector (take width (cycle input-text)))
:let [r (int (- 255 (* 255 (/ n width))))
b (int (* 255 (/ n width)))
g (if (>= b 128)
(- 510 (* 2 b))
(* 2 b))]]
(print (format "\033[48;2;%d;%d;%dm" r g b))
(print (format "\033[38;2;%d;%d;%dm" (- 255 r) (- 255 g) (- 255 b)))
(print (format "%s\033[0m" c)))
(println)))
Nice find! > (what any modern terminal supports) I recall having to add some magical incantation for truecolor to work in my iTerm. Which is to say, it doesn't seem safe to assume everyone has their terminal ready for an upgrade. However it would indeed sounds like a good addition to https://docs.cider.mx/cider/additional_packages.html#generic-emacs-extensions , for instance
I'm going to give it a couple days of testing in daily usage to see if it messes up anything. Assuming it's suitable, I'll at least submit a docs PR for it. Thanks

Is there an easy way to keep the existing ansi color hook out of the list? If this hook processes the color sequences, ansi-color-apply would be redundant. I can't think of how this would be an issue, but it feels look double escaping/unescaping data.
Sure,
(setq cider-repl-preoutput-hook (remove #'cider-repl--ansi-color-apply cider-repl-preoutput-hook))
would do itJust encountered this issue when Malli was throwing pretty-printed errors. With regular ansi-codes, the output looked like pic, but with xterm-color, and running xterm-color-colorize-buffer
it looked as expected.
Is there a way to completely replace ansi-color
with xterm-color
? If not, is there a similar hook I can set to get it working automatically when the *cider-error*
buffer is opened?
If you don't get an answer from norman feel free to raise an issue in CIDER (it also can save you time to check if Malli offers an option controlling colors - it's pretty common)
There is indeed, playing around with it now. I guess I should do a PR to Malli when I figure this out, at least to the docs.
I did forget to come back and submit a PR. I'll try and get on that - it's been working great. I don't know if the error-buffer uses the same ansi function, but it if it does, it should handle these 256 color ansi sequences just fine.
Hi,
I have a project that sets (cider-clojure-cli-global-options . "-J--add-opens=java.base/java.nio=ALL-UNNAMED -J--add-opens=java.base/sun.nio.ch=ALL-UNNAMED")
in .dir-locals.el.
I get the warning: "cider-clojure-cli-global-options is obsolete (since 1.8.0); use ‘cider-clojure-cli-parameters’ instead"
But putting the options into cider-clojure-cli-parameters does not work. The only difference I see is the order in which these options get passed to clojure.
Maybe the -J options need to be before -M:aliases:cider/nrepl and can not be used after -M:aliases:cider/nrepl?
I'll look into it rn. However, just a quick sanity check - would it not be more idiomatic to add those options within an alias in deps.edn, and activate said alias via CIDER? (which as a setting for the Clojure CLI aliases)
Give you agree it's nicer I'll investigate it later today. If you still feel there's a strong use case, feel free to create an issue - otherwise we'd enjoy leading users into simpler patterns
The only use case I can think of is when someone wanted to keep it out of deps.edn to give different developers the option to have different .dir-locals.el files. In my case your suggestion is superior.
Yeah, normally having an alias named e.g. :nio-opens
would not bother the rest of the team. Most often than not it's a nice way to document how-tos.