julien040 / gut

A beginner friendly porcelain for git

Home Page:https://gut-cli.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Raw ANSI escape codes get printed on Windows, on some places, but not on others

rotemdan opened this issue · comments

In the command prompt:
Screenshot_2

In VSCode terminal:
Screenshot_1

Otherwise colors do work:
Screenshot_3
Screenshot_4

Sometimes there's a mix of colors and raw ANSI codes:

Screenshot_5

(BTW: this error message is shown after pressing Control + C while viewing gut history. Maybe it's not needed in this case?)

Hey @rotemdan 👋, I have finally been able to get a Windows computer and try to reproduce the issue (sorry for the late response).
Which version are you using (windows and VsCode) ? I have opened Visual Studio Code on Windows 11 and was unable to reproduce the issue. The ANSI escape codes weren't showing

Capture d’écran 2023-08-29 173016

(And by the way, you're right. The error is not needed in this case. gut should handle CTRL+C termination.)

I'm using the cmd.exe command line, not PowerShell:

Screenshot_1

To set it as default in VSCode:
Screenshot_2

Same for the shell I'm using in general. I never use PowerShell.

Hi,
I apologize for the very late response.
I have been busy, and I cannot access a Windows computer frequently.

Replication

I have tried to replicate this issue, but unfortunately, I can't.
I don't see any ANSI codes even when using cmd.
gut whereami

Potential fix

After doing some research, I discovered that Windows started supporting ANSI color code from Windows 10 TH2 (https://superuser.com/a/1050078).
What is your Windows version ? Mine is:
WIndows version

I'm using:

Windows 10 Pro
Version: 22H2
OS Build: 19045.3570
Experience: Windows Feature Experience Pack 1000.19052.1000.0

In my Node.js applications I use the chalk library to add colors to terminal outputs, and it doesn't have this issue.

I saw in the code that you're using these libraries for color:

import (
	"github.com/charmbracelet/lipgloss"
	printColor "github.com/fatih/color"
)

Maybe one or both of them are not tested on Windows 10?

Thank you. It's not an issue with the Windows version.
I believe the issue is related to fatih/color.

Can you please run gut remote and screenshot the results ?
Normally, the raw ANSI codes should not show up if I have correctly identified the root cause.

My version is is still v0.2.10 (I tried to update using scoop). The issue still happens (I don't think the version is any different than before).

Do I need to compile the latest repository version to use the version you're referring to?

I haven't used Go in many years. Maybe you can attach a precompiled binary for Windows (if possible)?

I don't want to bother you with compiling. You are already kind enough to help solve this issue.

gut prints colors using three different methods. The one used by gut whereami is faulty. I want to check if the one used by gut remoteis faulty too.
You don't need to recompile. Just run gut remote with your current version.
If no escape codes are shown, I would have identified the bug.

gut remote prints a part of the text in invisible or black letters:
Screenshot_1

When copying and pasting the text, it turns out there is actually text in the black area:

Remote found:
        origin <https://github.com/echogarden-project/echogarden.git>

gut status prints some raw escape codes:
Screenshot_2

gut branch does print some text in a green color:
Screenshot_3

Thank you !
I know where the issue is coming from.
I must change the way gut prints the text (fatih/color#154 (comment))

I will ping you when I release the patch

Hi @rotemdan,
I have pushed a fix in v0.3.0.
Please check if the issue is now resolved.

Thanks! I updated to v0.3.0. Tried several commands and I'm not seeing the escape codes so far. The colors seem correct:

Screenshot_1
Screenshot_2
Screenshot_4

However gut remote still shows the black/invisible text:
Screenshot_3