Last active
February 27, 2026 22:44
-
-
Save ptaoussanis/f8a80f85d3e0f89b307a470ce6e044b5 to your computer and use it in GitHub Desktop.
Example of using Telemere with Bling (rich text console printing lib for Clj/s+)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Example created: 2024-12-23 | |
| ;; Last updated: 2025-03-11 by @paintparty | |
| ;; Dependencies: | |
| ;; Telemere - Ref. https://github.com/taoensso/telemere v1.0.0-RC5 (2025-03-10) | |
| ;; Bling - Ref. https://github.com/paintparty/bling v0.5.2 (2025-03-11) | |
| ;; Platform: Clj only for now (haven't tried yet with Cljs) | |
| ;; Improvements very welcome! | |
| ;; Original context: https://github.com/taoensso/telemere/issues/33 | |
| (require '[taoensso.telemere :as tel]) | |
| (require '[taoensso.telemere.utils :as tel-utils]) | |
| (require '[bling.core :as bling]) | |
| (defn- signal->callout-opts | |
| "Returns {:keys [type label data?]} for use with `bling/callout`, etc." | |
| [{:keys [level]}] | |
| (let [label (tel-utils/format-level level) | |
| type | |
| (case level | |
| (:report :info) :info | |
| (:fatal :error) :error | |
| (:warn) :warning | |
| (do nil)) | |
| colorway | |
| (case level | |
| (:trace :debug) :subtle | |
| (do :neutral))] | |
| {:type type, | |
| :colorway colorway | |
| :label label, | |
| :data? true, | |
| :margin-top 0, | |
| :margin-bottom 1})) | |
| (tel/add-handler! :my-bling-handler | |
| (let [;; Set your preferred formatting options below as usual: | |
| format-signal-fn (tel/format-signal-fn {:incl-newline? false}) | |
| my-output-fn | |
| (fn [signal] | |
| (let [norm-output (format-signal-fn signal)] ; Normal Telemere output | |
| (bling.core/callout ; Add Bling "callout" formatting | |
| (signal->callout-opts signal) | |
| norm-output)))] | |
| (tel/handler:console {:output-fn my-output-fn}))) |
Thanks yourself Jeremiah for a very useful (and fun) library
Re. colour translation choices --they're entirely my fault. Had spent some of the afternoon writing an indexed-db handler for telemere, which reminded me that I'd stolen this gist ages ago but not used it because it wasn't compatible with the cljs-devtools formatters. Did this quickly for fun before shuttting down -- first asked claude to format the log preamble using 'appropriate colors -- e.g. red for error, orange for warning'. Its initial choice for :info was green -- so then asked it to use blue instead, then to use a darker blue -- and here we are :) I'lll certainly use the semantic aliases you've provided going forward.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cormacc very cool, thank you for sharing!
I would recommend this change, as Bling has built-in semantic aliases precisely for use cases like this:
I haven't tested the above on my end, but lmk if it doesn't do what you expect.
Also curious to know if claude made the color translation choices in the above
caselogic? Because if so, I should consider augmenting the docs to better steer LLMs. In particular, the choice of:dark-blueseems like a bit hallucinatory. I don't think any of the*-darkor*-lightvariants of the colors have been publicly documented yet. They were added recently in order for bling to use internally, to provide better contrast, but only if the user has aBLING_MOODenv var set. Otherwise, they shouldn't be used to color text as they could potentially render something with very poor contrast, which kind of goes against the whole design of Bling's color pallette approach. For example,:dark-bluewould work fine if the user has a light-themed terminal, but very poorly if the user has a dark-themed terminal.