vterm.Terminal patches to enable easier subclassing
the grugq <the.grugq <at> gmail.com>
2011-11-27 00:46:32 GMT
Hey,
I've been working on an Urwid application that uses the vterm.Terminal widget
and integrates properly with Twisted. I've already submitted some minor patches
to make the raw_display.Screen() object more friendly to subclassing, now I'd
like to get the Terminal() patched as well.
The issue is that Terminal assumes the self.master attribute is a file
descriptor and it will inline calls to os.read()/os.write() on this attribute.
If the attribute is anything other than a file descriptor, it will raise an
exception and die. This makes it convoluted to have the master attribute as a
ProcessProtocol, which is the simplest solution for a Twisted application
subclassing and implementing the Terminal.
The best solution, from my POV, is to have all access to the the self.master
attribute wrapped in method calls which can be overwritten. There are two
options, either make the Terminal widget know how to do I/O on self.master, or
make self.master an object. That is, either:
# original code:
os.write(self.master, buf)
# terminal knows too much, code:
self.write_master(buf)
# I can't believe master's a file(), code:
self.master.write(buf)
In the attached patch I've implemented the latter approach. I promote the master
to a file() object (with disabled buffering and non-blocking enabled, so it
(Continue reading)