Summary: Is there an easy, standard way to change some text’s color, for instance via a
I’ve been developing a package, atom-slime, which seeks to make Atom an interactive development environment for Lisp code. As part of this, I’ve implemented a REPL / console in a text editor where you can enter commands and view results:
My current implementation achieves the different colors by using a custom grammar. For instance, part of this grammar looks for the prompt at the beginning of each line, and colors it appropriately with bold text. To colorize large segments of output text / return values, my current approach adds surrounding pairs of of non-printing ASCII characters around the desired text in the editor, which trigger the grammar to color the text appropriately. That’s how the “Hello, world!” string that is printed as output looks all green in the image above, and the return value (here, NIL) is orange.
For instance, instead of adding the text
"NIL" to the text editor, my package adds something like
"\x1BNIL\x1B" (using the nonprinting escape character), and my grammar labels anything between two
"\x1B" characters appropriately as an output value, and my styling colors it correctly.
This approach – namely the combination of using a custom grammar and special non-printing ASCII characters to trigger that grammar - feels a bit odd to me. I was curious, is there a better way to change the color of text in a
I’m of course familiar with the Markers / Decorations API, but those seem to be separate layers that can’t control text color. I’ve also taken a look at the excellent Atom pigments package, which as I understand it does something similar by using a highly-customized decoration-like API. I was wondering, however, if there is more standard way to accomplish that’s less risky when API’s change. I’d find such a feature / API super useful.
Thanks so much for your hard work on a wonderful text editor!