Skip to content

Commit

Permalink
pager: fix printing non-visible characters \001 & \002
Browse files Browse the repository at this point in the history
Fixes #2185 (Non-Visible Characters Printed with Page)

The `--raw-control-chars` option (aka `-r`) does the following:

```
Causes "raw" control characters to be displayed.  The default is
to  display  control  characters  using  the caret notation; for
example, a control-A (octal 001) is displayed as "^A".  Warning:
when the -r option is used, less cannot keep track of the actual
appearance of the screen (since this depends on how  the  screen
responds to each type of control character).  Thus, various dis-
play problems may result, such as long lines being split in  the
wrong place.
```

The `--RAW-CONTROL-CHARS` option was always used with the pager, I just expanded
it from `-R`, so that it looks more descriptive. For reference, it does the
following:

```
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.   You
can  make less think that characters other than "m" can end ANSI
color escape  sequences  by  setting  the  environment  variable
LESSANSIENDCHARS to the list of characters which can end a color
escape sequence.  And you can make less  think  that  characters
other  than the standard ones may appear between the ESC and the
m by setting the environment variable  LESSANSIMIDCHARS  to  the
list of characters which can appear.
```
  • Loading branch information
kyrylo committed Jul 4, 2021
1 parent 7a2284f commit 120afab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@

* Fixed bug where reading from the `_out_` sticky local variable could return
wrong results ([#2201](https://github.com/pry/pry/pull/2201))
* Fixed bug where paged output can erroneously display non-visible control
characters (`\001` aka `^A` & `\002` aka `^B`)
([#2207](https://github.com/pry/pry/pull/2207))

### [v0.14.1][v0.14.1] (April 12, 2021)

Expand Down
8 changes: 5 additions & 3 deletions lib/pry/pager.rb
Expand Up @@ -8,6 +8,9 @@ class Pager
class StopPaging < StandardError
end

# @return [String] the 'less' executable and its options
LESS_PAGER = 'less --RAW-CONTROL-CHARS --raw-control-chars -F -X'

attr_reader :pry_instance

def initialize(pry_instance)
Expand Down Expand Up @@ -130,9 +133,8 @@ class SystemPager < NullPager
def self.default_pager
pager = Pry::Env['PAGER'] || ''

# Default to less, and make sure less is being passed the correct
# options
pager = "less -R -F -X" if pager.strip.empty? || pager =~ /^less\b/
# Default to less.
pager = LESS_PAGER if pager.strip.empty? || pager =~ /^less\b/

pager
end
Expand Down

0 comments on commit 120afab

Please sign in to comment.