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.
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
Well, we create views on-demand, so rendering hiccup might make sense.
I think it's a good idea with html files! I wrote to to not forget
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.
im just looking thru the vlaaad.reveal.stream
namespace.
how can i interactively try out newly defined emit
methods?
Those are called actions in reveal, you can have a look at usages of vlaaad.reveal.action/def
macro for inspiration.
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
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
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
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...
😄
Eval calls to formatters wrapped in stream/just
Ah, you're talking about defined emit methods... Just eval them and they start working
ah, so sf
stands for *s*tream *f*ormatter?
Actually stream function
sort of like rf is reducing funcion and xf is.. transducer
sf
-s are closely tied to reducers/transducers
Yes. What's your use case? :)
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 ...
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?
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))
)
hmm, I was just re-evaluating calls to defmethod
, no need to reload namespaces
interesting... it doesn't work for me for some reason.
do you have the jvm option: -Dclojure.compiler.direct-linking=true
by chance?
u did this in clojure right? just not thru nREPL but Socket REPL, right? maybe that makes a difference somehow?
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
@smith.adriane not on purpose, no. im just using vanilla CLI setup
it shouldn't matter whether it's done with nrepl or socket repl
yeah, im just re-evaling the defmethod
and it doesn't work?
hmm
i just double-checked it and it does NOT work for me
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
I've only seen that behavior with direct linking. might be worth checking: (System/getProperty "clojure.compiler.direct-linking")
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
@smith.adriane it prints nil
but thanks for showing how to check it!
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
I just tried it with nrepl and it worked :thinking_face:
^{: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}))
=> #reveal/multi-fn[emit 0x37ff0d64]
1.5
=> Double:1.5
im on org.clojure/clojure {:mvn/version "1.10.2-alpha1"}
that might be an issue
went to stream ns, re-evaluated emitter for Double and then evaluated 1.5
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"}
are you doing this from Cursive? can we have a quick https://screen.so/ screen sharing session over this?
yes, from cursive
sorry, work starts in 15 minutes, no time for debugging right now
ok, thx
for me, this IS the work for today ;D
that indirection using vars works for me still, so im not stuck
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?emitting does not use CSS at all
output panels use custom rendering for performance
https://github.com/vlaaad/reveal/blob/master/src/vlaaad/reveal/layout.clj#L310-L318
current implementation can only do text fill
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))))
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 (< x canvas-width)
(let [end (+ x width)
y (-> (* i font/line-height)
(+ font/ascent)
(- scroll-y-remainder))]
(if (<= 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))))
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.
this is wonderful!
I experimented with overriding child rendering — it’s possible, though requires getting into the guts of sf/rf/xf use
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.
it will also require making sure those backgrounds play nice with selection
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...
@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.
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.
Align maps is a setting I turned off in Cursive (Editor -> Code Style -> Clojure -> General -> Align Map Value)
for some things like block
, as
etc I added custom indentation because I find it more readable.
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.
@logbot start logging please!
I think @seancorfield is admin here, he should know how to preserve channels. Sean, can you make this channel preserve history?
we should see messages archives popping up here from now on: https://clojurians-log.clojureverse.org/reveal
according to the about page i only need to invite the logbot here and that's it
oh, I shouldn’t have bothered Sean than 😅
well, maybe he knows some more modern way to do it 🙂 i never tried this before, just heard about it on #clojure-hungary
I prefer keeping repos free from IDE/editor specific data so everyone can have whatever setup they want without interfering with checked in dirs.
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.
And you already have @zulip-mirror-bot here to log to the slack-archive stream there
Ah. You do now!