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: 3.1.x: Mangled input/output when calling non-cygwin programs
Date: Mon, 03 Feb 2020 14:20:00 -0000	[thread overview]
Message-ID: <20200203231951.0b9e4ede90188c0fa20fe658@nifty.ne.jp> (raw)
In-Reply-To: <20200203040033.375b2b75be4ab5b8b12b82bb@nifty.ne.jp>

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

  reply	other threads:[~2020-02-03 14:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-01 18:00 m0viefreak
2020-02-02  9:59 ` Takashi Yano
2020-02-02 12:18   ` m0viefreak
2020-02-02 19:01     ` Takashi Yano
2020-02-03 14:20       ` Takashi Yano [this message]
2020-02-09 13: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=20200203231951.0b9e4ede90188c0fa20fe658@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).