[Twisted-Python] Screen clearing in the Manhole

I'm making a manhole service in the usual way: class PF(ServerProtocol): def protocolFactory(*a, **kw): return manhole.Manhole(namespace) realm = manhole_ssh.TerminalRealm() realm.chainedProtocolFactory = PF mh_portal = portal.Portal(realm) mh_portal.registerChecker(checker) manhole_service = TCPServer(0, manhole_ssh.ConchFactory(mh_portal)) manhole_service.startService() and I'd like to print a message when the terminal is opened. This change does it: class PF(ServerProtocol): def protocolFactory(*a, **kw): class Manhole(manhole.Manhole): def connectionMade(self): super(Manhole, self).connectionMade() self.terminal.write('Hello') return manhole.Manhole(namespace) and so does this version, which is better because t.c.i.i.ServerProtocol.connectionMade says it is the place to write messages: class PF(ServerProtocol): def protocolFactory(*a, **kw): return manhole.Manhole(namespace) def connectionMade(self): ServerProtocol.connectionMade(self) self.write('Hello') But in both cases, after the message the screen is cleared by what looks like a form feed, and another prompt is printed. So far I can't find where in the code this happens. Is there a way to print a message and not have it scrolled off the screen? Thanks, Peter.

As to where it happens, look at twisted.conch.recvline.RecvLine.connectionMade() and twisted.conch.insults.insults.TerminalProtocol.makeConnection() You could step on the RecvLine. initializeScreen(), but I have no idea what the side effects are. (And of course if you bypass all or part of it, even if it works now, it's alway subject to future breakage. On Tue, Aug 25, 2015 at 12:27 PM, Peter Westlake <peter.westlake@pobox.com> wrote:
I'm making a manhole service in the usual way:
class PF(ServerProtocol): def protocolFactory(*a, **kw): return manhole.Manhole(namespace)
realm = manhole_ssh.TerminalRealm() realm.chainedProtocolFactory = PF mh_portal = portal.Portal(realm) mh_portal.registerChecker(checker)
manhole_service = TCPServer(0, manhole_ssh.ConchFactory(mh_portal)) manhole_service.startService()
and I'd like to print a message when the terminal is opened. This change does it:
class PF(ServerProtocol): def protocolFactory(*a, **kw): class Manhole(manhole.Manhole): def connectionMade(self): super(Manhole, self).connectionMade() self.terminal.write('Hello') return manhole.Manhole(namespace)
and so does this version, which is better because t.c.i.i.ServerProtocol.connectionMade says it is the place to write messages:
class PF(ServerProtocol): def protocolFactory(*a, **kw): return manhole.Manhole(namespace)
def connectionMade(self): ServerProtocol.connectionMade(self) self.write('Hello')
But in both cases, after the message the screen is cleared by what looks like a form feed, and another prompt is printed. So far I can't find where in the code this happens. Is there a way to print a message and not have it scrolled off the screen?
Thanks,
Peter.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Someone wrote: (Sorry, reply in my mail client doesn't give me an editable text version of the mail. Instead, it is including it as an attachment. I don't know why this happens. I do know from bitter experience that if I don't delete the attachments from my reply, users of brain-dead mail clients (I'm looking at you, Outlook) can't see me reply but just see the attached copy of the original message. So I cut and pasted some context so people know what I'm talking about.)
As to where it happens, look at twisted.conch.recvline.RecvLine.connectionMade() and twisted.conch.insults.insults.TerminalProtocol.makeConnection()
You could step on the RecvLine. initializeScreen(), but I have no idea what the side effects are. (And of course if you bypass all or part of it, even if it works now, it's alway subject to future breakage.
On Tue, Aug 25, 2015 at 12:27 PM, Peter Westlake <peter.westlake@pobox.com> wrote:
I'm making a manhole service in the usual way:
[...]
t.c.r.R.connectionMade() calls self.initializeScreen(), which in turn calls self.terminal.reset() I'm pretty sure s.t.reset() is actually twisted.conch.insults.reset(), which has a bug (or an undesirable feature), it sends a "hard reset" escape sequence to the terminal (<ESC>c). This freaks out many terminal emulators, and real, VT100-compatible terminals, in many different ways. I've tested in Kermit-95, PuTTy, xterm, DECterm (a VT emulator written for DECwindows, DEC's X implementation) and on real DEC VT420 and VT520 terminals. They act differently, but none are pleasant. For example, a VT520 does a power-cycle on the CRT (which takes about 10 seconds), reloads the saved configuration, and (if you have multiple sessions enabled) switches to Session 1. The VT420 and VT520 manuals say about "hard reset", basically, "Don't do that!!" I have a patch to change it to send a soft reset (<ESC>[!p) and to set the terminal into "replace mode" (<ESC>[4l) (sometimes the software thought it was in overstrike mode, but the terminal thought it was in insert mode, with bad results. Ideally, it would set both the software and hardware to what ever mode the user desired. The hard reset would set the terminal to whichever mode was stored in its permanent settings. For a software terminal emulator, it was a dice roll.) Depending on the terminal emulator or physical terminal you are using, this probably explains your symptoms. See ticket # 7514: https://twistedmatrix.com/trac/ticket/7514 -- John Santos Evans Griffiths & Hart, Inc. 781-861-0670 ext 539

Can you remove me please. I am in NO WAY affiliated with your organization. Virus? Walk Tall. J Todd Ulrich m. 416.625.3209 Please excuse brevity as this message sent from my BlackBerry 10 smartphone on the Rogers network. Original Message From: John Santos Sent: Tuesday, August 25, 2015 5:58 PM To: Twisted general discussion Reply To: Twisted general discussion Subject: Re: [Twisted-Python] Screen clearing in the Manhole Someone wrote: (Sorry, reply in my mail client doesn't give me an editable text version of the mail. Instead, it is including it as an attachment. I don't know why this happens. I do know from bitter experience that if I don't delete the attachments from my reply, users of brain-dead mail clients (I'm looking at you, Outlook) can't see me reply but just see the attached copy of the original message. So I cut and pasted some context so people know what I'm talking about.)
As to where it happens, look at twisted.conch.recvline.RecvLine.connectionMade() and twisted.conch.insults.insults.TerminalProtocol.makeConnection()
You could step on the RecvLine. initializeScreen(), but I have no idea what the side effects are. (And of course if you bypass all or part of it, even if it works now, it's alway subject to future breakage.
On Tue, Aug 25, 2015 at 12:27 PM, Peter Westlake <peter.westlake@pobox.com> wrote:
I'm making a manhole service in the usual way:
[...]
t.c.r.R.connectionMade() calls self.initializeScreen(), which in turn calls self.terminal.reset() I'm pretty sure s.t.reset() is actually twisted.conch.insults.reset(), which has a bug (or an undesirable feature), it sends a "hard reset" escape sequence to the terminal (<ESC>c). This freaks out many terminal emulators, and real, VT100-compatible terminals, in many different ways. I've tested in Kermit-95, PuTTy, xterm, DECterm (a VT emulator written for DECwindows, DEC's X implementation) and on real DEC VT420 and VT520 terminals. They act differently, but none are pleasant. For example, a VT520 does a power-cycle on the CRT (which takes about 10 seconds), reloads the saved configuration, and (if you have multiple sessions enabled) switches to Session 1. The VT420 and VT520 manuals say about "hard reset", basically, "Don't do that!!" I have a patch to change it to send a soft reset (<ESC>[!p) and to set the terminal into "replace mode" (<ESC>[4l) (sometimes the software thought it was in overstrike mode, but the terminal thought it was in insert mode, with bad results. Ideally, it would set both the software and hardware to what ever mode the user desired. The hard reset would set the terminal to whichever mode was stored in its permanent settings. For a software terminal emulator, it was a dice roll.) Depending on the terminal emulator or physical terminal you are using, this probably explains your symptoms. See ticket # 7514: https://twistedmatrix.com/trac/ticket/7514 -- John Santos Evans Griffiths & Hart, Inc. 781-861-0670 ext 539

On Tue, 25 Aug 2015, at 23:58, John Santos wrote: ...
t.c.r.R.connectionMade() calls self.initializeScreen(), which in turn calls self.terminal.reset()
I'm pretty sure s.t.reset() is actually twisted.conch.insults.reset(), which has a bug (or an undesirable feature), it sends a "hard reset" escape sequence to the terminal (<ESC>c). This freaks out many terminal emulators, and real, VT100-compatible terminals, in many different ways. ... Depending on the terminal emulator or physical terminal you are using, this probably explains your symptoms.
See ticket # 7514: https://twistedmatrix.com/trac/ticket/7514
This does sound like a scary bug, especially on a real terminal, but I tried your patch and it didn't affect my symptom of the screen being cleared again. That's more about "when" rather than "how". Peter.

I found it! Manhole.terminalSize, inherited from RecvLine, does self.terminal.eraseDisplay(). t.c.manhole_ssh.TerminalSessionTransport.__init__ calls terminalSize *after* makeConnection. Since setting the terminal size is a sensible thing to do, and it can't be done before the connection is made, I'm not sure that much can be done about this. I was able to make my message stay visible by overriding terminalSize with a version that didn't erase, but that isn't very clean or general. Peter.

On Tue, 25 Aug 2015, at 22:26, Brian Costlow wrote:
As to where it happens, look at twisted.conch.recvline.RecvLine.connectionMade() and twisted.conch.insults.insults.TerminalProtocol.makeConnection()
My subclass of Manhole first calls Manhole.connectionMade, which calls HistoricRecvLine.connectionMade, which calls RecvLine.connectionMade, which resets the screen exactly as you say. Then, after the screen has been reset, I print the message. But then the screen is cleared a second time! Peter.
participants (4)
-
Brian Costlow
-
J Todd Ulrich
-
John Santos
-
Peter Westlake