title: How to tell if a Java application is running within the Eclipse console (versus, for example, xterm)?
body: <p>I am writing a Java framework that prints logging messages with ANSI color codes. Of course, there is always the chance that users could be using it from within Eclipse, in which case the ANSI escape codes appear as garbage characters on the console. It would be nice to autodetect this, so that users don't have to turn it off manually.</p>
  
  <p>I've done some Googling on the subject, and I suspect that it can't be done, but not many people have tried, so I figured it was worth asking. One method that comes to mind is checking whether <code>"xterm".equals(System.getenv("TERM"))</code>, which <em>sort of</em> works, but has a lot of exceptions and doesn't work at all on Windows (I'm using the JANSI library to get Windows color terminal support, as well). Another option that comes to mind is trying to call an external program to check whether a process called <code>eclipse</code> is running, but this is a dirty hack, and also has edge cases (color would disappear if someone was running the program in a terminal while also using Eclipse).</p>
  
  <p>I even tried using reflection to find the <code>OutputStream</code> subclass that <code>System.out</code> is wrapping, assuming it might be different depending on the terminal type, but it's apparently a <code>FileOutputStream</code> no matter what.</p>
  
  <p>Is there any less hackish way to determine whether a Java program is running in the built-in Eclipse console, or is this as hopeless as it sounds?</p>