Top down Python

Chris Angelico rosuav at gmail.com
Wed Feb 12 08:42:11 CET 2014


On Wed, Feb 12, 2014 at 6:05 PM, John Allsup <pydev at allsup.co> wrote:
>     1. Put a nice picture on the background.
>     2. Put a terminal window with, say, 64x20 lines, dead centre.
>     3. Run a simple REPL program written in Python or Ruby within it.
> I do not really want to write any more lines of code than I need to.
> Why do we not have langauges and libraries that can do the above
> with only five lines of code (line 0 == setup, line 4 == cleanup).

#!/bin/sh
xfce4-terminal --geometry=64x20 -x python3

There you are, two lines. :)

Seriously though, what you're asking is deceptively simple yet
incredibly difficult. You're trying to recreate the entire structure
of a terminal emulator or telnet client. I can show you the code for a
MUD client, which does a lot of what you're looking for; in fact, this
one has a REPL inbuilt (not Python or Ruby though):

https://github.com/Rosuav/Gypsum/

That's roughly how much code it takes to make a reasonably usable
replicant of a terminal window. (Some of that is specific to
networking and MUDding, but at very least, window.pike is basically
all about the visuals.) You'll do far better to make use of someone
else's terminal renderer, and just put a desktop background to make
your fancy image. Otherwise, you have to recreate everything - console
output (complete with color, presumably), scrolling, input history
(you can get most of your editing keys easily enough, but you will
need command history), clipboard operations, and somewhere along the
way, performance. Save yourself a whole mess of trouble and just use
your OS-provided terminal program :)

Actually, for what you're looking at, IDLE is probably close to what
you want. You could have a look at how much code it takes to power
IDLE, and/or just use it as is. It's pretty handy; I use it as my
primary interactive Python on Windows.

ChrisA



More information about the Python-list mailing list