0.helloWorld
// g++ 001-hello-world.cpp -lcurses
#include <ncurses.h>
using namespace std;
int main()
{
// set up memory and clears the screen
initscr();
// print a s string(const char*) to a window
printw("hello world!");
// refreshes the screen to mactach what is memory
// what's for user input,return int value of that key
int c = getch();
printw("%d", c);
getch();
// deallocates memory and end ncurses
endwin();
return 0;
}
1.movingCurses
#include <ncurses.h>
using namespace std;
int main()
{
// initialize the screen
// set up memory and clears the screen
initscr();
int x, y;
x = y = 10;
// move the cursor to the specified location
move(y, x);
// print a s string(const char*) to a window
printw("hello world!");
// what's for user input,return int value of that key
int c = getch();
clear();
// move(0, 0);
// printw("%d", c);
mvprintw(0, 0, "%d", c);
// move(0, 0);printw("%d", c); == mvprintw(0,0,"%d", c);
refresh();
getch();
// deallocates memory and end ncurses
endwin();
return 0;
}
2-3Window&Borders
#include <ncurses.h>
using namespace std;
int main()
{
// initialize the screen
// set up memory and clears the screen
/* NCURSES START */
initscr();
//cbreak(); // sensitive to signal ctl+C,default
raw(); // insensitive to signal ctl+C
// noecho(); // not echo the content that users input
int height, width, start_y, start_x;
height = 10;
width = 20;
start_y = start_x = 10;
WINDOW *win = newwin(height, width, start_y, start_x);
refresh();
//box(win, 0, 0);
//box(win, 103, 103);
//box(win, 103, 104);
char c1 = 'g';
char c2 = 'h';
char plus = '+';
char space = ' ';
//box(win, (int)c1, (int)c2);
int left, right, top, bottom, tlc, trc, blc, brc;
left = right = 103;
top = 104;
bottom = blc = brc = (int)plus;
tlc = trc = (int)plus;
wborder(win, left, right, top, bottom, tlc, trc, blc, brc);
mvwprintw(win, 1, 1, "this is my box");
wrefresh(win);
// what's for user input,return int value of that key
getch();
getch();
// deallocates memory and end ncurses
endwin();
return 0;
}