vlaaad / reveal

Read Eval Visualize Loop for Clojure

Home Page:https://vlaaad.github.io/reveal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't configure vlaaad.reveal.prefs from project.clj

rbeesley opened this issue · comments

I've been trying to use the following to set JAVA OPTS from a project.clj:

:profiles {:reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
                      :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs='{:font-family \"Consolas\" :font-size 15}'"]}}

It seems as though there is no way to escape the vlaaad.reveal.prefs properties in project.clj so that it can be read by Reveal. If you don't try to escape the double quotes using a backslash, then it would be parsed in the project.clj as closing the JAVA_OPTS. Using the escape seems to think it's already terminated as the error generated is that the "Consolas" class can't be loaded. I even tried to remove the :font-family so that it is just the :font-size and that wasn't parsed either.

Hi! Would be nice to see the exception during parsing, but I have a couple of thoughts nonetheless:

  1. ''-quoting is a shell thing, I don't think it's needed for JVM opts in the tooling like leiningen, so it should be something like "-Dvlaaad.reveal.prefs={:font-family \"Consolas\" :font-size 15}";
  2. Some tools like splitting args on spaces, if option 1 doesn't help, you can try replacing spaces with commas (they are whitespace in clojure): "-Dvlaaad.reveal.prefs={:font-family,\"Consolas\",:font-size,15}".

Does it help?

I was trying to figure out more myself. After your comment about quoting, this works:

  :profiles {:uberjar {:aot :all}
             :reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
                      :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32}"]}}

This does not:

  :profiles {:uberjar {:aot :all}
             :reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
                      :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \"Consolas\"}"]}}
Failed to read reveal prefs
Execution error - invalid arguments to vlaaad.reveal.prefs/fn at (prefs.clj:38).
Consolas - failed: string? at: [:font-family :url-string] spec: :vlaaad.reveal.prefs/font-family
Consolas - failed: system-font? at: [:font-family :system-font] spec: :vlaaad.reveal.prefs/font-family

This really does not:

  :profiles {:uberjar {:aot :all}
             :reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
                      :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \"Courier New\"}"]}}
Error: Could not find or load main class New}
Caused by: java.lang.ClassNotFoundException: New}

Just getting the font size to change is a step in the right direction. It did not seem as though I needed to use a comma for whitespace as ":font-size 32" was read correctly. It is a problem in the ":font-family," but based on the error it seems like maybe it isn't being quoted still.

I just tried your last example on a test project and it worked:

(defproject com.example/reveal "1.0.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.10.1"]]
  :profiles {:reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :jvm-opts ["-Dvlaaad.reveal.prefs={:font-size 32 :font-family \"Courier New\"}"]}})

Then started REPL with this:

lein with-profile +reveal run -m vlaaad.reveal/repl

This was done on a mac... What OS do you use?

Consolas - failed: string? — very interesting! My guess is something eats quotes and leaves it a symbol. Maybe adding escaped backslashes to this escaping madness will help? e.g. \\\"Consolas\\\"...

I would suggest starting JVM with JVM opt that triggers this error ("-Dvlaaad.reveal.prefs={:font-size 32 :font-family \"Consolas\"}") and looking at what's in the props by evaluating (System/getProperty "vlaaad.reveal.prefs")

I'm on Windows trying to start through Calva on VS Code. I haven't been working on it for a couple of days, but I'll try some more things and let you know if I see any changes. I tried escaping the quotes as you did, but that seemed to be causing more problems with parsing. Getting it to recognize a change in the font-size was a big step forward.

This worked:

  :profiles {:reveal {:dependencies [[vlaaad/reveal "1.2.184"]]
                      :repl-options {:nrepl-middleware [vlaaad.reveal.nrepl/middleware]}
                      ;; :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32}"] ;; Works
                      :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \\\"Consolas\\\"}"] ;; Works
                      ;; :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \\\"Courier New\\\"}"] ;; Works
                      ;; :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \\\"Cascadia Code\\\"}"] ;; Doesn't work with user font installation
                      ;; :jvm-opts ["-Dfile.encoding=UTF8" "-Dvlaaad.reveal.prefs={:font-size 32 :font-family \\\"Cascadia Mono\\\"}"] ;; Doesn't work with user font installation
  }}

This is the result when I have it working.

(System/getProperty "vlaaad.reveal.prefs")
=> "{:font-family \"Cascadia Mono PL\"}"

Ultimately I was trying to get Cascadia Code to work, to match the rest of my development environment. So when it failed I started trying to find the issue blocking. I get font-size to work, so I knew I could populate the vlaaad.reveal.prefs. With your suggestions I got escaping the quotes to work with Consolas. I figured the issue might be with the spaces, but I was able to get Courier New to work as well. Cascadia Code and Cascadia Mono are both True Type fonts, but they weren't showing. I opened NexusFont and I didn't see the fonts listed there although I certainly had been using them.

I realized that Cascadia * fonts had been installed to my user and not to the system. After installing them to all users, so that it was more than just my account, I was able to get them to show in NexusFont and I was able to get them to "load" in vlaaad.reveal.prefs.

Unfortunately it doesn't actually display correctly:

image

I was able to use Consolas to see Unicode sent to Reveal, so this seems to be something specific to font but I don't see what that issue may be.

UPDATE: The font rendering problem was because I ended up installing the font both in System and User space, and this is a known issue that can cause the font to render incorrectly.

I think at this point this specific issue should become a documentation issue, both that on Windows 10, fonts must be installed for all users and not just the user, and secondly how parameters may need to be escaped in project.clj. Finally there should be another defect perhaps at lower priority to investigate why the Cascadia Code font isn't working when installed.

Thanks for the follow-up, and I'm glad you got it working! I think I should provide a way to configure Reveal preferences without having to deal with escaping, perhaps by allowing prefs to be a path to a file containing preferences as edn... I'll think about it.