diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2021-07-03 11:12:37 +0300 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2021-07-04 23:06:06 +0300 |
commit | 120afabc4154cb21328f64a2086a202f80213870 (patch) | |
tree | 659d9e28f4707f8d7938fb9241232457a9470323 | |
parent | 7a2284f8a74bca3489e780769325c2b44619991b (diff) | |
download | pry-2185-pager-bug-fix.tar.gz |
pager: fix printing non-visible characters `\001` & `\002`2185-pager-bug-fix
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.
```
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | lib/pry/pager.rb | 8 |
2 files changed, 8 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 65ec4029..9644ec38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/pry/pager.rb b/lib/pry/pager.rb index e6e40898..fba881bc 100644 --- a/lib/pry/pager.rb +++ b/lib/pry/pager.rb @@ -8,6 +8,9 @@ class Pry 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) @@ -130,9 +133,8 @@ class Pry 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 |