python VTE Terminal weirdness

Posted by mykhal on Stack Overflow See other posts from Stack Overflow or by mykhal
Published on 2010-05-19T19:24:32Z Indexed on 2010/05/19 19:50 UTC
Read the original article Hit count: 335

i'm trying to use the terminal from python VTE binding (python-vte from debian squeeze) as a virtual terminal emulator (just for ANSI/control chars text processing)

in interactive python console, everything looks (almost) all right:

>>> import vte
>>> term = vte.Terminal()
>>> term.feed("a\nb")
>>> print repr(term.get_text(lambda *a: True).rstrip())
'a\n b'

however, launching this code (little modified) as python script, different result is yielded:

$ python vte_wiredness_1.py 
''

strangely enough, pasting the code back into the (new) interactive python session also yields empty string:

>>> import vte
>>> term = vte.Terminal()
>>> term.feed("a\nb")
>>> print repr(term.get_text(lambda *a: True).rstrip())
''
>>>

first thing caming on my mind was that the only difference between the two cases is the timing - there had to be some delay before get_text. unfortunately, preluding get_text with some seconds sleep did not help

then i thought it has something to do with X window environment. but the results are the same pure linux console (with some warning on missing graphics).

i wonder what causes such an unpredictable behavior (interactive console - pasted vs typed, and it's not the delay.. ant the interactive console has nothing to do with the vte terminal object.. i guess)

can someone explain what is happening? is it possible to use the VTE Term such way?

that the "b" letter in the output is preceded by the space, is another strangeness (all consecutive lines are preceded by more spaces.. looks like I have to send carriage return before the string.)

(the lambda *a: True get_text method argument i'm using is a dummy callback, it's is some SlotSelectedCallback.. for its explanation i'd be grateful as well :) )

© Stack Overflow or respective owner

Related posts about terminal

Related posts about vte