Fork me on GitHub
#planck
<
2016-08-17
>
timgilbert20:08:26

Say, I see planck uses fipp for printing stuff out. Is there any way I can include it in my own planck script? Trying to come up with a fast EDN pretty-printer

timgilbert20:08:52

(I tried a simple (require) but no dice)

mfikes20:08:58

Hrm… you are perhaps trying fipp.edn? Planck doesn’t bundle that particular namespace

timgilbert20:08:21

Aha, that's what I was trying

mfikes20:08:15

If you are just trying to pretty-print like Planck does, perhaps planck.pprint.data which uses FIPP might get you what you want. (It is an internal namespace, but it could at least let you see if it leads to something.)

timgilbert20:08:16

I suppose I could just (eval) the data and print it from planck, it's from trusted sources

timgilbert20:08:34

Ok, cool, I will give that a try, thanks

mfikes20:08:27

@timgilbert: Yeah, if you just want to read in some stuff to print nicely in the planck terminal you can, for example:

(cljs.tools.reader/read-string ":a”)

mfikes20:08:03

You could combine that with slurp:

(-> (planck.core/slurp "foo.edn")
  cljs.tools.reader/read-string)

mfikes21:08:29

@timgilbert: If you just want to pretty-print stdin using Planck, try this:

$ echo "[1 2 3]" | planck -e"(require 'planck.pprint.data 'planck.themes 'cljs.tools.reader 'planck.core)" -e'(-> (planck.core/slurp planck.core/*in*) cljs.tools.reader/read-string (planck.pprint.data/pprint {:width 70 :theme (planck.themes/get-theme :light)}))'

mfikes21:08:30

(You need to use Planck 1.16 for the above to work.)

timgilbert21:08:12

My script version of that is:

#! /usr/bin/env planck
(ns edn.pprint
  (:require [planck.pprint.data :as d]
            [planck.themes :as themes]
            [cljs.tools.reader :as reader]
            [planck.core :as core]))

(-> (core/slurp core/*in*)
    reader/read-string
    (d/pprint {:width 70 :theme (themes/get-theme "light")}))

timgilbert21:08:03

Will probably elaborate on it from there

mfikes21:08:26

@timgilbert: I'll add a ticket to Planck to bundle all of the Fipp namespaces. Also, if Planck's color syntax highlighting proves to be useful outside of the REPL, it could be surfaced in namespaces intended for public consumption.

timgilbert21:08:58

That would be cool

timgilbert21:08:32

I actually don't seem to be able to get the syntax highlighting to work in the above script, though it does at the repl, will look into it later

timgilbert21:08:04

Oh, duh - I used "light" instead of :light