Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Logs] Add colorful text log for CLI output #1810

Open
Slamdunk opened this issue Jan 27, 2023 · 9 comments
Open

[Logs] Add colorful text log for CLI output #1810

Slamdunk opened this issue Jan 27, 2023 · 9 comments

Comments

@Slamdunk
Copy link
Contributor

Slamdunk commented Jan 27, 2023

Hi, I'd like to have a colorful text log for CLI.
I am aware of the precious logs that are already present, like HTML, JSON, Summary and Stryker, but they are not very TDD friendly.
This is particularly necessary since Infection removes all indentation, so murators like ArrayItemRemoval are very hard to read when hundreds of LoC are compressed in a single line in text output.

I'm currently workarounding this with the text log, making it a compatible diff --unified format and redirecting it to diff-so-fancy, with this little bash script:

text-to-colorful-diff.sh
cat - \
  | sed \
    -e ':a' \
    -e 'N' \
    -e '$!ba' \
    -e 's#) \(\S\+\):\(\S\+\)    \[M\] \(\S\+\)\n\n--- Original\n+++ New\n@@ @@#) Mutant failed: \x1B[1;33m\3\x1B[0m\n\ndiff --git a/\1 b/\1\n--- a/\1\n+++ b/\1\n@@ -\2,1 +\2,1 @@#g' \
  | diff-so-fancy \
  | sed \
    -e ':a' \
    -e 'N' \
    -e '$!ba' \
    -e 's#─\+\x1B\[0m\n##g' \
    -e 's#modified: \S\+\n##g'

Before

image

After

image

@maks-rafalko
Copy link
Member

Hello, let me ask a couple of questions to understand how it's going to work

  1. Are you talking about text file, generated by text logger?
  2. Are you talking about stdout output by text logger, like this "logs": {"text": "php://stdout"}
  3. Is it supposed to be done by ANSI sequences?

If using ANSI sequenses, I guess the readability of the file will be reduced in the "raw" editor mode, because of ANSI chars (like [1;32m Some string [0m). So do we need a flag/option to enable this ANSI mode?

@Slamdunk
Copy link
Contributor Author

I guess it would be better to just introduce a new cli logger that defaults to STDOUT, reuses the text format internally and adds colors by using the built-in color detection of Symfony Console.

@maks-rafalko
Copy link
Member

one more question: did you try -s or --show-mutations option that gives similar output to what is shown on your screen?

or do you mean we need a characters diff (like on red background on your image) to be present in addition to red/green lines?

@Slamdunk
Copy link
Contributor Author

or do you mean we need a characters diff (like on red background on your image) to be present in addition to red/green lines?

Exactly this: the current color hightlights would be enough with original formatting, but inlining everything makes them useless again.
I need either the original formatting with the current red/green lines, or mangled formatting with char diff.

@maks-rafalko
Copy link
Member

maks-rafalko commented May 12, 2023

I see, thank you.

So the best way is to find such differ written in PHP so we don't need to integrate with/require diff-so-fancy.

This should be investigated. From the quick look, we can find some packages to try out, for example:

If you @Slamdunk has any suggestion, please advice.

@Slamdunk
Copy link
Contributor Author

Slamdunk commented May 12, 2023

I saw just now the src/Differ/DiffColorizer.php: it's easy to implement an inline-differ addition for char highlight.

I'll propose a PR in the next week then 💪

@maks-rafalko
Copy link
Member

that would be very cool. Thank you!

@maks-rafalko
Copy link
Member

Hello @Slamdunk

are you interested in adding this feature? If not, could you please show some examples where we can get that "inline-differ" and see how it works? Thanks

@Slamdunk
Copy link
Contributor Author

Slamdunk commented Nov 4, 2023

Sorry Maks, yes I'm still interested but got overwhelmed at job, sorry 😅

I forgot what I talking about, I had few snippet but lost them 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants