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

Non-Visible Characters Printed with Pager #2185

Open
tonyta opened this issue Apr 16, 2021 · 9 comments · May be fixed by #2207
Open

Non-Visible Characters Printed with Pager #2185

tonyta opened this issue Apr 16, 2021 · 9 comments · May be fixed by #2207
Milestone

Comments

@tonyta
Copy link

tonyta commented Apr 16, 2021

PR #2154 seems to have a regression where non-visible characters are being printed when using a pager. Below are the differences between v0.14.0 and v0.14.1. I'm using Terminal (Version 2.11 (440)) on macOS (11.2.3 (20D91)) and I've tested this with the system version of less (v487) and as well as the latest (v563)

Pry v0.14.1 (current)

Screen Shot 2021-04-16 at 1 59 31 PM

Pry v0.14.0 (previous)

Screen Shot 2021-04-16 at 2 01 31 PM

@justin808
Copy link

It's definitely related to the pager. When there's no page, no ^A^B.

@justin808
Copy link

Is there any workaround?

@quintrino
Copy link

@justin808, I've been using Pry.config.pager = false in my .pryrc which eliminates the extra characters, but obviously disables the pager.

@SilverPhoenix99
Copy link
Contributor

Unfortunately, in Windows, disabling the pager doesn't seem to work against removing the extra characters.

kyrylo added a commit that referenced this issue Jul 3, 2021
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.
```
@kyrylo kyrylo linked a pull request Jul 3, 2021 that will close this issue
@kyrylo
Copy link
Member

kyrylo commented Jul 3, 2021

I published #2207 which should fix the problem. Could you guys give it a try before I merge? I just want to make sure it will consistently work for everyone.

  1. Checkout the branch

     git fetch origin
     git checkout -b 2185-pager-bug-fix origin/2185-pager-bug-fix
    
  2. Then:

    bundle install
    rake pry
    

@SilverPhoenix99
Copy link
Contributor

I've also pushed a version in #2209 that takes a different approach.

kyrylo added a commit that referenced this issue Jul 4, 2021
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.
```
@vikdotdev
Copy link

vikdotdev commented Oct 17, 2021

Had the same issue with ^A^B characters being visible; #2185 (comment) fixes the issue for me.

Looking at #2207 made me come up with a workaround someone can use while this is still not merged. Adding the following to your .pryrc fixes ^A^B being visible:

  ENV['PAGER'] = ' less --raw-control-chars -F -X'

Note the leading space - ' less ...', this is intentional - it omits the regex from lib/pry/pager.rb:135

pager = "less -R -F -X" if pager.strip.empty? || pager =~ /^less\b/

searls added a commit to searls/icloud-dotfiles that referenced this issue Aug 15, 2022
@x-yuri
Copy link

x-yuri commented Nov 9, 2022

I see, so what adds the escapes is pry itself (e.g.). They were added in #2154 (0.14.1) to make them available for use in the pry prompt (#493). But the same helpers are also used by pry to display information. And when the information is passed to the pager (less -R), the escapes are visible.

#2207 tries to fix this by using -r in place of -R. This might be a usable approach, but it depends on what escapes the pager might have to deal with. If only those produced by pry than that might be okay. If one should expect arbitrary escape sequences, then it might mess less up.

#2209 supposedly addresses the other issue, where readline might not support ^A/^B. And Pry.config.escape_prompt makes it not add the escape sequences to the prompt. Not sure about outputting to the pager.

An obvious solution is to simply not add ^A/^B when outputting to the pager. The prompt people want to use the helpers? Give them a separate set of helpers. Am I missing something here?

Workarounds:

  • PAGER=' less -rFX' (thanks vikdotdev)
  • downgrade to '< 0.14.1'
  • change -R to -r manually in lib/pry/pager.rb

@andrehjr
Copy link
Member

andrehjr commented Jan 9, 2023

That's a nice summary of our options @x-yuri !

For pry 1.14.2, I reverted #2154. That change was merged before and it also got reverted (More details on #2235) .. So I went with that for now. We'd still need a better way to deal with prompts.

Right now, it's fine to use 1.14.2.

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 a pull request may close this issue.

8 participants