【curses学习】0-1-2-3

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值