Skip to content

less with -r option causes strange display behavior for input with ANSI control characters #9176

Open

Description

@zachmu

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]: 10.0.19041.0
Windows Terminal version (if applicable): 1.5.10411.0

Any other software?
Ubuntu on WSL 1

Steps to reproduce

Have a long file, in this case produced with git reflog. Examine with less. Notice that output does not include the first ~10 lines.

git reflog > reflog.out
head reflog.out
5240aea1 HEAD@{0}: checkout: moving from zachmu/windows to aaron/indexed-in-subquery-filter
56ac2928 HEAD@{1}: checkout: moving from aaron/indexed-in-subquery-filter to zachmu/windows
5240aea1 HEAD@{2}: checkout: moving from zachmu/windows to aaron/indexed-in-subquery-filter
56ac2928 HEAD@{3}: checkout: moving from aaron/indexed-in-subquery-filter to zachmu/windows
5240aea1 HEAD@{4}: checkout: moving from master to aaron/indexed-in-subquery-filter
1acb0aab HEAD@{5}: pull: Fast-forward
66627818 HEAD@{6}: checkout: moving from zachmu/windows to master
56ac2928 HEAD@{7}: commit: Added some more query tests for window funcs
cb14e839 HEAD@{8}: commit: Working row_number() function
5f08c885 HEAD@{9}: commit: Semi working sort order. Moved more functions and types around to avoid cycles.

less reflog presents me with a screen that starts like this:

rtField up to the sql package and gave it some more methods.
e9c3d6d8 HEAD@{11}: commit: Added window setting to function analysis
98044728 HEAD@{12}: commit: Chalked in outline of adding all rows to a window expression. Now need a way to get Window values into the functions.
d8fcf55e HEAD@{13}: commit: Sketched out an iter
000efaba HEAD@{14}: commit: Chalked out a window node. This involved moving some Sort related types out of the plan package to the expression package
66627818 HEAD@{15}: checkout: moving from master to zachmu/windows

As you can see, the first ~10 lines of the file are not there. If I press the up arrow, less does not respond (chimes the bell). If I press the down arrow key twice, then the up arrow key twice, I see this:

5240aea1 HEAD@{0}: checkout: moving from zachmu/windows to aaron/indexed-in-subquery-filter
56ac2928 HEAD@{1}: checkout: moving from aaron/indexed-in-subquery-filter to zachmu/windows
98044728 HEAD@{12}: commit: Chalked in outline of adding all rows to a window expression. Now need a way to get Window values into the functions.
d8fcf55e HEAD@{13}: commit: Sketched out an iter

Something very strange is happening with the display buffering here. I've noticed this on other invocations of less as well, not just when examining this particular file.

Expected behavior

When less is invoked the terminal should contain the first page of text from the input. Instead, it's starting about 10 lines in.

Actual behavior

As described above

Activity

  1. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Feb 15, 2021
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Feb 15, 2021
  3. DHowett commented on Feb 15, 2021

    @DHowett
    Member

    Do you have anything in your startup scripts that would change the size of the console window (MODE CON LINES=, $Host.UI.RawUI.WindowSize=, stty, printf "\e[..........t", etc.?)

  4. zachmu commented on Feb 15, 2021

    @zachmu
    Author

    Good question!

    Digging through my .zshrc, it appears this line is the culprit:

    export LESS=-r

    Unsetting this var fixes the issue. Presumably triggered by ANSI color codes in the output of various git commands where I've noticed this?

    I don't know if this is a windows terminal problem or not. I do know I've had that line in my .zshrc for over a decade and never noticed a problem before using windows terminal.

  5. ghost added
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Feb 15, 2021
  6. ghost removed
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    on Feb 15, 2021
  7. DHowett commented on Feb 15, 2021

    @DHowett
    Member

    Really curious, that. When you remove -r, do you see any control sequences in the less output?

  8. zachmu commented on Feb 15, 2021

    @zachmu
    Author

    Nope, I don't see any printed control sequences in the output.

    I notice that the man page for less has this to say about the -r option:

    •   -r or --raw-control-chars
               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 display problems may result, such as long lines being split  in  the
               wrong place.
      

    So maybe this is the whole of the story? Still not sure if this is a problem with WSL / windows terminal or not.

    For anyone reading, this is the current value of $LESS, which gets rid of the problem for me:

    % echo $LESS
    -F -i -J -M -R -W -x4 -X -z-4
    
  9. added
    Issue-BugIt either shouldn't be doing this or needs an investigation.
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)
    on Feb 16, 2021
  10. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Feb 16, 2021
  11. 2 remaining items

  12. DHowett commented on Feb 17, 2021

    @DHowett
    Member

    Alright, one more thing to troubleshoot.

    Can you get it in a state where it'll reproduce, and then hit me with a script? It should be in the bsdutils package.

    $ script
    < script will spawn a subshell here >
    $ # do the repro
    $ exit
    < script will tell you what file it wrote the output to, usually called "typescript" >
    

    If you're not comfortable sharing typescript publicly, you can send it to my GitHub profile's e-mail address.
    If you're not comfortable sharing typescript privately, you get to pick through it to find what control sequence less is emitting that we're catching and handling.

  13. DHowett commented on Feb 17, 2021

    @DHowett
    Member

    (It'll capture all the unparsed VT coming out of any of its child processes.)

  14. added
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    and removed
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Feb 17, 2021
  15. ghost added
    No-Recent-ActivityThis issue/PR is going stale and may be auto-closed without further activity.
    on Feb 21, 2021
  16. zachmu commented on Feb 22, 2021

    @zachmu
    Author

    Here you go! (zipped because github only accepts certain file types)

    Repro was:

    less reflog.out

    With LESS=-r

    typescript.zip

  17. ghost added
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Feb 22, 2021
  18. ghost removed
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    on Feb 22, 2021
  19. ghost removed
    No-Recent-ActivityThis issue/PR is going stale and may be auto-closed without further activity.
    on Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-AttentionThe core contributors need to come back around and look at this ASAP.Priority-2A description (P2)Product-TerminalThe new Windows Terminal.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions