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

MMC Colored Output #51

Closed
Aabaz opened this issue Feb 24, 2020 · 5 comments
Closed

MMC Colored Output #51

Aabaz opened this issue Feb 24, 2020 · 5 comments
Labels

Comments

@Aabaz
Copy link

Aabaz commented Feb 24, 2020

Hello,
I see that MMC outputs colored text using ASCII escape sequences.

In some cases this makes it difficult to filter the output with text based tools like sed.

Would it be possible to either disable it via a command line option or to at least put reset escape sequences before line breaks (example patch below) as it would make it easier to process the following lines.

diff --git a/src/mcx_utils.c b/src/mcx_utils.c
index d34e4dc..4797d15 100644
--- a/src/mcx_utils.c
+++ b/src/mcx_utils.c
@@ -1394,7 +1394,7 @@ void mcx_printheader(mcconfig *cfg){
 #                Research funded by NIH/NIGMS grant R01-GM114365              #\n\
 ###############################################################################\n\
 $Rev::      $2019.4 $Date::                       $ by $Author::              $\n\
-###############################################################################\n"S_RESET);
+###############################################################################"S_RESET"\n");
 }
 
 /**

Thanks for your help.

PS: I compiled mmc from tag v2019.4 using make release

@fangq fangq added the wontfix label Feb 24, 2020
@fangq
Copy link
Owner

fangq commented Feb 24, 2020

the color escape code is easy to remove using sed before processing the text, you just insert

mmc ... | sed -e 's/\x1b\[[0-9;]*m//g' | ...

or

sed -e  's/\x1b\[[0-9;]*m//g'  -e '...'

the first -e flag removes all code escape codes and then you can apply further filters to the text.

you can also do this with perl and other stream processing tools

https://superuser.com/questions/380772/removing-ansi-color-codes-from-text-stream
https://stackoverflow.com/questions/17998978/removing-colors-from-output

@fangq fangq closed this as completed Feb 24, 2020
@Aabaz
Copy link
Author

Aabaz commented Feb 24, 2020

Yes, the escape sequences can be removed later, I just find it a little cleaner to keep the escape sequences on the colored lines (or ideally to be able to suppress them via a CLI argument) but I understand this is a matter of taste/opinion.

If the escape sequences stay as they are now, the examples cases bash scripts may need to be updated to remove them.

Please let me know if you would be open to that kind of contributions, I could try to do a PR.

Best,

@fangq
Copy link
Owner

fangq commented Feb 24, 2020

is there a particular field that you want to filter?

you could also use mmc -v to print the version info, if that's what you want, that does not have color escape codes.

@Aabaz
Copy link
Author

Aabaz commented Feb 25, 2020

To be clearer, the examples scripts filter the output for postprocessing by Octave/Matlab scripts but the filter commands fail because of the ASCII escape sequences.

For instance, the "onecube" example, the run_test.sh script fails to filter the output because of the escape sequence.

So a solution may be to either:

  • change MMC output to keep escape sequences on the same line as colored text
  • or change the filtering commands in the examples

Hope that helps.

fangq pushed a commit that referenced this issue Feb 25, 2020
@fangq
Copy link
Owner

fangq commented Feb 25, 2020

ok, I see where this came from.

see my above command update to the onecube example.

first, the output did not work anymore because the printed messages are only visible when running the simulation on the CPU - this is now triggered by -G -1, if you don't add that flag, mmc will call OpenCL version of mmc, which does not print the message - printing on the GPU is quite expensive.

so I added -G -1 in the commands, and also removed the header that I force printing, now the output should be correct again.

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

No branches or pull requests

2 participants