Using Go to create a terminal prompt

I just started working on a small hobby project where the goal is to create a terminal prompt for my self. The prompt is configurable using a JSON file, since I know essentially nothing about bash and .bashrc. When I run my program in the terminal, it looks ok, the colors are working:

The first row is my current prompt, so ignore the first row. The second row shows the output of my program right now, and please ignore the fact that it is ugly as hell, and the colors are all over the place, that is not the problem. I am currently testing a lot of things, and are just picking the first color that comes to mind in my JSON file.

The problem is when I in my .bashrc write:


then the prompt has lost all of it’s color:


This is probably a bash problem, and not a Go problem, so this might not be the best forum for a question like this, but I am trying here first. Does anyone know why the colors disappear? Do I need to add a special character, or two, to initiate coloring (for the terminal to understand colors) in my Go program, or do I need to add something to my .bashrc, or is it impossible to create a terminal prompt using another language (other than bash)?

If it matters, I am testing this on a machine running Linux Mint 20.2, and I am using Go 1.17.

The (incomplete) code can be found here : GitHub - Hultan/goprompt: A terminal prompt configurable using a JSON file

I just skimmed the code, but you seem to use a library that disables colour if it doesn’t detect a TTY. Which usually is a good thing. You need to find a way to enforce colour despite no TTY being available.

Aaah, thanks! I just made a small test, and there is a flag called NoColor (in the color package), that has different values when run through .bashrc. So you are almost certainly correct, now I have an idea of how to continue…thanks!

Edit: There was a function called enableColor() on the color-package, that solved the problem. Now I have color, even when using it through .bashrc. I was so focused on bash being the problem, that I completely missed this. Again, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.