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

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

  1. 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 Calderone, Feb 9, 2006
    1. Advertisements

  2. Jean-Paul Calderone

    Ian Ward Guest

    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
    1. Advertisements

  3. Jean-Paul Calderone

    Joel Hedlund Guest

    The code for handling window resizing isn't jumping out at
    (...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:

    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:

    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:
    print current_terminal_size
    Joel Hedlund, Feb 9, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.