Where to insert Python readline?

Gary Bishop gb at cs.unc.edu
Sun May 18 20:06:21 EDT 2003


On Sun, 18 May 2003 18:56:44 -0500 "Chris Gonnerman" 
<chris.gonnerman at newcenturycomputers.net> wrote:
> Sorry about the link; I made a bugfix release but didn't get the
> page updated for it.  Try again, it should work fine.

Got it. Thanks.

> What does the ctypes package have to do with anything, anyway?  I don't
> know about this module, but as far as I can see the only reasonable way
> to use the readline hook is from C.

With ctypes you can do just about anything you could do from C in 
Python. As just a quick, example in order to determine the cursor 
position I say

class COORD(Structure):
  _fields_ = [("X", c_short),
              ("Y", c_short)]

class SMALL_RECT(Structure):
  _fields_ = [("Left", c_short),
              ("Top", c_short),
              ("Right", c_short),
              ("Bottom", c_short)]

class CONSOLE_SCREEN_BUFFER_INFO(Structure):
  _fields_ = [("dwSize", COORD),
              ("dwCursorPosition", COORD),
              ("wAttributes", c_short),
              ("srWindow", SMALL_RECT),
              ("dwMaximumWindowSize", COORD)]

  info = CONSOLE_SCREEN_BUFFER_INFO()
  self.GetConsoleScreenBufferInfo(self.hout, byref(info))

Then I can get the width as info.dwSize.X. I am AMAZED!

gb





More information about the Python-list mailing list