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

ANSI escape sequences in captured output #35

Closed
magixx opened this issue Aug 20, 2015 · 4 comments
Closed

ANSI escape sequences in captured output #35

magixx opened this issue Aug 20, 2015 · 4 comments

Comments

@magixx
Copy link

magixx commented Aug 20, 2015

Using cygwin and python/plumbum I am noticing that I'm getting ANSI escape sequences in my output such as '\x1b[?25l\r\x1b[2K\x1b[0m\r\n\x1b[2K'. Is there a way to hide this reliably? I've not notice any such issue with proxywinconsole.

@rprichard
Copy link
Owner

I'm curious as to why you need to suppress the ANSI escape sequences. Normally they're interpreted by a terminal emulator, so you don't see them.

There is a "console mode" in libwinpty that suppress some/all sequences, but IIRC, there's no way to enable it from console.exe. I'm not sure what it's intended use is. (I didn't probe very much when it was contributed.)

winpty uses cursor-up and erase-line commands to backtrack in the terminal when parts of the console change. (e.g. full-screen editors, progress bars, REPLs). I'm not sure how winpty is useful if those commands are suppressed.

@rprichard
Copy link
Owner

Can you explain what you're doing where you're seeing the unwanted escape sequences?

winpty does output a lot of escape sequences, and some of them can be suppressed:

  • If you aren't interested in e.g. colors or cursor position/visibility, then winpty can have a flag for disabling that information.
  • winpty can be smarter about appending to the current line. Currently, it always redraws lines from scratch, and it resets the cursor position before doing so.

If you absolutely cannot tolerate any escape sequences, then winpty has a "console mode" that's relevant, but all that does now is suppress escape sequences, so in principle, it can output a lot of junk.

I need more information to do anything with this issue; otherwise, I'll just close it.

@rprichard
Copy link
Owner

I'm not sure what this issue is about. winpty is designed to output escape sequences normally. The console mode in master is much improved now. The winpty.exe adapter has an undocumented -Xplain switch you can use to see what console mode would output.

I'm going to close this issue.

@jagannatharjun
Copy link

I needed to catch child's input and output and using winpty for unbuffered io from child
I am using a slightly modified version of this
winpty\src\tests\trivialtest.cc:

static std::vector<unsigned char> filterContent(
        const std::vector<unsigned char> &content) {
    std::vector<unsigned char> result;
    auto it = content.begin();
    const auto itEnd = content.end();
    while (it < itEnd) {
        if (*it == '\r') {
            // Filter out carriage returns.  Sometimes the output starts with
            // a single CR; other times, it has multiple CRs.
            it++;
        } else if (*it == '\x1b' && (it + 1) < itEnd && *(it + 1) == '[') {
            // Filter out escape sequences.  They have no interior letters and
            // end with a single letter.
            it += 2;
            while (it < itEnd && !isalpha(*it)) {
                it++;
            }
            it++;
        } else {
            // Let everything else through.
            result.push_back(*it);
            it++;
        }
    }
    return result;
}

is there any other way to do it from winpty.exe

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

No branches or pull requests

3 participants