planck

Planck ClojureScript REPL
timgilbert 2016-08-17T20:42:26.000337Z

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

mfikes 2016-08-17T20:42:45.000338Z

yeah

timgilbert 2016-08-17T20:42:52.000339Z

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

mfikes 2016-08-17T20:45:58.000341Z

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

timgilbert 2016-08-17T20:46:21.000342Z

Aha, that's what I was trying

mfikes 2016-08-17T20:47:15.000343Z

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.)

timgilbert 2016-08-17T20:47:16.000344Z

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

timgilbert 2016-08-17T20:47:34.000345Z

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

mfikes 2016-08-17T20:53:27.000346Z

@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”)

mfikes 2016-08-17T20:55:03.000347Z

You could combine that with slurp:

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

mfikes 2016-08-17T21:07:29.000348Z

@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)}))'

mfikes 2016-08-17T21:11:30.000349Z

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

timgilbert 2016-08-17T21:11:57.000350Z

Awesome, thanks @mfikes

timgilbert 2016-08-17T21:19:12.000351Z

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")}))

timgilbert 2016-08-17T21:20:03.000352Z

Will probably elaborate on it from there

mfikes 2016-08-17T21:23:26.000353Z

@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.

timgilbert 2016-08-17T21:42:58.000354Z

That would be cool

timgilbert 2016-08-17T21:43:32.000355Z

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

timgilbert 2016-08-17T21:44:04.000356Z

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