#include <iostream>
#include <ncurses.h>
#include <cstring>
#include <chrono>
#include <thread>
usingnamespace std;
int main()
{
char mesg[]="@";
int row,col; /* to store the number of rows and *
* the number of colums of the screen */
int dir = 1;
initscr(); /* start the curses mode */
getmaxyx(stdscr,row,col); /* get the number of rows and columns */
int maxx = col - 3;
col = col - 4;
while(true)
{
werase(stdscr);
if (col == maxx - 1) dir = -1;
if (col == maxx - 4) dir = 1;
col += dir;
mvwprintw(stdscr, row - 1, col, mesg);
refresh();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
/* print the message at the center of the screen */
getch();
endwin();
return 0;
}
It is basically copied tutorial from ncurses with my things added, so sorry for comments.
The program moves around "@" sign - left and right. It works okay when it's like this - maxx = realmaxx - 3. This way, it's printed before line end and works nicely. You can try it out. Command to compile would be:
g++ -std=c++11 -o main main.cpp -lncurses
However, if you change maxx at line 17 to maxx = col, then there's a problem. idk why, but it stops for a moment at edges. I have no idea what's causing it. Any ideas?