jquast / blessed

Blessed is an easy, practical library for making python terminal apps

Home Page:http://pypi.python.org/pypi/blessed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to clear without flickering?

nemecsek69 opened this issue · comments

When clearing the terminal very fast in a loop (every 200 msec) it flickers.
In Curses you can use term.erase() instead of term.clear().
Is there an equivalent command in Blessed?

If I understand you correctly, and we wrote a game of "pong" on the terminal, you print term.clear() before drawing each new frame, and this makes the screen (and probably the ball, too) appear to flicker like candles, very unattractive !

This will definitely flicker, curses doesn't flicker because it doesn't actually clear the screen, it has a "virtual screen" that it manipulates and compares to what was previously drawn -- if we moved the ball by only one column, then it would need only erase one character, and draw one character, it does not need to erase the entire screen.

You can see in example program, https://github.com/jquast/blessed/blob/master/bin/worms.py#L197 that I simply erase precisely what I expect to erase, its quite easy for a "worms" game.

For pong, you could simply draw blank over the old ball before drawing the new. You can also buffer this as a single string, and by printing it at one time as a single print() command, the terminal evaluates it so quickly that you do not notice the flicker.

See ncurses howto article, subsection 2.2.2., "The mysterious refresh()"

http://www.tldp.org/HOWTO/html_single/NCURSES-Programming-HOWTO/#DISSECTION