X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:in-reply-to
	:references:mime-version:content-type:content-transfer-encoding;
	 q=dns; s=default; b=W0Hq+gU3tMu2kg2iblGdyoM4CKOHRl27wijXcBVlYiq
	kuOQ+xHBGXZN89Sg1TxAmEOBKLskVSrJ2H0wXqAW8vcGrSDC2qUVBlhUZXdWJ39a
	fmZgRjg7FeMmX2KxlAr5RjKW1zwVz8mIgF2AutBuzC/Yrt1Areh1BZgOhB85Y8/o
	=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:date:from:to:subject:message-id:in-reply-to
	:references:mime-version:content-type:content-transfer-encoding;
	 s=default; bh=FUEShYFF6ck3yXuGZKLUFZXOrro=; b=Ekga2BkCERlc/f2+/
	jYnF5W2KKSRl3Agp4JbX+ImFSrUnGGp/5RP7A1K/wPNBOG2IjUqCfLaxppxsUjRT
	G5CpKys81YoI2Aku3t39I0zbIhJofuxIXV5CKrhMN1widrxp+eMSVG4ICxVe9qHt
	exMqi+AyuKHfcml8+p4zX8dtzs=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-17.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=HX-Spam-Relays-External:Sendmail, H*RU:Sendmail, H*r:authenticated
X-HELO: conssluserg-02.nifty.com
DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-02.nifty.com 013EJpS6000390
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp;	s=dec2015msa; t=1580739591;	bh=2NMkbZdpHQ8+mzNOoXdcP/cTLAmBQfOqkRQ9zqlmiH4=;	h=Date:From:To:Subject:In-Reply-To:References:From;	b=nLDGO0QQVs4EAsE7SLflHixPEKYdmjlJFaSsjEUbFtgXjG8hFxFYUBmGgNatndp3e	 6yMWXHd6YWFvp1x1Jjx5P9Oo2gGsNBXGAC41ee0Q2sGx+EuKd+lgiRIKGnHAWws0Wo	 arM7GKma+qJ8IxcHnQmxnQzOO9LcIPgYT3Cjt1e32C6mzt1RLDpAz0/E1FZak54Z/H	 TftcyJc6gAx83ZE3D88MtJl+YWojGHDEVvhuecL621jGznwgR2AeO4ysrh0jWjftgQ	 CLEWqArm4PsX5HOa7ByY/u27wFTv/56Oa3yqxxE53XsJuns/NfeTQT1rYDL5EQaW9M	 NKpI4AL01KmTw==
Date: Mon, 3 Feb 2020 23:19:51 +0900
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: 3.1.x: Mangled input/output when calling non-cygwin programs
Message-Id: <20200203231951.0b9e4ede90188c0fa20fe658@nifty.ne.jp>
In-Reply-To: <20200203040033.375b2b75be4ab5b8b12b82bb@nifty.ne.jp>
References: <7e3d947e-b178-30a3-589f-b48e6003fbb3@googlemail.com>	<20200202185909.a3b3f8627438177e18171de3@nifty.ne.jp>	<04b7abc1-3317-51c2-99e2-c8573458a5f1@googlemail.com>	<20200203040033.375b2b75be4ab5b8b12b82bb@nifty.ne.jp>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On Mon, 3 Feb 2020 04:00:33 +0900
Takashi Yano wrote:
> On Sun, 2 Feb 2020 13:18:03 +0100
> m0viefreak wrote:
> > It seems that the cygwin1.dll does not care about TERM, but if a
> > non-native application *uses* TERM for whatever reason things start to
> > break. If indeed 'cygwin' is the right terminfo to be used, should the
> > PTY code then somehow set TERM=cygwin in the non-native process? But
> > what if the none-native program doesn't even know the 'cygwin' terminfo?
> 
> This make sens only if apps use TERM *right way*. In other words,
> if apps uses TERM in the manner of termcap or terminfo. I don't
> think Maven does that.
> 
> Now I am looking into jansi library which Maven uses, and found
> it sets IS_CYGWIN flag according to TERM environmen. It seems
> that IS_CYGWIN is set to false if TERM=cygwin. In this case,
> jansi uses SetConsoleTextAttribute() call to set text color
> rather than escape sequences such as ESC[31m. Ohterwise, escape
> sequence is used.
> 
> See:
> https://github.com/fusesource/jansi/blob/master/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
> 
> New cygwin provide pure windows console for native apps, so
> escape sequence is not handled correctly. This is the cause
> of the problem 1) and 2). It may be a problem that TERM is
> set even though pure windows console does not have the
> capability which TERM environment declares. For the one
> thought, it can make sense to unset TERM before execute
> native-console apps. However, this does not solve the issue
> of Maven. If Maven (jansi) handles TERM *correctly*, this
> can be a solution.

As for the problem 1) and 2), I think Maven (jansi) should be
fixed rather than cygwin. I have applied the following patch
to jansi, and confirmed this solves the problem 1) and 2).

diff --git a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
index 628cad3..a5400c5 100644
--- a/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
+++ b/jansi/src/main/java/org/fusesource/jansi/AnsiConsole.java
@@ -19,6 +19,10 @@ import static org.fusesource.jansi.internal.CLibrary.STDERR_FILENO;
 import static org.fusesource.jansi.internal.CLibrary.STDOUT_FILENO;
 import static org.fusesource.jansi.internal.CLibrary.isatty;
 
+import static org.fusesource.jansi.internal.Kernel32.GetConsoleMode;
+import static org.fusesource.jansi.internal.Kernel32.GetStdHandle;
+import static org.fusesource.jansi.internal.Kernel32.STD_OUTPUT_HANDLE;
+
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -54,10 +58,11 @@ public class AnsiConsole {
      */
     static final boolean IS_CON_EMU_ANSI = "ON".equals(System.getenv("ConEmuANSI"));
 
+    static private int[] mode = {0};
     static final boolean IS_CYGWIN = IS_WINDOWS
             && System.getenv("PWD") != null
             && System.getenv("PWD").startsWith("/")
-            && !"cygwin".equals(System.getenv("TERM"));
+            && GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode) == 0;
 
     static final boolean IS_MINGW_XTERM = IS_WINDOWS
             && System.getenv("MSYSTEM") != null


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

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

