Coder Social home page Coder Social logo

Comments (14)

bczsalba avatar bczsalba commented on August 15, 2024 1

The sequence actually comes from your terminal! Basically, PTG writes a pixel dimension request, and the terminal has some time (I think 0.1 seconds) to respond. The timing is there to solve an issue where PTG would try to catch sequences that are never written, so it would just get stuck on an endless getch call.

The sensible thing to do here would be the only query the dimensions on demand, so it's not done when not needed. The timeout could also be a bit larger.

from pytermgui.

bczsalba avatar bczsalba commented on August 15, 2024 1

Aw heck. The sequence is the response to use querying the terminal's foreground color, which we need to create an accurate screenshot. Gonna try to look into why the response doesn't get captured.

from pytermgui.

bczsalba avatar bczsalba commented on August 15, 2024 1

That's alright! Let me know if you ever run into it again.

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

I see, thanks for the explanation 🙂
I'd be totally fine with being able to configure the timeout through an env var if this is something you'd consider.

from pytermgui.

bczsalba avatar bczsalba commented on August 15, 2024

Could you check on the latest commit? This should be fixed now.

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

Just checked (pip install using master branch, i.e. commit e523f70): seems to be fixed indeed! Thanks!

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

Hello, I'm having a similar issue again. When I run the following snippet in a subprocess, it prints an ANSI sequence and then gets stuck:

from io import StringIO
import pytermgui as ptg

terminal = ptg.Terminal(stream=StringIO(), size=(80, 16))
ptg.set_global_terminal(terminal)
with terminal.record() as recorder:
    recorder.write(ptg.tim.parse(ptg.highlight_python(code)))
print("before svg")
svg = recorder.export_svg(inline_styles=True)
print("after svg")

Output when running it:

before svg
^[]10;rgb:e4e4/d9d9/c6c6^G

Note that this happens in a mkdocs subprocess, and then in an exec call (I'm working on markdown-exec 😉). Not sure if it really matters.

Do you know to what corresponds this ANSI sequence ^[]10;rgb:e4e4/d9d9/c6c6^G? (and why it's printed on screen?)

from pytermgui.

bczsalba avatar bczsalba commented on August 15, 2024

Hey, is this still an issue? I'm not sure if anything related has changed since then, but in case things are still broken I can look into it.

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

Let me check, I had disabled pytermgui in the meantime :)

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

Still happens, but only when I run the mkdocs command through my task runner (duty) it seems (didn't test extensively), so don't bother too much. I'll try to isolate the real cause when I get some time 🙂

from pytermgui.

bczsalba avatar bczsalba commented on August 15, 2024

Ever figure it out? :)

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

Nope, sorry 😕

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

So it's still happening. The crux of the issue is probably that I'm capturing the output, preventing PyTermGUI to read it it itself when querying the terminal for the foreground color, so it blocks. The sequence I'm seeing: ^[]11;rgb:1212/1919/0d0d^[\. I'm capturing output at the file descriptor level: https://github.com/pawamoy/failprint/blob/3d1317dc9f663719bab381c1f39fe54cda308d3f/src/failprint/capture.py#L78.

Ideally, PyTermGUI wouldn't block thanks to a read timeout or something 🙂 I'm trying to think of something for disabling it when capturing the output (when I'm checking if the docs build correctly), but I don't see yet how I could disable just a paragraph in one my Markdown pages 🤔

from pytermgui.

pawamoy avatar pawamoy commented on August 15, 2024

OK found a workaround, I'm adding this at the top of the PyTermGUI snippet:

import os  # markdown-exec: hide
for envvar in ("PYTHON_VERSIONS", "CI", "MULTIRUN"):  # markdown-exec: hide
    if envvar in os.environ:  # markdown-exec: hide
        print(  # markdown-exec: hide
            "PyTermGUI blocks when querying the terminal foreground color with an ANSI sequence "  # markdown-exec: hide
            "because we capture the output ourselves through `failprint`, "  # markdown-exec: hide
            "so this gallery example is disabled in CI.",  # markdown-exec: hide
        )  # markdown-exec: hide
        raise SystemExit(0)  # markdown-exec: hide

from pytermgui.

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.