I’m using an NSTask to grab the output from /usr/bin/man. I’m getting the output but without formatting (bold, underline). Something that should appear like this:
Bold text with underline
(note the italic text is actually underlined, there’s just no formatting for it here)
Instead gets returned like this:
BBoolldd text with _u_n_d_e_r_l_i_n_e
I have a minimal test project at http://cl.ly/052u2z2i2R280T3r1K3c that you can download and run; note the window does nothing; the output gets logged to the Console.
I presume I need to somehow interpret the NSData object manually but I have no idea where to start on that. I’d ideally like to translate it to an NSAttributedString but the first order of business is actually eliminating the duplicates and underscores. Any thoughts?
What is your actual purpose? If you want to show a man page, one option is to convert it to HTML and render it with a Web view.
Parsing
man’s output can be tricky because it is processed bygroffusing a terminal processor by default. This means that the output is tailored to be shown on terminal devices.One alternative solution is to determine the actual location of the man page source file, e.g.
and manually invoke
groffon it with-a(ASCII approximation) and-c(disable colour output), e.g.This will result in an ASCII file without most of the formatting. To generate HTML output,
You can also specify these options in a custom configuration file for
man, e.g. parseman.conf, and tellmanto use that configuration file with the-Coption instead of invokingman -w,gunzip, andgroff. The default configuration file is/private/etc/man.conf.Also, you can probably tailor the output of the terminal device processor by passing appropriate options to
grotty.