Code highlighting in browser (codemirror)
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Code highlighting in browser (codemirror)
I just made a test build to play around with codemirror (https://codemirror.net/)
Is this something we want?
It is easy to implement now i need to figure out how to implement custom highlighting for espeasy (right now it is just javascript)
Is this something we want?
It is easy to implement now i need to figure out how to implement custom highlighting for espeasy (right now it is just javascript)
You do not have the required permissions to view the files attached to this post.
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
i think so too 
save button & char counter do not work right now... therefore the function needs to be rewritten...
edit: works...

save button & char counter do not work right now... therefore the function needs to be rewritten...
edit: works...
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
Oooh that's nice!
How much space does it need to have this implemented?
I'm thinking about adding some p2p mirroring from other nodes.
So one node can advertise what "standard" files it has to offer, allowing other nodes to fetch it from them and serving it to the client (or let it link in the HTML to another node, but not sure about CORS when serving these static files)
How much space does it need to have this implemented?
I'm thinking about adding some p2p mirroring from other nodes.
So one node can advertise what "standard" files it has to offer, allowing other nodes to fetch it from them and serving it to the client (or let it link in the HTML to another node, but not sure about CORS when serving these static files)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
[...]
edit: the p2p option would be nice too... (i am thinking of global or serverside settings from a device that has an other form of storage like sd. also serving a local css file would be great)
Not only the CSS, but think bigger
Let's see if you can think of it yourself before I have implemented it, so you have quite some time to figure it out
edit: the p2p option would be nice too... (i am thinking of global or serverside settings from a device that has an other form of storage like sd. also serving a local css file would be great)

Not only the CSS, but think bigger

Let's see if you can think of it yourself before I have implemented it, so you have quite some time to figure it out

-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
What happend to my post? There are parts missing and text was added
@TD-er did you hijacked my post?
edit:
@TD-er did you hijacked my post?

edit:
I´ll try to think about it but for now i am like a zombie because i read to much text today and tomorrow we have visitors for one week...wich is actually good because then I have to do something other than sitting at the computer all the time....Not only the CSS, but think bigger
Let's see if you can think of it yourself before I have implemented it, so you have quite some time to figure it out

-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
Sjips... I guess instead of quote, I used edit...
Sorry about that, was in no way my intention.
Sorry about that, was in no way my intention.
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
No harm done... i only replied to my own statement...that looks totally normal
Good, that the browser caches a lot of data...hitting the back button a few times and voila:
the files must be stored externally (codemiror.js is about 400k)
and one extra line in rules.cpp after "addHtml(F("</textarea>"));":
thats it

Good, that the browser caches a lot of data...hitting the back button a few times and voila:
these extra lines in webserver.cpp for the head:
Code: Select all
"<link rel='stylesheet' href='codemirror.css'>" // the css files could be combined into one
"<link rel='stylesheet' href='material-darker.css'>"
"<script src='codemirror.js'></script>"
"<script src='javascript.js'></script>" //this is the language for highlighting (just working on that but i am bad at js...or any other language)
and one extra line in rules.cpp after "addHtml(F("</textarea>"));":
Code: Select all
addHtml(F("<script> var rEdit = CodeMirror.fromTextArea(document.getElementById('rules'), {theme: 'material-darker',lineNumbers: true}); rEdit.on('change', function(){rEdit.save()});</script>"));
Last edited by chromo23 on 02 Jun 2022, 11:28, edited 1 time in total.
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
I started with an crude highlighting test. this is definitely a big challenge for me.. so if anyone here speaks fluent js and wants to contribute to a very nice in-browser code highlighting you are very welcome to help writing the language add-on

You do not have the required permissions to view the files attached to this post.
Last edited by chromo23 on 02 Jun 2022, 10:44, edited 1 time in total.
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
Would be even better if you highlight "Event" and add a balloon to suggest to use "asyncevent" 
Using the "delay" command should play some "oh-oh" sound.
But I guess that would be a bit too much for simple grammar parsing to color highlight.

Using the "delay" command should play some "oh-oh" sound.
But I guess that would be a bit too much for simple grammar parsing to color highlight.
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
codemirror offers codefolding, autocompletion and hints 

-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
But for now (and to keep it simple) it would be sufficient to just have a proper highlighting.. 

-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
You might want to have a look at the Notepad++ highlighter for 'inspiration'
/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Thats where i copied all the keywords fromAth wrote: ↑02 Jun 2022, 10:55 You might want to have a look at the Notepad++ highlighter for 'inspiration'

Edit: but implementing it into codemirror is not as easy as in notepad++
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
For testing i uploaded a zip file which contains a custom build for the esp8266 (building for the esp32 gave me an error but if wanted i can upload one later) based on the rather old 20211224 release. but for rules testing it will suffice.
The other files need to be copied to the esp via file upload.
The espeasy.js is the language file wich can be editied (right now this is a modified copy of the shell.js file).
A lot of infos are on the codemirror website and you can download demos and languagefiles here: https://codemirror.net/codemirror.zip
!!! only works with 4mb units because of codemirrors filesize
The other files need to be copied to the esp via file upload.
The espeasy.js is the language file wich can be editied (right now this is a modified copy of the shell.js file).
A lot of infos are on the codemirror website and you can download demos and languagefiles here: https://codemirror.net/codemirror.zip
!!! only works with 4mb units because of codemirrors filesize
You do not have the required permissions to view the files attached to this post.
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
So that alone would be a good idea to have the file served from some CDN or another node in your network.
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Absolutely

For this in particular since i really want to see it implemented, files could be where all the other static stuff is stored (if possible)
The good thing about implementing codemirror is, that it only overlays and hides the textinput... so if the files are not available anymore it falls back to the standard textinput. completly harmless.
Reminder to myself: Stop procrastinating!!!! You have to clean up the apartment before your visitors come....

-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Actually already usable 
i still struggle a bit with "bracketsinbrackets" highlighting...

i still struggle a bit with "bracketsinbrackets" highlighting...
You do not have the required permissions to view the files attached to this post.
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
You are getting somewhere, looking great 

/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Of course, a dark mode should not be missing:
You do not have the required permissions to view the files attached to this post.
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
last but nor least... autocompletion
You do not have the required permissions to view the files attached to this post.
Last edited by chromo23 on 10 Jun 2022, 19:39, edited 1 time in total.
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
Wow!
That looks nice, this autocompletion.
That looks nice, this autocompletion.
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
@TD-er
This one is for you:
This one is for you:
You do not have the required permissions to view the files attached to this post.
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
That flashing red will be annoying very quickly 

/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
BTW the hint system not only uses words from the wordlist. it also analyses the inputfield...
You do not have the required permissions to view the files attached to this post.
-
- Normal user
- Posts: 51
- Joined: 13 Mar 2022, 21:25
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
right now you could build your own firmware using this branch:
https://github.com/chromoxdor/ESPEasy/t ... codemirror
and copy the necessary files from /static (codemirror.min.js, codemirror.min.css, espeasy.min.js, anyword-hint.min.js ) to your esp (for now since the files need to be stored locally 4m units only)
otherwise you have to wait until @TD-er integrates this into the main repository and from there it would make it into a release eventually or before this into an action-build...
https://github.com/chromoxdor/ESPEasy/t ... codemirror
and copy the necessary files from /static (codemirror.min.js, codemirror.min.css, espeasy.min.js, anyword-hint.min.js ) to your esp (for now since the files need to be stored locally 4m units only)
otherwise you have to wait until @TD-er integrates this into the main repository and from there it would make it into a release eventually or before this into an action-build...
-
- Normal user
- Posts: 51
- Joined: 13 Mar 2022, 21:25
Re: Code highlighting in browser (codemirror)
That is, all the necessary files are stored locally, in the ESP?chromo23 wrote: ↑13 Jun 2022, 12:30 right now you could build your own firmware using this branch:
https://github.com/chromoxdor/ESPEasy/t ... codemirror
and copy the necessary files from /static (codemirror.min.js, codemirror.min.css, espeasy.min.js, anyword-hint.min.js ) to your esp (for now since the files need to be stored locally 4m units only)
otherwise you have to wait until @TD-er integrates this into the main repository and from there it would make it into a release eventually or before this into an action-build...
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
The files can be found here:
https://github.com/chromoxdor/ESPEasy/t ... ror/static
For now the files need to be stored locally...but in the future they will come from an external source like a cdn.
If you dont want to build for yourself there is an freshly baked action-build:
https://github.com/letscontrolit/ESPEas ... 2487730400
https://github.com/chromoxdor/ESPEasy/t ... ror/static
For now the files need to be stored locally...but in the future they will come from an external source like a cdn.
If you dont want to build for yourself there is an freshly baked action-build:
https://github.com/letscontrolit/ESPEas ... 2487730400
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
for anyone who wants to test rules highlighting in browser, without building or copying something, can do this here:
https://raw.githack.com/chromoxdor/Easy ... rcode.html
hint: shortcut is currently "alt+space"
https://raw.githack.com/chromoxdor/Easy ... rcode.html
hint: shortcut is currently "alt+space"
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
That won't work for Windows users, as alt-space will activate the current window menu...
/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
S**t

-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Whats with Ctrl+Enter or Alt+Enter?
Edit: Ctrl+Alt seems to work too
Edit: Ctrl+Alt seems to work too

-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
The highlighting is working, but how to activate the auto-complete feature? Can't get that working yet.
Isn't the most common hotkey for code completion ctrl+space? That should work fine on all OSes.
Last edited by Ath on 20 Jun 2022, 21:28, edited 1 time in total.
/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
hinting involves autocompletion.. therefore a shortcut is needed
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
Hm, Windows user here (though that may be obvious
), but the hinting is not working for me, both in Firefox or Chrome
tried all kind of hotkey combinations of ctrl, alt, space, enter...


/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
Thats why i am asking.. the shortcut is still alt+shift (i havent used windows for quite a while so i was not aware that it is already in use)
i want to change that so we have to find a solution that makes both worlds happy

-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
ohh i havent read that yet... you are right with ctrl+space but for me it is already in use for more than a decade..thats why i tried to circumvent this...

So if you can come up with another possibility fine, if not i will have to make a sacrifice

-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
i changed it to ctrl+space for now....
happy testing
happy testing
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
Are you saying that alt+shift (without any other key) should trigger the hint feature? That is not working for me at all, and combined with space it still activates the current window menu, same as alt-space.
And alt-shift in windows also switches keyboard layouts (if you have multiple, like many users/developers in EU have for switching with/without dead keys for accented letters).
And alt-shift in windows also switches keyboard layouts (if you have multiple, like many users/developers in EU have for switching with/without dead keys for accented letters).
/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
i think our communication got a little mixed up...Ath wrote: ↑20 Jun 2022, 22:02 Are you saying that alt+shift (without any other key) should trigger the hint feature? That is not working for me at all, and combined with space it still activates the current window menu, same as alt-space.
And alt-shift in windows also switches keyboard layouts (if you have multiple, like many users/developers in EU have for switching with/without dead keys for accented letters).

i understand, that alt+shift is not working for you thats why i changed it to ctrl+shift for now....
edit: but give it some time or download the html file since github takes some time to refresh the raw content it seems
edit2: now it works with ctrl+shift
-
- Normal user
- Posts: 4341
- Joined: 10 Jun 2018, 12:06
- Location: NL
Re: Code highlighting in browser (codemirror)
That is now working both in Chrome and Firefox, thank you.
/Ton (PayPal.me)
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
@ath
if you want to try the new display keywords since they are all more or less compound words first complete the display type and do the hint again to continue with "," for example....
if you want to try the new display keywords since they are all more or less compound words first complete the display type and do the hint again to continue with "," for example....
-
- Core team member
- Posts: 9921
- Joined: 01 Sep 2017, 22:13
- Location: the Netherlands
Re: Code highlighting in browser (codemirror)
That's a long list of hints.
Can you make it slightly more context-aware?
For example, after an "if" you don't expect "do" or "on" for example.
Or does that make the code (a lot) bigger?
Can you make it slightly more context-aware?
For example, after an "if" you don't expect "do" or "on" for example.
Or does that make the code (a lot) bigger?
-
- Normal user
- Posts: 1018
- Joined: 10 Sep 2020, 16:02
- Location: germany
Re: Code highlighting in browser (codemirror)
That would be indeed a nice extra but nothing i am planning to implement since after one or maximum two characters the list gets significantly smaller...
Who is online
Users browsing this forum: Ahrefs [Bot], Anthropic Claude Bot [bot] and 1 guest