public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: "cat" breaks ANSI codes on Windows Terminal when piping stdout to python or golang
Date: Tue, 14 Jun 2022 19:47:53 +0900	[thread overview]
Message-ID: <20220614194753.e06a3ff4e6be224249956e50@nifty.ne.jp> (raw)
In-Reply-To: <1qctAGvnk1sjfU-ob9Y_DTSQIMpPGIn6lDmSoU0JKGPa_EDZkIMYP65gYufkeEVyPX0WCmJDQAJAmGf13IpPPHUmmchN17WDX4PyRxt2omE=@protonmail.com>

On Tue, 14 Jun 2022 08:01:45 +0000
5990 via Cygwin wrote:
> ## Bug:
> Piping the standard output of cat into the standard input of golang or python, makes the Windows Terminal render ANSI codes as arrows.
> 
> For example:
> `\033[36m` turns into `←[36m` (or in base64'd UNICODE: `4oaQWzM2bQ==`)
> 
> ## Environment:
> - cat v8.26
> - Windows Terminal v1.12.10982.0
> - golang version go1.17.2 windows/amd64
> - python v3.7.7
> 
> colors.go
> ```
> package main
> 
> import "fmt"
> 
> const colorReset = "\033[0m"
> const colorCyan = "\033[36m"
> 
> func main(){
>   fmt.Print(string(colorCyan) + "golang-test" + string(colorReset) + "\n")
> }
> ```
> 
> 
> color.py
> ```
> from lolpython import lol_py
> 
> lol_py("python-test")
> ```
> 
> 
> domains.txt is an empty file (from my testing, the contents of domains.txt do not affect this bug)
> 
> ## What works:
> The following commands will successfuly output in cyan color
> `go run color.go`
> `go build color.go && color.exe`
> `go build color.go && cat domains.txt | color.exe`
> `go build color.go && echo a | color.exe`
> `go build color.go && type domains.txt | color.exe`
> `py -3.7 color.py`
> 
> ## What triggers the bug:
> `cat domains.txt | go run color.go`
> OUTPUT: `←[36mgolang-test←[0m`
> 
> `cat domains.txt | py -3.7 color.py`
> OUTPUT: `←[38;2;128;237;18mp←[0m←[38;2;139;231;12my←[0m←[38;2;150;225;8mt←[0m←[38;2;161;217;5mh←[0m←[38;2;172;209;2mo←[0m←[38;2;182;200;1mn←[0m←[38;2;192;190;1m-←[0m←[38;2;201;180;1mt←[0m←[38;2;210;170;3me←[0m←[38;2;218;159;5ms←[0m←[38;2;226;148;9mt←[0m`
> 
> Strangely enough, golang compiled executables work perfectly, but piping `cat domains.txt | go run color.go` does not work.
> The workaround I had to go with is to use Windows's built-in `type` command instead of `cat`. This was a tricky bug to track-down so I hope this report helps hahah

I cannot reproduce your problem.

My environment is:
cygwin 3.3.5
cat 8.32
Windows Terminal 1.13.11431.0
go version go1.18.3 windows/amd64

What shell did you use? cygwin bash? cmd.exe? powershell?

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

  reply	other threads:[~2022-06-14 10:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14  8:01 5990
2022-06-14 10:47 ` Takashi Yano [this message]
2022-06-14 21:53   ` 5990
2022-06-14 21:56     ` 5990
2022-06-15  1:04       ` Takashi Yano
2022-06-15  4:42         ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220614194753.e06a3ff4e6be224249956e50@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).