reveal

Docs: https://vlaaad.github.io/reveal/ Source: https://github.com/vlaaad/reveal
onetom 2020-07-24T05:01:05.066600Z

we just realized that you hooked in the javafx web browser to display URIs. it’s a really helpful feature! what sprung to my mind as an easy - but not necessarily great - extension idea is to render hiccup too. it’s probably an overkill to create a browser instance for every hiccup snippet 🙂 i see you are already handling URI/URL and strings matching #"^https?://.+". another idea is to treat <http://clojure.java.io|clojure.java.io>.File s ending with .html as web pages too.

onetom 2020-07-24T05:35:32.069Z

we were wondering how can we use our own functions in the popup which appears when u press space. it seems like the current namespace is clojure.core in that context. is there a way to change it? we tried typing (in-ns 'user) but we just got a another idea is to treat http://clojure.java.io.File` s ending with .html as web pages too.` error

vlaaad 2020-07-24T05:52:08.069200Z

Well, we create views on-demand, so rendering hiccup might make sense.

vlaaad 2020-07-24T05:53:53.069400Z

I think it's a good idea with html files! I wrote to to not forget

vlaaad 2020-07-24T05:56:53.070400Z

no documentation yet since you discovered it a bit before 1.0 release, you can have a look at existing formatters https://github.com/vlaaad/reveal/blob/master/src/vlaaad/reveal/stream.clj starting around line 500.

onetom 2020-07-24T05:57:24.070900Z

im just looking thru the vlaaad.reveal.stream namespace. how can i interactively try out newly defined emit methods?

vlaaad 2020-07-24T05:58:45.071Z

Those are called actions in reveal, you can have a look at usages of vlaaad.reveal.action/def macro for inspiration.

vlaaad 2020-07-24T05:59:55.071200Z

eval-on-selection is unfortunately in clojure.core now, I'm aware of that. Picking a better namespace is on my todo list post 1.0

onetom 2020-07-24T06:01:07.072100Z

if i understand well, there is no way to reference the created ui, because it's just a local binding inside the repl middleware. am i correct? https://github.com/vlaaad/reveal/blob/18e197151374ccdb9863b548f41eb0f6793a60c8/src/vlaaad/reveal/nrepl.clj#L63

onetom 2020-07-24T09:05:38.080300Z

ok, i can confirm that the issue seems to be related to nREPL, because the (defmethod emit ... re-evaluation works, when I just use a clojure.main Cursive Local REPL namespace switching also works when connected via vlaaad.reveal.repl, but has no effect when done via the Cursive Local nREPL

onetom 2020-07-24T09:06:54.080500Z

aside from that, the example I showed above was testing using a java.lang.Long when I was trying to develop the emitter for Double s...

vlaaad 2020-07-24T09:25:49.080700Z

😄

vlaaad 2020-07-24T06:08:36.072300Z

Eval calls to formatters wrapped in stream/just

vlaaad 2020-07-24T06:09:23.072500Z

Ah, you're talking about defined emit methods... Just eval them and they start working

onetom 2020-07-24T06:09:40.072700Z

ah, so sf stands for *s*tream *f*ormatter?

vlaaad 2020-07-24T06:09:53.072900Z

Actually stream function

vlaaad 2020-07-24T06:12:19.073100Z

sort of like rf is reducing funcion and xf is.. transducer

vlaaad 2020-07-24T06:13:15.073300Z

sf-s are closely tied to reducers/transducers

vlaaad 2020-07-24T06:13:48.073500Z

Yes. What's your use case? :)

onetom 2020-07-24T06:17:47.073700Z

i thought i would need access to it if i want to show something, because i saw code like

(defn wrap-print [ui print]
  (fn [x]
    (ui
      (stream/just ...

onetom 2020-07-24T06:20:16.073900Z

but calling (just (something-which-would-implement-emit)) works. however, if i want to overwrite some of the (defmethod emit xxx definitions then i might need to reinitialize some of the namespaces, right? how were you developing those emit methods interactively?

onetom 2020-07-24T06:23:44.074100Z

i know it's a common issue with multimethods and protocols, but i havent used them enough by heart to know who to properly redefine them. for now, i will just extract their implementation into a separate function and call it by its var, to make it possible to modify them at runtime:

(defn emit-double [n]
  (raw-string
    (cond
      (= Double/POSITIVE_INFINITY n) "##Inf"
      (= Double/NEGATIVE_INFINITY n) "##-Inf"
      (Double/isNaN n) "##NaN"
      :else (str n))
    {:fill style/scalar-color}))

(defmethod emit Double [n]
  (#'emit-double))

(comment

  (defn emit-double [n]
    (raw-string
      (str "Double:" n)
      {:fill style/scalar-color}))

  (just (emit-double 123))
  
  )

vlaaad 2020-07-24T06:24:32.074400Z

hmm, I was just re-evaluating calls to defmethod , no need to reload namespaces

onetom 2020-07-24T06:24:55.074600Z

interesting... it doesn't work for me for some reason.

phronmophobic 2020-07-24T06:25:32.074800Z

do you have the jvm option: -Dclojure.compiler.direct-linking=true by chance?

onetom 2020-07-24T06:25:32.075Z

u did this in clojure right? just not thru nREPL but Socket REPL, right? maybe that makes a difference somehow?

vlaaad 2020-07-24T06:25:56.075200Z

you don't need to redefine the multi-method itself (aka dispatch function), you need to redefine a particular method inside that multimethod, which is done just by evaluating

onetom 2020-07-24T06:26:06.075400Z

@smith.adriane not on purpose, no. im just using vanilla CLI setup

vlaaad 2020-07-24T06:26:09.075600Z

it shouldn't matter whether it's done with nrepl or socket repl

onetom 2020-07-24T06:26:28.075800Z

yeah, im just re-evaling the defmethod

vlaaad 2020-07-24T06:26:51.076Z

and it doesn't work?

vlaaad 2020-07-24T06:26:53.076200Z

hmm

onetom 2020-07-24T06:29:01.076400Z

i just double-checked it and it does NOT work for me

onetom 2020-07-24T06:29:37.076800Z

i guess i will try it thru socket repl then. i don't have a lot of experience with that though, so it might take awhile

phronmophobic 2020-07-24T06:31:14.077Z

I've only seen that behavior with direct linking. might be worth checking: (System/getProperty "clojure.compiler.direct-linking")

onetom 2020-07-24T06:31:24.077200Z

btw, would it be hard to print those lines with the ^{:clojure.core/eval-file on their own line or rather its own, vertical block, so we can see what's been evaled? that would help to see it easier what's been evaluated

onetom 2020-07-24T06:32:20.077400Z

@smith.adriane it prints nil but thanks for showing how to check it!

1👍
onetom 2020-07-24T06:33:18.077700Z

i just read about it again a few days ago in the official clojure faq, iirc, and remember it's possible to disable direct linking on a per-ns basis, by providing some metadata on the ns itself

vlaaad 2020-07-24T06:37:18.077900Z

I just tried it with nrepl and it worked :thinking_face:

vlaaad 2020-07-24T06:37:23.078100Z

^{:clojure.core/eval-file "C:/Users/Vlaaad/Projects/reveal/src/vlaaad/reveal/stream.clj" :line 551 :column 1} (defmethod emit Double [n]
  (raw-string
    (cond
      (= Double/POSITIVE_INFINITY n) "##Inf"
      (= Double/NEGATIVE_INFINITY n) "##-Inf"
      (Double/isNaN n) "##NaN"
      :else (str "Double:" n))
    {:fill style/scalar-color}))
=&gt; #reveal/multi-fn[emit 0x37ff0d64]
1.5
=&gt; Double:1.5

onetom 2020-07-24T06:38:17.078300Z

im on org.clojure/clojure {:mvn/version "1.10.2-alpha1"} that might be an issue

vlaaad 2020-07-24T06:38:31.078500Z

went to stream ns, re-evaluated emitter for Double and then evaluated 1.5

onetom 2020-07-24T06:39:18.078700Z

and i also upgraded javafx as you recommended the other night.

cljfx                                      {:mvn/version "1.7.4"}

           org.openjfx/javafx-controls                {:mvn/version "15-ea+7"}
           org.openjfx/javafx-base                    {:mvn/version "15-ea+7"}
           org.openjfx/javafx-graphics                {:mvn/version "15-ea+7"}
           org.openjfx/javafx-media                   {:mvn/version "15-ea+7"}
           org.openjfx/javafx-web                     {:mvn/version "15-ea+7"}

onetom 2020-07-24T06:42:10.078900Z

are you doing this from Cursive? can we have a quick https://screen.so/ screen sharing session over this?

vlaaad 2020-07-24T06:44:09.079200Z

yes, from cursive

vlaaad 2020-07-24T06:44:24.079400Z

sorry, work starts in 15 minutes, no time for debugging right now

onetom 2020-07-24T06:44:42.079600Z

ok, thx

onetom 2020-07-24T06:45:00.079800Z

for me, this IS the work for today ;D

onetom 2020-07-24T06:47:43.080100Z

that indirection using vars works for me still, so im not stuck

onetom 2020-07-24T09:05:38.080300Z

ok, i can confirm that the issue seems to be related to nREPL, because the (defmethod emit ... re-evaluation works, when I just use a clojure.main Cursive Local REPL namespace switching also works when connected via vlaaad.reveal.repl, but has no effect when done via the Cursive Local nREPL

onetom 2020-07-24T09:06:54.080500Z

aside from that, the example I showed above was testing using a java.lang.Long when I was trying to develop the emitter for Double s...

vlaaad 2020-07-24T09:25:49.080700Z

😄

onetom 2020-07-24T09:46:37.082800Z

I'm trying to change the background color of an expression like this:

(defmethod emit lambdaisland.deep_diff.diff.Insertion [diff]
    (prn diff)
    (horizontal
      (raw-string "+" {:style-class "reveal-ddiff-insertion"})
      (emit (:+ diff))))
and i've added this to the top of the reveal.style ns:
(def style
  (css/register ::main
    {".reveal"
       {"-ddiff" {"-insertion" {:-fx-background-color "#0F0"}}
the result is just a back + on the standard background. what am i missing? is there something which overrides my styling?

vlaaad 2020-07-24T10:07:18.083100Z

emitting does not use CSS at all

vlaaad 2020-07-24T10:08:19.083300Z

output panels use custom rendering for performance

vlaaad 2020-07-24T10:09:34.083800Z

current implementation can only do text fill

onetom 2020-07-24T12:11:51.084600Z

indicating differences in the return value of a deep diff operation:

(let [inserted-color "#0F04"
        deletion-color "#F004"]
    (defmethod emit lambdaisland.deep_diff.diff.Insertion [diff]
      (horizontal
        (raw-string "+" {:bg inserted-color})
        (emit (:+ diff))))

    (defmethod emit lambdaisland.deep_diff.diff.Deletion [diff]
      (horizontal
        (raw-string "-" {:bg deletion-color})
        (emit (:- diff))))

    (defmethod emit lambdaisland.deep_diff.diff.Mismatch [diff]
      (horizontal
        (raw-string "-" {:bg deletion-color})
        (emit (:- diff))
        (raw-string " ")
        (raw-string "+" {:bg inserted-color})
        (emit (:+ diff))))

    (let [d (ddiff/diff {:removed 123
                         :common "data"
                         :changed "value"}
                        {:common "data"
                         :added 456
                         :changed "new value"})]
      (just (emit d))))

onetom 2020-07-24T12:12:21.085500Z

i just changed the guts of the reveal.layout/draw like this:

(dotimes [i drawn-line-count]
      (transduce
        (mapcat :segments)
        (completing
          (fn [x {:keys [text width style]}]
            (if (&lt; x canvas-width)
              (let [end (+ x width)
                    y (-&gt; (* i font/line-height)
                          (+ font/ascent)
                          (- scroll-y-remainder))]
                (if (&lt;= end 0)
                  end
                  (do
                    (when-let [bg-color (:bg style)]
                      (doto ctx
                        (.setFill (fx.coerce/color bg-color))
                        (.fillRect x (- y font/ascent)
                                   width font/line-height)))

                    (.setFill ctx (fx.coerce/color
                                    (if-let [fill (:fill style)]
                                      (get style/style fill fill)
                                      "#000")))
                    (.setFont ctx font/font)
                    (.fillText ctx text x y)
                    end)))
              (reduced nil))))
        scroll-x
        (lines (+ i dropped-line-count))))

onetom 2020-07-24T12:15:15.088100Z

i wanted to color the whole background of the changed data, but the current rendering algo is not very amenable to such a change. at the end this style might even be better, because at least i don't have to worry about many color combinations... a thick underline with the current color would be a nice alternative, but again, im not sure what's the best way to apply such styling to nested elements.

vlaaad 2020-07-24T12:18:07.088300Z

this is wonderful!

vlaaad 2020-07-24T12:22:00.089500Z

I experimented with overriding child rendering — it’s possible, though requires getting into the guts of sf/rf/xf use

vlaaad 2020-07-24T12:24:02.091300Z

What I don’t like about overriding colors is that it gets harder to navigate the data structure. But I think using background as a sort of non-intrusive accent is a fine approach. I’ll experiment with it.

vlaaad 2020-07-24T12:25:28.092Z

it will also require making sure those backgrounds play nice with selection

onetom 2020-07-24T12:54:03.093600Z

well, my whole "light theme" doesn't really play nice with most of the other colors, but it just doesn't worth the effort now. there are a lot of more useful things we can try to implement first. also, i like the low feature set, because it's easier to hack on it...

onetom 2020-07-24T13:41:32.096700Z

@vlaaad, r u using cursive's built-in code formatting or something else? because im just using the cursive deafults and when i reformat your sources it changes it a lot. the primary difference i can notice is that the Align map values is turned on for me. then the block, as and when-class are also indented like regular functions for me, but in your case they just use 2 space indentation.

onetom 2020-07-24T13:42:26.097500Z

we should turn on logging for this channel. do u know how to do that? have to add some bot... but i never done it.

vlaaad 2020-07-24T13:42:53.097900Z

Align maps is a setting I turned off in Cursive (Editor -> Code Style -> Clojure -> General -> Align Map Value)

vlaaad 2020-07-24T13:43:40.099300Z

for some things like block, as etc I added custom indentation because I find it more readable.

onetom 2020-07-24T13:44:04.100100Z

maybe u should commit your .idea directory until there is any other means for formatting the code. it could make it slightly easier to contribute.

onetom 2020-07-24T13:44:59.100600Z

@logbot start logging please!

vlaaad 2020-07-24T13:46:14.101800Z

I think @seancorfield is admin here, he should know how to preserve channels. Sean, can you make this channel preserve history?

onetom 2020-07-24T13:46:20.102Z

we should see messages archives popping up here from now on: https://clojurians-log.clojureverse.org/reveal

onetom 2020-07-24T13:46:45.102400Z

according to the about page i only need to invite the logbot here and that's it

vlaaad 2020-07-24T13:47:14.103Z

oh, I shouldn’t have bothered Sean than 😅

onetom 2020-07-24T13:49:32.103900Z

well, maybe he knows some more modern way to do it 🙂 i never tried this before, just heard about it on #clojure-hungary

vlaaad 2020-07-24T13:55:46.104Z

I prefer keeping repos free from IDE/editor specific data so everyone can have whatever setup they want without interfering with checked in dirs.

onetom 2020-07-24T14:17:33.104200Z

i know and i agree in general, except currently that's the easiest way to encode your formatting rules. until a more common formatting solution has been intergrated across the major editor integrations, it think it's a worthwhile compromise. u can also share run configs for the various repl integrations via the .idea/ dir, so at least the intellij users can get started hacking on reveal conveniently.

seancorfield 2020-07-24T16:07:21.106100Z

And you already have @zulip-mirror-bot here to log to the slack-archive stream there

seancorfield 2020-07-24T16:07:37.106700Z

Ah. You do now!

2❤️