Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom colors in the prompt #33

Open
midshell-ghoul opened this issue Oct 15, 2024 · 5 comments
Open

Using custom colors in the prompt #33

midshell-ghoul opened this issue Oct 15, 2024 · 5 comments

Comments

@midshell-ghoul
Copy link

midshell-ghoul commented Oct 15, 2024

Using custom colors in the prompt adds dead space at the end of it. This occurs anytime you pass a string with ANSI escape characters in it, and seems to be roughly the length of the escape characters used.

This code:

var noise = Noise.init()

let fgCustomColor = ansiForegroundColorCode(rgb(150, 50, 250))
let prompt = Styler.init(fgCustomColor, "prompt> ")
noise.setPrompt(prompt)

Results in this output:
image

I tried another method, by using a Color value directly in the Styler initialization, however it didn't work. I might be reading the source code wrong, but I believe it is supported here (https://github.com/jangko/nim-noise/blob/master/noise/styler.nim#L54). Please let me know if I've misunderstood something.

@jangko
Copy link
Owner

jangko commented Oct 16, 2024

looks like the prompt length calculator not calculating the color correctly. The calculator should ignore the color chars length.

@midshell-ghoul
Copy link
Author

Is there a proper way to pass Color to the Styler.init() ? I tried:

let fgCustomColor = rgb(150, 50, 250)
let prompt = Styler.init(fgCustomColor, "prompt> ")

but that didn't seem to take despite there being code in the library to handle Color.

@jangko
Copy link
Owner

jangko commented Oct 16, 2024

What kind of terminal you use? Is the example/test.nim works for your terminal?

@midshell-ghoul
Copy link
Author

midshell-ghoul commented Oct 16, 2024

I'm using the default kali terminal. The examples in example/test.nim work as they are using ForegroundColor. Anything from std/colors fails (https://nim-lang.org/docs/colors.html)

Edit: zsh version 5.9. It seems nim-noise uses stdout.setForegroundColor c.rgbVal when using Color. This function checks to make sure the terminal supports true color, which mine supposedly does... (https://github.com/nim-lang/Nim/blob/version-2-2/lib/pure/terminal.nim#L764). This might just be a configuration issue on my end.

Edit2: Terminal supports true color just fine
image

Final Edit: Okay it turns out I needed to call enableTrueColors(). std/terminal doesn't seem to actually check whether true color is supported, you've got to explicitly tell it.

@jangko
Copy link
Owner

jangko commented Oct 16, 2024

Glad you can solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants