Giter Club home page Giter Club logo

Comments (9)

BurntSushi avatar BurntSushi commented on May 22, 2024 1

Yup, I can reproduce it. Setting TERM=screen.linux was key.

from ripgrep.

BurntSushi avatar BurntSushi commented on May 22, 2024

N.B. When I'm in a screen session, if I do TERM=xterm rg -p foo | less -R then things appear to work. When TERM=screen, I see the same ^0 characters as the OP. I wonder if it's a bug in the term library I'm using.

from ripgrep.

balta2ar avatar balta2ar commented on May 22, 2024

Same here (ArchLinux, tmux 2.2, rg 0.2.1). In tmux my $TERM is screen-256color, but running TERM=xterm rg temp | less helps.

from ripgrep.

uazu avatar uazu commented on May 22, 2024

Yes, I can work around it. ^O is shift-in, i.e. switch to non-graphic character set, so may be part of a generic "reset" sequence. As I need to add --color always to use with less, I need to put a wrapper script around it anyway so I'll add TERM=whatever there. Perhaps it only needs documenting. However if there was a way to just reset colours without also resetting character set that might avoid confusion.

from ripgrep.

BurntSushi avatar BurntSushi commented on May 22, 2024

@uazu Ah thanks for the explanation. I think other tools seem to work fine, so we should try to fix it. Documenting it as a known bug in the README is also a good idea. By the way, you may also be interested in the -p/--pretty flag. :-)

from ripgrep.

Screwtapello avatar Screwtapello commented on May 22, 2024

According to less(1), the -R option tells less to assume all sequences of the form ESC [ ... m are zero-width, and pass them through verbatim. ^O is not of that form, so less makes it printable. But where does the ^O come from?

Looking at the terminfo database entry for screen, we see:

$ infocmp -1 screen | grep sgr0
    sgr0=\E[m\017,

...so whenever ripgrep calls .reset(), the term crate looks up the sequence associated with sgr0 ("set graphical rendition to 0" i.e. all fancy things turned off), the terminfo database for screen defines sgr0 to be "ESC [ m ^O" and so that's what gets written to the screen.

If there's a bug here, I'd say it's in less for half-assing its escape-sequence passthrough.

from ripgrep.

uazu avatar uazu commented on May 22, 2024

Well, I now have a wrapper around ripgrep which sets TERM=xterm and pipes to less and everything is fine (and I use ripgrep all the time now -- Thanks!). However, maybe using the 'reset' (sgr0) sequence in this application is overkill, since you don't need to reset everything, but rather just the colours. If there is some other terminfo string that can be used for that then the problem is avoided. Otherwise the TERM=xterm workaround needs to be documented, since I'm sure some other people will want to use ripgrep with less on screen.

from ripgrep.

Screwtapello avatar Screwtapello commented on May 22, 2024

sgr0 is definitely the canonical way to do it. And it's not just colours - ripgrep also makes some text bold.

from ripgrep.

kaushalmodi avatar kaushalmodi commented on May 22, 2024

Thanks. I confirm the fix.

from ripgrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.