FenderLang / Fender

A functional scripting language, intended for string manipulation and general scripting on the command line
MIT License
13 stars 0 forks source link

Add shothand for using color escapes when printing to the terminal #99

Open FuzzyNovaGoblin opened 1 year ago

boxbeam commented 1 year ago

We could have a color function that emits a color code sequence for a color by name, so you could use it like "This is {color("red")}some colored text{color("reset")}"

eliminmax commented 1 year ago

Hello. I'm the one who was presenting in the other room today, and the one who asked about this functionality.

In case its helpful, I've found this to be a great guide to how terminal graphics work - it's decades of hacks upon hacks that somehow work, but are often complex.

@Redempt That can make it simple, but does not give as much control as entering color codes directly - in Python, if I wanted to print that red text, I'd use "\x1b[31msome colored text\x1b[m" (1b is the hex code for the escape character). Obviously less readable, but as someone who does a lot with color control escape sequences, I often need to be more precise than simply specifying "red" or "green".

boxbeam commented 1 year ago

That's a great resource, thank you!

eliminmax commented 1 year ago

I think that simply adding '\e' as an escape character that maps to \u{1b} is enough for my use case - I can get by with \u001B as well - it just took a bit of experimentation to figure out the right syntax for that.