A simple terminal based data inspector for clojure.
(The project is in early development so it may be quite buggy and unstable)
Run the data viewer in a terminal using the com.msladecek.inspector/-main
function, it may be useful to create an :inspector
alias first.
;; deps.edn
{:aliases {:inspector
{:extra-deps {com.msladecek/inspector {:git/url "https://github.com/msladecek/inspector-tui"
:git/sha "<put a commit sha here>"}}
:main-opts ["-m" "com.msladecek.inspector"]}}}
Then start the viewer:
clojure -M:inspector
Once the viewer starts, your terminal will look like this:
view -/0
no view selected
The basic viewer will display lists of maps using clojure.pprint/print-table
and everything else using clojure.pprint/pprint
, for example:
[:one 2 "three"]
shows up as:
view 1/1
[:one 2 "three"]
whereas
[{:id :one :color "red"}
{:id 2 :color "blue" :flavor "sour"}
{:id "three" :flavor "sweet"}]
shows up as:
view 2/2
| :color | :flavor | :id |
|--------+---------+-------|
| red | | :one |
| blue | sour | 2 |
| | sweet | three |
For a full list of viewer options, see the usage help message:
clojure -M:inspector --help
tap>
(require '[com.msladecek/inspector :as inspector])
(add-tap inspector/send-data!)
(tap> {:hello "world" :message "I submitted this using tap>"})
In the viewer you should see:
view 1/1
{:hello "world" :message "I submitted this using tap>"}
The inspector can hook into nrepl's print
function and submits whatever data it receives.
Add the nrepl middleware:
;; deps.edn
{:aliases :nrepl+inspector
{:extra-deps {nrepl/nrepl {:mvn/version "1.4.0"}
cider/cider-nrepl {:mvn/version "0.57.0"}
com.msladecek/inspector {:git/url "https://github.com/msladecek/inspector-tui"
:git/sha "<put a commit sha here>"}}
:main-opts ["-m" "nrepl.cmdline"
"--middleware" "[cider.nrepl/cider-middleware com.msladecek.inspector.nrepl/middleware]"]}}
Start nrepl using the new alias:
clojure -M:nrepl+inspector
Connect to the nrepl from your editor and evaluate some expressions, in the viewer you should see the results:
view 2/2
{:bonjour "le monde" :message "I evaluated this using nrepl"}
With H, and L keys you can go back and forth through the history of previosly submitted data. Whenever a new value is submitted to the viewer, it automatically goes to the end of the history and the active view is moved to it.
Inspired by the inspector tool that ships with cider
(emacs plugin).
I wanted a basic, editor-agnostic tool which replicates some of its functionality.
Other (more featureful) data viewer tools exist:
clojure.inspector
graphical inspector distributed along with clojureFeel free to open an issue or submit a pull request if you're aware of others.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |