-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses.cpp
More file actions
35 lines (32 loc) · 819 Bytes
/
curses.cpp
File metadata and controls
35 lines (32 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* hello5.c
* purpose bounce a message back and forth across the screen
* compile cc hello5.c -lcurses -o hello5
*/
#include <curses.h>
#include <unistd.h>
#define LEFTEDGE 10
#define RIGHTEDGE 30
#define ROW 10
int main()
{
char message[] = "Hello";
char blank[] = " ";
int dir = +1;
int pos = LEFTEDGE ;
initscr();
clear();
while(1){
move(ROW,pos);
addstr( message ); /* draw string */
move(LINES-1,COLS-1); /* park the cursor */
refresh(); /* show string */
sleep(1);
move(ROW,pos); /* erase string */
addstr( blank );
pos += dir; /* advance position */
if ( pos >= RIGHTEDGE ) /* check for bounce */
dir = -1;
if ( pos <= LEFTEDGE )
dir = +1;
}
}