Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Replacing curses (Was: Re: Problem with curses and UTF-8)

Reply
Thread Tools

Re: Replacing curses (Was: Re: Problem with curses and UTF-8)

 
 
Jean-Paul Calderone
Guest
Posts: n/a
 
      02-09-2006
On Wed, 08 Feb 2006 15:10:26 -0500, Ian Ward <(E-Mail Removed)> wrote:
>Grant Edwards wrote:
>> Depending on what you're tring to do, slang might be an option,

>
>I've looked at newt and snack, but all I really need is:
>- a way to position the cursor at (0,0)
>- a way to hide and show the cursor
>- a way to detect when the terminal is resized
>- a way to query the terminal size


You might be interested in Twisted Conch's insults package. I haven't followed this thread closely, so I'm not sure if it covers all your requirements, but it can do all of the above.

Jean-Paul
 
Reply With Quote
 
 
 
 
Ian Ward
Guest
Posts: n/a
 
      02-09-2006
Jean-Paul Calderone wrote:
>> I've looked at newt and snack, but all I really need is:
>> - a way to position the cursor at (0,0)
>> - a way to hide and show the cursor
>> - a way to detect when the terminal is resized
>> - a way to query the terminal size

>
> You might be interested in Twisted Conch's insults package. I haven't
> followed this thread closely, so I'm not sure if it covers all your
> requirements, but it can do all of the above.


Thanks for the pointer! twisted.conch.insult definitely has some of
what I need. The code for handling window resizing isn't jumping out at
me but I'll keep looking.

Ian Ward

 
Reply With Quote
 
 
 
 
Joel Hedlund
Guest
Posts: n/a
 
      02-09-2006
> The code for handling window resizing isn't jumping out at
> me but I'll keep looking.


(...jumping out, rather unexpectedly!)

You might be interested in an ongoing discussion that I and Grant Edwards are holding in this newsgroup on the subject "Best way of finding terminal width/height?".

Thread summary:

There's a function that Chuck Blake wrote for detecting the current terminal size, available here:

http://pdos.csail.mit.edu/~cblake/cls/cls.py

You'll only need the first two functions for this task (ioctl_GWINSZ and terminal_size).

To monitor changes in window size, have a look at the signal module (in standard library). You can attach a monitor function to the signal signal.SIGWINCH, like so:

signal.signal(signal.SIGWINCH, report_terminal_size_change)

or, in context:

-------------------------------------------------------------------
#!/usr/bin/python
from cls import terminal_size

current_terminal_size = terminal_size()

_bTerminalSizeChanged = False

def report_terminal_size_change(signum, frame):
global _bTerminalSizeChanged
_bTerminalSizeChanged = True

def update_terminal_size():
global _bTerminalSizeChanged, current_terminal_size
current_terminal_size = terminal_size()
_bTerminalSizeChanged = False

signal.signal(signal.SIGWINCH, report_terminal_size_change)

while True:
if _bTerminalSizeChanged:
update_terminal_size()
print current_terminal_size
----------------------------------------------------------------------

Take care!
/Joel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
curses and refreshing problem Karlo Lozovina Python 3 12-14-2008 06:14 PM
Problem with curses and UTF-8 Ian Ward Python 30 02-10-2006 08:14 PM
Replacing - and not Replacing... Rob Meade ASP General 5 04-11-2005 06:49 PM
Curses and getch problem spambox@volja.net Perl Misc 11 01-05-2005 08:23 PM
Curses and Events and Other Pierluigi Fabbris Python 0 12-12-2003 08:48 PM



Advertisments