Bug 8186

Summary: less: add -r/-R support for handling of raw ansi control codes
Product: Busybox Reporter: Mingye Wang <arthur200126>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: enhancement CC: busybox-cvs, holger
Priority: P5    
Version: 1.23.x   
Target Milestone: ---   
Hardware: All   
OS: All   
Host: Target:
Build:
Attachments: [PATCH 1/2] less: add support for -R option
[PATCH 2/2] less: accept the command line options from the environment variable

Description Mingye Wang 2015-06-28 10:59:57 UTC
When busybox is configured to ENABLE_LESS, running `busybox man docs/busybox.1` creates output with lots of escaped ANSI escape sequences like `\e[1m`.

The commonly-used full version of less, less 458 from www.greenwoodsoftware.com/less, has an option -R which asks less to output raw ANSI color chars:

>       -R or --RAW-CONTROL-CHARS
>              Like  -r,  but  only ANSI "color" escape sequences are output in
>              "raw" form.  Unlike -r, the screen appearance is maintained cor-
>              rectly  in  most  cases.   ANSI  "color"  escape  sequences  are
>              sequences of the form:
>
>                   ESC [ ... m
>
>             where the "..." is zero or more color  specification  characters
>             For  the  purpose  of  keeping  track of screen appearance, ANSI
>             color escape sequences are assumed to not move the cursor...

But busybox less doesn't support such thing at all.

Extra info:

Working mans:

    PAGER='less -R' busybox man docs/busybox.1
    PAGER='more' busybox man docs/busybox.1
    PAGER='busybox more' busybox man docs/busybox.1

Failing mans:

    PAGER='less' busybox man docs/busybox.1
    PAGER='busybox less' busybox man docs/busybox.1
Comment 1 Mingye Wang 2015-06-28 12:02:57 UTC
Additions:

Working:

    PAGER=less man docs/busybox.1

Failing

    PAGER='busybox less' man docs/busybox.1

It seems that man-db has some special handling for less.
Comment 2 Mike Frysinger 2016-02-18 07:02:07 UTC
*** Bug 5546 has been marked as a duplicate of this bug. ***
Comment 3 Lubomir Rintel 2018-01-22 12:19:07 UTC
Created attachment 7436 [details]
[PATCH 1/2] less: add support for -R option
Comment 4 Lubomir Rintel 2018-01-22 12:19:43 UTC
Created attachment 7441 [details]
[PATCH 2/2] less: accept the command line options from the  environment variable
Comment 5 Lubomir Rintel 2018-01-22 12:20:41 UTC
A cover letter that I sent to the list before it rejected my message:

Hi,

chained are two patches that add make the less applet behave well with
tools that use coloring and paging at the same time. My first busybox
patches, so I beg for some understanding if I didn't get things right.

Issues have been reported for nmcli, systemd and git upstreams (perhaps
more) all of the falling victim to a rather reasonable assumption that
a thing called "less" behaves like "less" (in support of "-R" option
in particular). I guess the implausibility of teaching all of the
affected tools to do some sort of capability assessment of pager's
capabilities justifies the slight growth in the applet size.

An alternative way would be to use the "more" applet instead somehow.
All of the afforementioned tools prefer "less" over "more" for obvious
reasons, but perhaps the busybox applet could just dispatch to "more" if
it sees a "LESS" environment variable with options it doesn't
understand. "more" works well with ANSI control sequences, at the cost
of not being able to scroll backwards.

Thank you,
Lubo
Comment 6 Denys Vlasenko 2018-01-22 14:23:04 UTC
Added support to -R and $LESS in git