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

Use -r with less for help output #391

Merged
merged 1 commit into from
Oct 8, 2013
Merged

Use -r with less for help output #391

merged 1 commit into from
Oct 8, 2013

Conversation

ianw
Copy link

@ianw ianw commented Oct 2, 2013

groff outputs control characters which less will display escaped by
default. Since it's all safe (non-cursor moving) commands like bold,
underline, etc., by default allow less to process them with -r

less-non-escaped

@jamesls
Copy link
Member

jamesls commented Oct 3, 2013

Not opposed to this, but I want to make sure I understand what's going on. I can only reproduce this issue on fedora. I have no issues on Mac/Ubuntu. From what I can tell, the output of groff is different on fedora.

This is the hexdump of the output from mac/ubuntu: https://gist.github.com/jamesls/9eba11c743d06eb58a5b
This is the hexdump of the output of fedora: https://gist.github.com/jamesls/47192d526c39aad83b37

I'm not intimately familiar with fedora, so I'm not sure why there's a difference. Perhaps the easiest way to fix this is to just change the default pager, but I wonder if there's a way to get uniform groff output across the linux platforms. I did verify that if I take the output from aws help on ubuntu and feed it to less on fedora, that the help text is rendered properly.

@ianw
Copy link
Author

ianw commented Oct 4, 2013

After some digging, I found that Debian ships /etc/groff/man.local that disables use of SGR escape codes (ANSI colors, the things that mess up the output) for man pages. Presumably OSX does similar.

In this case, we see in your hexdump it falling back to the "old" way of using a backspace and repeating the character.

the grotty man page says

For SGR support, it is necessary to use the -R option of less(1) to disable the interpretation of grotty's old output format. Consequently, all programs which use less
as the pager program have to pass this option to it. For man(1) in particular, either add -R to the $PAGER environment variable, e.g.

So it seems passing -r to less gives maximum compatibility. For Debian/Ubuntu/OSX that are using the backspace method, the -r doesn't affect things. For Fedora (and anyone else whose grotty outputs SGR codes) it looks correct

The other option is to force grotty to only output the "old" method with "-P-c" to groff. This seems to be what man does on Fedora

16111 execve("/usr/bin/groff", ["groff", "-mtty-char", "-Tutf8", "-mandoc", "-P-c", "-rLL=176n", "-rLT=176n"], [/* 50 vars */] <unfinished ...>

that also probably works everywhere.

@chandanadesilva
Copy link

I posted a support request on AWS for this same problem. Also I found that there is a similar problem with console output.

I have only pasted the last bit from the aws ec2 get-console-output command here:

Verifying : 32:bind-libs-9.8.2-0.17.rc1.29.amzn1.x86_64 6/6 \r\n\r\nUpdated:\r\n bind-libs.x86_64 32:9.8.2-0.17.rc1.30.amzn1 \r\n bind-utils.x86_64 32:9.8.2-0.17.rc1.30.amzn1 \r\n java-1.6.0-openjdk.x86_64 1:1.6.0.0-62.1.11.11.90.55.amzn1 \r\n\r\nComplete!\r\n[ OK ]\r\r\ncloud-init: puppet[ OK ]\r\r\ncloud-init: runcmd[ OK ]\r\r\nMounting other filesystems: [ OK ]\r\r\nRetrigger failed udev events--type=failed is deprecated and will be removed from a future udev release.\r\n[ OK ]\r\r\nGenerating SSH1 RSA host key: [ OK ]\r\r\nStarting sshd: [ OK ]\r\r\nntpdate: Synchronizing with time server: [ OK ]\r\r\nStarting ntpd: [ OK ]\r\r\nStarting sendmail: [ OK ]\r\r\nStarting sm-client: [ OK ]\r\r\nStarting crond: [ OK ]\r\r\nStarting atd: [ OK ]\r\r\nRunning cloud-init user-scriptsSep 16 05:23:05 ip-192-168-100-148 kernel: Kernel logging (proc) stopped.\r\nSep 16 05:23:05 util kernel: imklog 5.8.10, log source = /proc/kmsg started.\r\n[ 128.589483] EXT4-fs (xvdf1): mounted filesystem with ordered data mode. Opts: (null)\r\nSep 16 05:24:10 util kernel: [ 128.589483] EXT4-fs (xvdf1): mounted filesystem with ordered data mode. Opts: (null)\r\n[ OK ]\r\r\n\r\nAmazon Linux AMI release 2013.03\r\nKernel 3.4.43-43.43.amzn1.x86_64 on an x86_64\r\n\r\nutil.ops.mmd login: "

Chandana

@jamesls
Copy link
Member

jamesls commented Oct 4, 2013

Thanks @ianw for the research, much appreciated. While I thought it would be nice to have groff create the same output on all platforms, it doesn't seem like that would help much. Given that fedora users will have to change their PAGER var anyways since groff outputs SGR codes by default, I think changing the default pager seems like the right way to go.

@ianw just want to double check, from your quoted output of the grotty man page, it says to use -R, not -r. Should the default pager be changed to less -R?

@ianw
Copy link
Author

ianw commented Oct 4, 2013

hmm, -R is a restricted version. let's use that

On some platforms, such as Fedora, groff by default outputs control
characters which less will display escaped by default (on other
platforms such as Debian and OSX this is disabled via local
customisations and falls back to the old method of backspacing over
characters).

Using less -R as the pager means that output looks correct in both
cases.
@jamesls
Copy link
Member

jamesls commented Oct 8, 2013

@ianw Thanks for all your help with this.

@jamesls jamesls merged commit a11c03e into aws:develop Oct 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants