2022-07-21

Python curses.flash() work only under certain conditions but theses doesn't seem to be documented

While programming with python curses I've came cross many unpredictable behaviors which I will not discuss here. But for now, among theses issues there is a particular one that bother me and understanding this might help for the other issues.

The following is working fine as long as I don't call stdscr.getkey(). Indeed the screen is flashing every half-second. If I call stdscr.getkey() the screen flash once and only once. Pressing a key and moving forward into the loop doesn't change anything. Why ? I did not find any documentation on flash() and getkey() that could explain what is happening.

#! /usr/bin/env python3

import curses

def test(stdscr):
    import time
    curses.noecho()
    curses.cbreak()
    curses.curs_set(0)
    stdscr.keypad(True)
    
    while True:
        curses.flash()
        time.sleep(0.5)
        # ~ stdscr.getkey()
        
curses.wrapper(test)

Maybe some curses function alter some states in such a way that flash doesn't work anymore ? But how and why ?



No comments:

Post a Comment