I'm a newbie programmer and am currently writing a simple Ncurses application, but i faced such a problem - calling the move
function or mvwadch
as example cleans the window contents after the place i'm moving to.
The code is like:
#include <string>
#include <ncurses.h>
void function(WINDOW* win)
{
std::string somestring = "Test";
waddstr(win, somestring.c_str());
wmove(win , 0, 1);
wrefresh(win);
}
WINDOW* win_ = initscr();
int main()
{
function(win_);
wgetch(win_);
endwin();
}
It leaves only "T", as example, if somestring
is "Test".
P.S. Sorry for possible bad English and c++.
Your program doesn't wait for user input (e.g., a call to getch
) and exits immediately without calling endwin
. Because ncurses initializes the terminal to raw mode, that leaves the terminal in raw mode, making the normal translation of newline to carriage-return/line-feed by your shell not work immediately (though most shells recover from this by resetting the mode back to cooked). That causes some text to be overwritten since (instead of advancing to a newline) the shell prompt is written on the same line as the text-message.