[Twisted-Python] Using twisted.conch.recvline
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
Hello all, I'm trying to figure out how to hook up the necessary classes in twisted.conch.recvline to add line-editing and history to a simple ssh app. It was easy to modify http://twistedmatrix.com/projects/conch/documentation/examples/sshsimpleserv... to use a custom protocol (a simple command-line interface that sends web services requests to a JotSpot wiki), but I can't figure out how recvline is meant to be used. Could someone (Jp?) show me how you'd go about bolting recvline onto sshsimpleserver? Thanks! Abe
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Tue, 31 May 2005 17:52:46 -0400, Abe Fettig <abe@fettig.net> wrote:
In summary, you need: 1) A Realm which produces avatars implementing IConchUser 2) An avatar which also implements or is adaptable to ISession 3) A session which constructs a twisted.conch.insults.insults.ServerProtocol in openShell, and connects it to a transport 4) A protocol class which subclasses one of the recvline protocol classes, passed as the first argument to ServerProtocol If you hook all these pieces up right, the protocol class you give to ServerProtocol should end up receiving application-level data from your ssh server, and its terminal attribute will be hooked up to send bytes back. Note that this API may not be stable. There's an example of all this smeared across doc/conch/examples/demo_recvline.py and twisted/conch/manhole_ssh.py. The API presented by manhole_ssh.py is definitely not stable. Jp
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
Jp Calderone wrote:
I've done this, and it's working in my example the same way as it does in demo_recvline.py. It's a much nicer environment than my original: backspace works, arrows work, you can scroll up and down through command history. Yippee! But there's a problem, both in my code and in demo_recvline.py: when you get to the bottom of the terminal it doesn't scroll. All the lines just get pasted over each other on the bottom line of the terminal. I'm clueless about terminal programming: generally I just know that I can dump a bunch of text and the terminal will scroll. But now it doesn't. Can you help me fix this? Once I get this all working, I'll post a modified simplesshserver.py for the benefit of others who might want a working line editing and history for their custom protocol. Thanks! Abe
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Jun 2, 2005, at 12:44 AM, Abe Fettig wrote:
I know way too much about terminal programming, and can immediately identify the problem as the use of "ESC E". Never ever use ESC E, it's worthless. While I'm at it: never use ESC D, and really try not to use ESC M either. They're all mostly unused and people who don't care about correctness, only "working for unix termcap" don't bother implementing them right. Use instead \r\n, \n, and ESC[A (not quite the same thing, as it doesn't do a backwards scroll, but if you think backwards scrolling is going to work, I've got this bridge to sell you...). Anyhow, could you say which horribly broken terminal program you're using? I like to keep track of these things. From what I can tell, the authors of most of the terminal emulators out there must have never even bothered to read the documentation for the terminals they claim to emulate... James
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
James Y Knight wrote:
Thanks, it worked! I changed the nextLine() method of insults.ServerProtocol to use \r\n: class PatchedServerProtocol(insults.ServerProtocol): def nextLine(self): self.cursorPos.x = 0 self.cursorPos.y = min(self.cursorPos.y + 1, self.termSize.y - 1) self.transport.write('\r\n') # this is the only change Is this something that should be fixed in insults? I can submit a patch to the bug tracker.
gnome-terminal 2.10 Thanks! Abe
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
On Tue, 31 May 2005 17:52:46 -0400, Abe Fettig <abe@fettig.net> wrote:
In summary, you need: 1) A Realm which produces avatars implementing IConchUser 2) An avatar which also implements or is adaptable to ISession 3) A session which constructs a twisted.conch.insults.insults.ServerProtocol in openShell, and connects it to a transport 4) A protocol class which subclasses one of the recvline protocol classes, passed as the first argument to ServerProtocol If you hook all these pieces up right, the protocol class you give to ServerProtocol should end up receiving application-level data from your ssh server, and its terminal attribute will be hooked up to send bytes back. Note that this API may not be stable. There's an example of all this smeared across doc/conch/examples/demo_recvline.py and twisted/conch/manhole_ssh.py. The API presented by manhole_ssh.py is definitely not stable. Jp
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
Jp Calderone wrote:
I've done this, and it's working in my example the same way as it does in demo_recvline.py. It's a much nicer environment than my original: backspace works, arrows work, you can scroll up and down through command history. Yippee! But there's a problem, both in my code and in demo_recvline.py: when you get to the bottom of the terminal it doesn't scroll. All the lines just get pasted over each other on the bottom line of the terminal. I'm clueless about terminal programming: generally I just know that I can dump a bunch of text and the terminal will scroll. But now it doesn't. Can you help me fix this? Once I get this all working, I'll post a modified simplesshserver.py for the benefit of others who might want a working line editing and history for their custom protocol. Thanks! Abe
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Jun 2, 2005, at 12:44 AM, Abe Fettig wrote:
I know way too much about terminal programming, and can immediately identify the problem as the use of "ESC E". Never ever use ESC E, it's worthless. While I'm at it: never use ESC D, and really try not to use ESC M either. They're all mostly unused and people who don't care about correctness, only "working for unix termcap" don't bother implementing them right. Use instead \r\n, \n, and ESC[A (not quite the same thing, as it doesn't do a backwards scroll, but if you think backwards scrolling is going to work, I've got this bridge to sell you...). Anyhow, could you say which horribly broken terminal program you're using? I like to keep track of these things. From what I can tell, the authors of most of the terminal emulators out there must have never even bothered to read the documentation for the terminals they claim to emulate... James
![](https://secure.gravatar.com/avatar/6cd37343ce1da139b1d2ff5ee717f5d5.jpg?s=120&d=mm&r=g)
James Y Knight wrote:
Thanks, it worked! I changed the nextLine() method of insults.ServerProtocol to use \r\n: class PatchedServerProtocol(insults.ServerProtocol): def nextLine(self): self.cursorPos.x = 0 self.cursorPos.y = min(self.cursorPos.y + 1, self.termSize.y - 1) self.transport.write('\r\n') # this is the only change Is this something that should be fixed in insults? I can submit a patch to the bug tracker.
gnome-terminal 2.10 Thanks! Abe
participants (4)
-
Abe Fettig
-
Itamar Shtull-Trauring
-
James Y Knight
-
Jp Calderone