davsclaus opened a new pull request, #29924:
URL: https://github.com/apache/camel/pull/29924

   Part of item 5 of 
[CAMEL-26929](https://issues.apache.org/jira/browse/CAMEL-26929): ANSI escape 
codes in piped output.
   
   ## Problem
   
   `--logging-color` defaults to true for `camel cmd send`, `camel trace`, 
`camel cmd browse`, `camel get history`, `camel cmd receive`, `camel get span` 
and `camel cmd stub`. These commands print the colors through the printer, so 
in a file or a pipe the output has the ANSI codes, which an AI agent or a 
script reads as noise. #29826 fixed `camel log` only.
   
   On the launcher from main, with an integration whose `direct:echo` route 
replies:
   
   ```
   $ camel cmd send <pid> --endpoint=direct:echo --body=hi --reply | cat     # 
12 ESC characters in the output
   ```
   
   ## Change
   
   - `CamelCommand.colorOutput(loggingColor)` (new) decides whether to print in 
colors:
     - an explicit `--logging-color` (true or false) is followed as given;
     - else colors only when the command prints to a terminal 
(`EnvironmentHelper.hasTerminal`, which uses `Console.isTerminal` on JDK 22+);
     - a command that prints to another printer than the console (the TUI, the 
MCP server, tests) keeps the option as it is.
   - The seven commands apply it at the start of the command.
   
   After, with the patched jars:
   
   ```
   $ camel cmd send <pid> --endpoint=direct:echo --body=hi --reply | cat        
            # 0 ESC characters, the reply is there
   $ camel cmd send <pid> --endpoint=direct:echo --body=hi --reply 
--logging-color | cat    # 12, as asked
   ```
   
   The rest of item 5 (JSON shape: `uptime`, `pid` types, missing `pid`/`name`, 
`--json` for `cmd send` and the trace dump) is left for its own PR.
   
   ## Tests
   
   - `ColorOutputTest`: no colors to the console without a terminal (the test 
JVM has none); colors when `--logging-color` is given; another printer keeps 
the option.
   - The send, trace and browse action tests pass (93), including the colored 
status line test, which uses a string printer.
   - End to end with the launcher, as above.
   - camel-jbang-run: 303 tests pass. camel-jbang-core: 3005 + 259 pass 
(`DependencyUpdateTest` failed once and passed on the rerun, as on other 
branches).
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to