Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add syntax coloring #19

Closed
arichiardi opened this issue Oct 22, 2015 · 30 comments
Closed

Add syntax coloring #19

arichiardi opened this issue Oct 22, 2015 · 30 comments
Assignees

Comments

@arichiardi
Copy link
Contributor

We can add syntax coloring easily (hopefully), using for instance highlight.js or better its cljsjs package.

@arichiardi
Copy link
Contributor Author

@tomasz-biernacki if you want you can work on this, toghther with a lil' improvement of the UI graphics...for instance I would love to make it a bit smaller (padding)

@arichiardi
Copy link
Contributor Author

Another idea is to use the simpler (and cljs only) puget

because jqconsole supports ANSI: https://github.com/replit/jq-console#ansi-escape-code-sgr-support

@arichiardi
Copy link
Contributor Author

This one is not easy, and after talking and sharing ideas, @tomasz-biernacki made a very good point: we need to somehow hook info the prompt (I opened an issue on jqconsole and either write ANSI or inject our own <pre><code> ....

Postponed for now.

@piecyk
Copy link
Contributor

piecyk commented Oct 28, 2015

just to be on the same page we want to have color syntax while input to repl ? and while returning form it ? @arichiardi is right we can hack the jqconsole and alter the dom... i'm building reagent console when some free time i have this will be very easy but this is a song from future 🎅

image

@arichiardi
Copy link
Contributor Author

Yes on .Write is easier with puget library, as jq-console supports ansi.
The problem is exactly the coloring during the input. We need a mix of event and injecting our stuff in the DOM.
I suggest having a look and PR jqconsole. I am the owner of release 2.12 basically (joking)

@arichiardi
Copy link
Contributor Author

With jQuery for instance, can you capture the element between jqconsole-prompt and jqconsole-cursor? Then we spray some highlightjs on top and we are done!

@piecyk
Copy link
Contributor

piecyk commented Oct 28, 2015

yes we can! but need to be smart about it... will do some crazy demo 👯 don't be scared

@arichiardi
Copy link
Contributor Author

Now you are talking like Obama and I am scared

@arichiardi
Copy link
Contributor Author

😄

@tomasz-biernacki
Copy link
Contributor

  1. We don't necessarily need to inject <pre><code>, this is the default highlight.js behavior. Can be any element, see Custom Initialization section here https://highlightjs.org/usage/
  2. When selecting the element to update (the input to highlight) keep in mind that there could be more than one repl on the page (maybe in a blog post or something)

@piecyk
Copy link
Contributor

piecyk commented Oct 29, 2015

some quick hack i don't like the flickering (resenting colors ) but i think we can fix it (yep it will work for more than one)

color

@arichiardi
Copy link
Contributor Author

are you using highlightjs? that's cool, we will do the same with the write-output! it would be great to have syntax coloring for everything but we decrease brightness when the user evaluates.

@piecyk
Copy link
Contributor

piecyk commented Oct 30, 2015

yep here i'm using the highlightjs but trying to move on puget can you check if we can use it in clojurescirpt i got some errors with require namespace? will continue with that today but will have time late evening....

@tomasz-biernacki
Copy link
Contributor

@piecyk It seems it doesn't work, it cannot find the namespace. If you try to do it in a regular Clojure application it works (I checked and it prints coloured output to the console) so it seems it's a ClojureScript problem. I asked Andrea to double check and he had the same problem.

@piecyk
Copy link
Contributor

piecyk commented Oct 30, 2015

Yes it's not ported to clojurescirpt, the quickest why to check if lib can run in cljs is to check if it has cljs files... maybe i will try to port. It's decencies are small and it would be much better that highlightjs let see.

@arichiardi
Copy link
Contributor Author

By the way there exist cljsjs/highlightjs so everything can be ported to cljs :)

@arichiardi
Copy link
Contributor Author

Guys, I opened an issue, can you write that you have the same problem? 😄
greglook/puget#27

@arichiardi
Copy link
Contributor Author

As you can see in the issue guys, no luck with puget, but there is fipp

@piecyk
Copy link
Contributor

piecyk commented Oct 30, 2015

fipp alone is not very useful for us, we need colors! man you read my mind i was driving car back home and was thinking about opening the issue... and 💥 there is an issue 👍

@arichiardi
Copy link
Contributor Author

An other idea is to add what we need (a custom class) or key press events to jq-console. It shouldn't take long. What do you think about it? In any case, even with puget working we will have the problem of inject custom stuff after the prompt..

@piecyk
Copy link
Contributor

piecyk commented Oct 30, 2015

this exactly what i'm doing now in the gif presented, i'm catching the event and coloring the block it's not pretty, it's dirty... i will have fresh look on that over the weekend...

@arichiardi
Copy link
Contributor Author

That's great, thanks for your help Damian.

@arichiardi arichiardi added this to the Repl RC1 milestone Nov 3, 2015
@arichiardi
Copy link
Contributor Author

@piecyk I was thinking, maybe I can hack jq-console to trigger an event each time one function (that we will pass) returns true?
For instance, our function returns true only if the input is a clojure keyword.....the user types de, our fn returns false...it returns true on the f.
It should be easy. What do you think?

@arichiardi
Copy link
Contributor Author

Closed by #56

@arichiardi
Copy link
Contributor Author

I notice a lot of flashing, we will work on this ok?

@arichiardi arichiardi reopened this Nov 5, 2015
@tomasz-biernacki
Copy link
Contributor

@piecyk I noticed two things:

  1. it flashes a little when writing code, my browser is Chrome, Version 46.0.2490.80 (64-bit) on Mac OS X 10.10.5
  2. when you are at the end of the line and type, before the closing parens, a <code> tag appears and disappears

@arichiardi arichiardi removed this from the Repl RC1 milestone Nov 6, 2015
@arichiardi
Copy link
Contributor Author

Good job @piecyk with #59

@arichiardi
Copy link
Contributor Author

I reopen this issue, in every project there is a painful point.
Basically because we are using internals of jqconsole that are not declared in its externs, the minified version of our app fails big time.

So, two solutions, the cleaner is to change the highlighing so that we can have something cleaner using keypress events...
The second is faster, AKA we add the entries to our externs file...

@arichiardi arichiardi reopened this Nov 20, 2015
@arichiardi
Copy link
Contributor Author

A better explanation on how to wrap JS components -> https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components

@arichiardi
Copy link
Contributor Author

@piecyk I also opened a repo called cljs-console for a reagent-only console. I think we can have something quickly. But now I am busy with replumb 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants