Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a formatter that can output the source code in a form that can be used with GNU Troff (groff).
Groff is a typesetting system that has its roots in some of the oldest text formatting software out there. It can be used to create formatted documents, papers, books, etc. It is similar to LaTeX in that sense but much more minimal and older. Nowadays, it's mostly used for creation of
man
manual pages.This formatter is using groff escapes to change the color and font style (regular, bold, italic) of the text. It also has a few options that allow the user to print the source code with line numbers and wrap it to a specified width. By default, the output is using a monospace font but it can be disabled too. Some special characters that are used by groff are replaced by escapes for printing Unicode characters. The same applies for non-ASCII characters, which groff can't print. The formatter isn't using any macro specific commands, so it should work with all of them (ms, mom, man, etc.).
I tested the formatter thoroughly using various source code files of my own and the ones available in the tests/examplefiles directory. I also used different combinations of options to make sure they don't conflict with each other. I didn't notice any issues. The only time when the output might look different than expected is when input contains characters that groff doesn't support (possibly to the lack of them in the default font). It will then give a warning that it cannot find the character and won't print it.
To test it yourself, you can use the following command:
It is my first contribution to the project and I'm not programming in Python that often, so I'm open to comments and feedback.