Telnet client using curses

P.J.W.S. Vrijlandt P.J.W.S.VRIJLANDT at INT.azg.nl
Wed Apr 19 04:39:35 EDT 2000


On 19 Apr 00 at 1:53, Aquarius wrote:

> Having used Python for a few brief scripts (the sort of thing I used
> to use Perl for :), I thought I'd try something a bit more
> ambitious, to teach myself the language. What I decided on, because
> I need one, is a telnet client. The key thing is that I'd like to
> use curses to give me one input line into which text it typed, while
> data returned from the connection goes into the window above.
> Something like TinyFugue.
> 
> Looking at telnetlib, it uses select to poll stdin. However, I'll be
> getting user input using curses input functions, not input() or
> raw_input(), so the user input doesn't go into stdin. Is the best
> way to handle this: 1. get user input with the curses function and
> then somehow slip this input into stdin, so it looks like it came
> from raw_input() or whatever? Obviously, raw_input() gets its data
> into stdin, but it's a built-in function, so I don't know how it
> does it :-) 2. write a file object which I feed data *into* from the
> curses input function, and which then feeds that data back out when
> requested to do so, and poll *that* instead of stdin? 3. A better
> solution?
> 
> If your answer is "3", some kind of suggestion as to the Right Way
> to do it would be appreciated :-)
> 
> Aquarius
> 
> -- 
> Well *done*, Aquarius -- a phrase we love typing because it makes us
> feel like the boss-character from a 1980s Glen A Larson action
> series...
>   NTK,
>   http://www.ntk.net/index.cgi?back=archive99/now0618.txt&line=292#l
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list

I would opt for "3". The Right Thing (tm) requires 
rewriting/modifying of telnetlib in order to seperate the terminal 
functions from the protocol handling, like it was intended in de rfc.

I have done such a thing and I will mail it to you privately when I'm 
home  (it's not ready for publication). 

You then get a TTY object with read and write methods and you can use 
it as you like. On windows, you can't use select with stdin and you 
have to use seperate threads for input and output to get an elegant 
solution.

The elegance of this solution is that you don't have to modify 
telnetlib again if you want to write logfiles or implement a terminal 
that uses another gui instead of curses.

Patrick Vrijlandt






More information about the Python-list mailing list