nREPL middleware to pretty-print colored values
Clojure
Latest commit e5b9a85 Nov 4, 2015 @greglook Add demo gif.
Permalink
Failed to load latest commit information.
src Allow tag-types keys to be classes or symbols. Nov 4, 2015
.gitignore Initial copy of nrepl middleware. May 9, 2014
CHANGELOG.md
HISTORY.md Separate the history from the README. Oct 14, 2014
README.md Add demo gif. Nov 5, 2015
UNLICENSE Rename project 'whidbey' and add docs and unlicense. May 9, 2014
demo.gif Add demo gif. Nov 5, 2015
project.clj Set release version 1.3.0. Nov 4, 2015

README.md

whidbey

Dependency Status Join the chat at https://gitter.im/greglook/whidbey

This is a plugin for Leiningen which changes the REPL to pretty-print results with Puget.

repl demo

Internally, Whidbey reaches into nREPL to replace the default pr-values rendering middleware. See the history for more on the motivations and implementation details behind this project.

Usage

To use Whidbey, add it to the :plugins vector in your user or system profile. Note that this requires Leiningen version 2.5.1 or higher for profile and plugin functionality.

Clojars Project

Configuration

Whidbey passes rendering options into Puget from the :whidbey key in the profile map:

:whidbey {:width 180
          :map-delimiter ""
          :extend-notation true
          :print-meta true
          :color-scheme {:delimiter [:blue]
                         :tag [:bold :red]
                         ...}
          ...}

See the puget.printer namespace for the available configuration.

Additionally, Whidbey adds some convenience tagged-literal extensions for binary data and URIs. The extensions update the default-data-readers var to support round-tripping the tagged representations:

=> (java.net.URI. "http://github.com/greglook")
#whidbey/uri "http://github.com/greglook"

=> (.getBytes "foo bar baz")
#whidbey/bin "Zm9vIGJhciBiYXo="

=> #whidbey/bin "b25lIG1vcmUgdGltZSwgbXVzaWNzIGdvdCBtZSBmZWVsaW5nIHNvIGZyZWU="
#whidbey/bin "b25lIG1vcmUgdGltZSwgbXVzaWNzIGdvdCBtZSBmZWVsaW5nIHNvIGZyZWU="

This is controlled by the :extend-notation option. Other type extensions can be added by providing a :tag-types map. This should map type symbols to a map with a tag symbol key pointing to a formatting function. When the type is encountered, it will be rendered as a tagged literal with a form from calling the formatter on the value.

For example, to render class values as tagged types, you can add this to your :whidbey config:

:tag-types {java.lang.Class {'class #(symbol (.getName %))}}}

If the type name or the formatter function are not available at load time, you can quote them to suppress evaluation until those types are printed.

Troubleshooting

Sometimes, there are types which Puget has trouble rendering. These can be excluded from pretty-printing by adding their symbol to the :escape-types set in the options. These types will be rendered with the normal Clojure printer. If you want to use these types' print-method instead, set the :print-fallback option to :print:

:whidbey {:print-fallback :print
          :escape-types #{'datomic.db.Db 'datomic.btset.BTSet ...}
          ...}

Whidbey may also conflict with other REPL customizations. If you experience errors, you can check how the profiles are being merged using the lein-pprint or lein-cprint plugins:

$ lein with-profile +whidbey/repl cprint :repl-options

License

This is free and unencumbered software released into the public domain. See the UNLICENSE file for more information.