Goto XY
Chris F.A. Johnson
cfajohnson at gmail.com
Tue Nov 8 22:33:47 EST 2005
On 2005-11-09, ale.of.ginger at gmail.com wrote:
> Is there some command in python so that I can read a key's input and
> then use a gotoxy() function to move the cursor on screen? e.g.:
> (psuedo-code)
You can use curses, but that may be more trouble than it's worth.
If you don't mind limiting your program to an ANSI-type terminals
(vt100, xterm, rxvt, linux, putty, etc....), then you can just use
the codes to position the cursor:
ESC = '\033'
CSI = ESC + "["
def printat(row,col,arg=""):
sys.stdout.write( CSI + str(row) + ";" + str(col) + 'H' + str(arg))
> When the right arrow is pushed, cursor gotoxy(x+1,y)
To read a single keystroke, see Claudio Grondi's post in the
thread "python without OO" from last January.
Function and cursor keys return more than a single character, so
more work is required to decode them. The principle is outlined in
<http://www.unixreview.com/documents/s=9920/ur0511a/ur0511a.html>;
the code there is for the shell, but translating them to python
should be straightforward. I'll probably do it myself when I have
the time or the motivation.
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
More information about the Python-list
mailing list