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

The library can not render some escape codes about positions. #100

Open
mdtrooper opened this issue Nov 29, 2019 · 1 comment
Open

The library can not render some escape codes about positions. #100

mdtrooper opened this issue Nov 29, 2019 · 1 comment
Labels
enhancement This issue/PR relates to a feature request.

Comments

@mdtrooper
Copy link

Hi.

I have a tiny test.

The next code puts a text in the bottom of terminal with urwid:

import urwid

def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()


txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'bottom')
loop = urwid.MainLoop(fill, unhandled_input=exit_on_q)

loop.run()

And it shows in term:

output_in_terminal

And the code to get the output in other python file is:

import os
import fcntl
import subprocess

p = subprocess.Popen(['python3', '/tmp/test00.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

fd = p.stdout.fileno()  
fl = fcntl.fcntl(fd, fcntl.F_GETFL)  
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
fd = p.stderr.fileno()  
fl = fcntl.fcntl(fd, fcntl.F_GETFL)  
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
a = p.stdout.read()

from ansi2html import Ansi2HTMLConverter
conv = Ansi2HTMLConverter()
with open('/tmp/caca.html', 'w') as f: 
    f.write(conv.convert(a.decode('utf8')))
a.decode('utf8')

And the output is:

output_as_html

@mdtrooper
Copy link
Author

The string with the escape codes is

'\x1b7\x1b[?47h\x1b[?1002l\x1b[?1000l\x1b[?1000h\x1b[?1002h\x1b)0\x1b[?25l\x1b[0;39;49m\x1b[H\x1b[1;1H\x1b[0;39;49m\x0f\x1b[K\x1b[2;1H\x1b[0;39;49m\x0f\x1b[K\x1b[3;1H\x1b[0;39;49m\x0f\x1b[K\x1b[4;1H\x1b[0;39;49m\x0f\x1b[K\x1b[5;1H\x1b[0;39;49m\x0f\x1b[K\x1b[6;1H\x1b[0;39;49m\x0f\x1b[K\x1b[7;1H\x1b[0;39;49m\x0f\x1b[K\x1b[8;1H\x1b[0;39;49m\x0f\x1b[K\x1b[9;1H\x1b[0;39;49m\x0f\x1b[K\x1b[10;1H\x1b[0;39;49m\x0f\x1b[K\x1b[11;1H\x1b[0;39;49m\x0f\x1b[K\x1b[12;1H\x1b[0;39;49m\x0f\x1b[K\x1b[13;1H\x1b[0;39;49m\x0f\x1b[K\x1b[14;1H\x1b[0;39;49m\x0f\x1b[K\x1b[15;1H\x1b[0;39;49m\x0f\x1b[K\x1b[16;1H\x1b[0;39;49m\x0f\x1b[K\x1b[17;1H\x1b[0;39;49m\x0f\x1b[K\x1b[18;1H\x1b[0;39;49m\x0f\x1b[K\x1b[19;1H\x1b[0;39;49m\x0f\x1b[K\x1b[20;1H\x1b[0;39;49m\x0f\x1b[K\x1b[21;1H\x1b[0;39;49m\x0f\x1b[K\x1b[22;1H\x1b[0;39;49m\x0f\x1b[K\x1b[23;1H\x1b[0;39;49m\x0f\x1b[K\x1b[24;1H\x1b[0;39;49m\x0fHello World\x1b[K'

@hartwork hartwork added feature enhancement This issue/PR relates to a feature request. labels Feb 3, 2022
@ssbarnea ssbarnea removed the feature label Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue/PR relates to a feature request.
Projects
None yet
Development

No branches or pull requests

3 participants