How how to delete text to end of line ?
stdscr.addstr(5, 5, "Egestas Curabitur Phasellus magnis")
result screen: Egestas Curabitur Phasellus magnis
# OK
stdscr.addstr(5, 5, "Elit metus")
result screen: Elit metusrabitur Phasellus magnis
# Problem
To delete to the EOL (End Of Line) use window.clrtoeol()
:
Example:
import curses
window = curses.initscr()
window.clrtoeol()
window.refresh()
I really recommend the use of the great urwid for any console/TUI programming however.
Update: Bhargav Rao is right however; you have to call window.refresh()
explicitly:
Accordingly, curses requires that you explicitly tell it to redraw windows, using the refresh() method of window objects. In practice, this doesn’t really complicate programming with curses much. Most programs go into a flurry of activity, and then pause waiting for a keypress or some other action on the part of the user. All you have to do is to be sure that the screen has been redrawn before pausing to wait for user input, by simply calling stdscr.refresh() or the refresh() method of some other relevant window.
You need to call stdscr.refresh()
before your second line of code. This is made clear in the documentation
All you have to do is to be sure that the screen has been redrawn before pausing to wait for user input, by simply calling
stdscr.refresh()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With