Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete text to end of line with curses

Tags:

python

curses

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

like image 406
Ing Dedek Avatar asked May 15 '15 11:05

Ing Dedek


2 Answers

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.

like image 86
James Mills Avatar answered Sep 19 '22 08:09

James Mills


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()

like image 29
Bhargav Rao Avatar answered Sep 22 '22 08:09

Bhargav Rao