Search code examples
pythonncursescurses

Python curses blink function doesn't work in gnome-terminal


I am using the python curses library. I am trying to make an asterisk blink using this code win.addstr(6, 4, "*", curses.A_BLINK) However it does not work on gnome terminal. I tried using it on xterm and it works. It also does not work on the recovery shell. How can I make text blink using the curses library or some other method?


Solution

  • You could make a program (whether with curses or even hardcoded) that draws text on the screen and overwrites it with blanks, with a suitable time delay (if it's too short, it annoys people — see PuTTY for an example of that).

    The drawback is that it would "blink" only as long as the program runs, and of course it's a little complicated.

    As a shell script, you could do this:

    • save the stty settings,
    • change the stty settings to prevent output of carriage return (\r) from being converted to \r\n
    • print the text, ended with \r
    • wait a while, e.g., sleep 1
    • print blanks where you wrote text
    • wait a while
    • loop back to the first "print"
    • on exit, restore the stty settings.

    For a curses application - you could make it "blink" by replacing the text, in a similar way. For what it's worth, the xmas example in ncurses-examples uses a combination of window copying and terminal blinking for its animation effects (see C blinkit function and Python translation).