蛋疼地写了个hjkl画图的小程序,人生就是各种上下左右找不着北。

#include <ncurses.h>

inline int max(int a, int b)
{
    return (a > b) ? a : b;
}

inline int min(int a, int b)
{
    return (a < b) ? a : b;
}

int main()
{
    initscr();
    cbreak();
    noecho();
    //curs_set(0);

    /* get window size */
    int h,w;
    getmaxyx(stdscr, h, w);

    int y = 0,x = 0;
    int c;
    while ((c = getch()) != 'q') {
        if (c >= 'a') {
            mvaddch(y, x, '*');
            move(y, x);
        }
        if (c == 'h' || c == 'H') {
            x = max(0, x-1);
        } else if (c == 'j' || c == 'J') {
            y = min(h-1, y+1);
        } else if (c == 'k' || c == 'K') {
            y = max(0, y-1);
        } else if (c == 'l' || c == 'L') {
            x = min(w-1, x+1);
        }
        if (c >= 'a')
            mvaddch(y, x, '*');
        move(y, x);
        refresh();
    }

    endwin();
    return 0;
}

ncurses-painter