[ 
https://issues.apache.org/jira/browse/GROOVY-12784?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18147076#comment-18147076
 ] 

ASF GitHub Bot commented on GROOVY-12784:
-----------------------------------------

codeconsole commented on PR #3309:
URL: https://github.com/apache/groovy/pull/3309#issuecomment-7000148736

   Thanks both. Both points reproduced, and they're addressed in 9bb03d5667, 
e2c0a85070 and 4f31e60c14:
   
   - `IO` only opens JLine's console for `jansi.mode=force`, or on a terminal 
when the mode isn't `strip` (`System.console()`, plus `Console.isTerminal()` on 
JDKs that have it), so piped, CI and daemon runs never load the native library 
(9bb03d5667).
   - There's no JDK API that identifies the JVM's original stdout once a host 
has replaced it, so color is now opt-in: `new IO()` and the stream constructor 
are plain, as they were on master, and only an IO from the new 
`IO.forConsole()`, which groovydoc's `Main` uses, can color. The Ant task and 
anything else that goes through `Logger` never load JLine (9bb03d5667). This 
adds public methods on `IO`; `IO` isn't in the ABI registry.
   - The console is created lazily, as Paul suggested (4f31e60c14). `out` and 
`err` stay plain and `ansiSupported` stays final, decided without opening the 
console. `Logger` opens the console through the new `IO.getAnsiOut()` on its 
first colored line, and prints plain text if the console can't render ANSI or 
`System.out` has been replaced since the IO was created. A groovydoc run that 
logs nothing never opens it.
   - The `groovydoc` and `groovydoc.bat` launchers pass 
`--enable-native-access=ALL-UNNAMED`, as `groovysh` does (e2c0a85070).
   - New forked tests: `System.out` replaced before `Logger` creates its IO and 
replaced before the first line, the console still closed when nothing has been 
logged, `strip` mode, and Jansi off the classpath. The redirected test also 
asserts that no console was opened and no restricted-method warning appears on 
stderr. Each of these fails when the check it covers is disabled.
   - `ansiSupported`'s Javadoc now says what it decides, and that `out` and 
`err` are always plain.
   
   Checked in a pseudo-terminal on JDK 25 and 17: `groovydoc --debug` is 
colored on a terminal and plain when piped or with `-Djansi.mode=strip`, with 
no warning in either case, and a run that logs nothing sends no terminal probe. 
The one remaining case is code that calls `IO.forConsole()` itself on a JDK 24+ 
terminal without `--enable-native-access`, which gets the warning on its first 
colored line. That would be the release-note item.




> The shell Logger never prints ANSI colors because IO looks for the old Jansi
> ----------------------------------------------------------------------------
>
>                 Key: GROOVY-12784
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12784
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {{org.codehaus.groovy.tools.shell.IO}} decides whether to render ANSI by 
> looking for {{org.fusesource.jansi.AnsiRenderWriter}}. Since GROOVY-8162 
> Groovy ships JLine's Jansi ({{org.jline:jansi}}) instead, which has no such 
> class, so {{IO.ansiSupported}} is always {{false}} and the shell {{Logger}} 
> (used by groovydoc) never colors its DEBUG, WARN and ERROR prefixes, although 
> {{Logger}} already renders them with {{org.jline.jansi.Ansi}}.
> {{IO}} should detect JLine's Jansi and render through its {{AnsiConsole}}, 
> for the JVM's own standard output and error only, so output redirected to a 
> file or a pipe stays plain. The {{jansi.mode}} system property ({{force}} / 
> {{strip}}) still applies.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to