ABridoux/lux

Terminal output should have escape characters

DiegoMagdaleno opened this issue · 6 comments

Hi! First of all thanks a lot for this project, I hope it can get more users and more languages in the future! and I will be happy to contribute, however I noticed the following issue.

To print colors in the terminal we need an escape character: \e here is a reference.

So I was wondering if it would be an option to have this escape chars so:

This:
[0;0mlet[0;0m[38;5;65m a[0;0m[38;5;24m =[0;0m [38;5;65m-1[0;0m\n

Becomes this:
\e[0;0mlet\e[0;0m\e[38;5;65m a\e[0;0m\e[38;5;24m =\e[0;0m \e[38;5;65m-1\e[0;0m\n

Or I might not be using the library correctly, anyway I am thankful for this project! Hope there is a solution.

Hi! Thanks. What terminal are you using ? From what I have read, you should not need to escape the modifiers yourself in most terminals, since Lux already does it.
If you want to specify a color, you can use the Terminal Modifier(colorCode:) initialiser with a 0-255 color code (you can find the color codes list in the wiki). It will apply the escape and the color specification.
But if you don't plan to modify a color, you should not have to escape anything. Could you tell me more about your use case?

Thanks for the reply, I am using it as a library to output to iTerm 2, I am not using any colors that are different, I was testing it in playgrounds.
I don't know if the use as library has different behavior than the CLI tool

// Playgrounds
import Lux

var delegate = SwiftDelegate()
let injector = SwiftInjector(type: .terminal, delegate: delegate)

let text = "let a = -1"

let colorizedText = injector.inject(in: text)
print (colorizedText)

Here is the code since I am testing, I don't know if that helps.

Seems to work in the terminal with the lux command line tool:

Screen Shot 2020-09-19 at 10 39 29

However this is not the case with the library, or perhaps im doing something wrong

Do you output in the terminal or inside the Xcode console when running the playground ? If it's in the Xcode console, it's not supported unfortunately, although some alternatives exist in open-source.

Oh I see thanks a lot, just checked seems to work correctly outside xcode console!

You are welcome! Glad to help.