Syntax highlighting is here! Honestly thought this would take way longer than it did.
The approach is simple: walk through the string character by character, check
what type the next token is (keyword, variable, number, operator, bracket) and
set the color before printing. The actual characters are printed 1:1 — no
modification, no magic. 17 spaces in? 17 spaces out.
Color changes are handled by a prebuilt textColor(COLOUR) function that just
sets the console color before the next print. Clean and simple.
Known bugs I definitely know about and totally plan to fix (eventually):
– Can’t write mid-line because of a \0 at the start of the string 💀
– Pressing delete at the end of a line removes the entire line (is this a bug or a feature? I’m choosing to call it a feature for now)
Next up: fixing the actual bugs. Probably.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.