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

Discussion in 'Python' started by Jean-Paul Calderone, Feb 9, 2006.

  1. On Wed, 08 Feb 2006 15:10:26 -0500, Ian Ward <> 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
     
    Jean-Paul Calderone, Feb 9, 2006
    #1
    1. Advertising

  2. Jean-Paul Calderone

    Ian Ward Guest

    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
     
    Ian Ward, Feb 9, 2006
    #2
    1. Advertising

  3. Jean-Paul Calderone

    Joel Hedlund Guest

    > 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
     
    Joel Hedlund, Feb 9, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike

    Replacing utf-8 characters

    Mike, Oct 5, 2005, in forum: Python
    Replies:
    8
    Views:
    504
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Oct 5, 2005
  2. Ian Ward

    Problem with curses and UTF-8

    Ian Ward, Feb 7, 2006, in forum: Python
    Replies:
    30
    Views:
    1,844
    Ian Ward
    Feb 10, 2006
  3. Replies:
    1
    Views:
    401
    Andrey
    Jul 21, 2007
  4. jmfauth
    Replies:
    4
    Views:
    340
    jmfauth
    Oct 13, 2010
  5. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    299
    Chris Hohmann
    Apr 11, 2005
Loading...

Share This Page